Powershell 连接集合中的项
我在ActiveDirectory中有一个名为Powershell 连接集合中的项,powershell,active-directory,Powershell,Active Directory,我在ActiveDirectory中有一个名为$results的SearchResultCollection: $results = $directorySearcher.FindAll() 该集合中有两个表示计算机的SearchResult对象。 我想要一个计算机名用逗号分隔的字符串: $computerNames = $results | Select-Object { $_.Properties.name } $computerNamesCommaSeparated = $compute
$results
的SearchResultCollection
:
$results = $directorySearcher.FindAll()
该集合中有两个表示计算机的SearchResult
对象。
我想要一个计算机名用逗号分隔的字符串:
$computerNames = $results | Select-Object { $_.Properties.name }
$computerNamesCommaSeparated = $computerNames -join ","
然而,这只给了我,“
,里面没有计算机名
我可以在$computerNames
中看到它具有以下功能:
$_.Properties.name
------------------
ComputerName1
ComputerName2
我怎样才能让它工作?试试这个:
$computerNamesCommaSeparated = $results.Properties.name -join ","
$ComputerNames.Properties.name-join“,”
或者改为$ComputerNames=$results | ForEach对象{$\u0.Properties.name}
然后join。这样就行了。谢谢。@TessellingEckler为什么不写一个答案而不是一个评论,这样我就可以把它标记为被接受的答案呢?总是愚蠢的人,没有解释就投了反对票,这个代码行得通!我认为你的代码不会工作,因为Properties属性只存在于$results中的每个元素上,而不存在于$results对象本身上。。。在…之前验证你的确认。。。通过示例尝试以下代码“(GetChildItem-recurse).FullName”