连接集合中的项



我有一个名为$results的ActiveDirectory SearchResultCollection

$results = $directorySearcher.FindAll()

该集合中有两个表示计算机的SearchResult对象。我想有一个用逗号分隔的计算机名称的字符串:

$computerNames = $results | Select-Object { $_.Properties.name }
$computerNamesCommaSeparated = $computerNames -join ","

但是,这给了我",",里面没有计算机名称。

我可以在$computerNames中看到它具有以下内容:

$_.Properties.name
------------------
ComputerName1
ComputerName2

我怎样才能让它工作?

试试这个:

$computerNamesCommaSeparated = $results.Properties.name -join ","

最新更新