1

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"}
     }

}

2 Answers 2

1

Like this: $child.Name.ToString()

Edit: I just tested in my lab and actually this works, not sure why exactly:

$child | %{$_.name}
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.