1

这可能吗?我需要从转换System.DirectoryServices.PropertyValueCollectionString.

IE

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

}
4

2 回答 2

1

我相信你的问题在这里:

}else{Write-Host "$child.Name is offline"}

尝试:

}else{Write-Host "$($child.Name) is offline"}

在字符串变量的属性未展开时,您需要用$()符号将其括起来。

于 2013-06-12T07:01:33.783 回答
1

像这样: $child.Name.ToString()

编辑:我刚刚在我的实验室进行了测试,实际上这有效,不知道为什么:

$child | %{$_.name}
于 2013-06-11T23:43:17.483 回答