Get-AD计算机与文本文件内容不匹配



我想获得所有广告计算机的列表,不包括文本文件中的服务器。这是我的代码:-


$excludedServers = (Get-Content 
"C:UserstestuserDocumentsRdpDisconnectedSessionsExcludedServers.txt").name #| Sort-Object
Get-ADComputer -Filter * | Where { $_.DistinguishedName -like "*Computers*" -and $_.DistinguishedName -notmatch $excludedServers }  | Select-Object Name

有什么建议吗?

首先,Get-Content不会带回对象,因此.name部分不会工作。如果它只是一个计算机名列表,那么只需将其更改为.

$excludedServers = Get-Content "C:UserstestuserDocumentsRdpDisconnectedSessionsExcludedServers.txt"

如果它是一个带有名称列的CSV,那么你可以用几种方法来实现它。坚持你的格式,这将工作

$excludedServers = (Import-Csv "C:UserstestuserDocumentsRdpDisconnectedSessionsExcludedServers.txt").name

现在你有了名称列表,你可以这样过滤(假设它实际上是服务器的名称,而不是它们的可分辨名称(

Get-ADComputer -Filter * | Where { $_.DistinguishedName -like "*Computers*" -and $_.name -notin $excludedServers }  | Select-Object Name

最新更新