Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 连接集合中的项_Powershell_Active Directory - Fatal编程技术网

Powershell 连接集合中的项

Powershell 连接集合中的项,powershell,active-directory,Powershell,Active Directory,我在ActiveDirectory中有一个名为$results的SearchResultCollection: $results = $directorySearcher.FindAll() 该集合中有两个表示计算机的SearchResult对象。 我想要一个计算机名用逗号分隔的字符串: $computerNames = $results | Select-Object { $_.Properties.name } $computerNamesCommaSeparated = $compute

我在ActiveDirectory中有一个名为
$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”