【发布时间】:2017-02-02 00:30:18
【问题描述】:
我有一个来自 ActiveDirectory 的 SearchResultCollection,名为 $results:
$results = $directorySearcher.FindAll()
该集合中有两个 SearchResult 对象代表计算机。
我想要一个用逗号分隔的计算机名称的字符串:
$computerNames = $results | Select-Object { $_.Properties.name }
$computerNamesCommaSeparated = $computerNames -join ","
但是这给了我",",里面没有计算机名称。
我可以在$computerNames 中看到它具有以下内容:
$_.Properties.name
------------------
ComputerName1
ComputerName2
我怎样才能让它工作?
【问题讨论】:
-
$ComputerNames.Properties.name -join ","或$computerNames = $results | ForEach-Object { $_.Properties.name }然后加入。 -
那行得通。谢谢。
-
@TessellatingHeckler 为什么不写一个答案而不是评论,以便我可以将其标记为已接受的答案?
标签: powershell active-directory