Reputation: 3185
Is this possible? I need to convert from System.DirectoryServices.PropertyValueCollection
to a String
.
i.e.
$ou = [ADSI]"LDAP://OU=Domain Controllers,DC=domain,DC=local"
foreach ($child in $ou.psbase.Children) {
if ($child.ObjectCategory -like '*computer*') {
Write-Host $child.Name
if (Test-Connection -quiet $child.Name) {
Test-Connection $child.name
Invoke-GPUpdate $child.name
}else{Write-Host "$child.Name is offline"}
}
}
Upvotes: 1
Views: 1116
Reputation: 60976
I believe your issue is here:
}else{Write-Host "$child.Name is offline"}
Try:
}else{Write-Host "$($child.Name) is offline"}
In a string variable's properties aren't expanded, you need to enclose it in $()
notation.
Upvotes: 1
Reputation: 867
Like this: $child.Name.ToString()
Edit: I just tested in my lab and actually this works, not sure why exactly:
$child | %{$_.name}
Upvotes: 1