1

我正在尝试列出我域中的所有计算机,但存储在两个 OU 中的计算机除外。一旦我使用 -or 运算符添加第二个 OU,事情就会中断。

使用这个我返回所有计算机,除了那些存储在我的第一个不需要的 ou 中的计算机:

[array]$Computers1 = get-adcomputer -filter '*' -SearchBase 'ou=WorkStations,dc=XXX,dc=XXX,dc=edu' | where { $_.DistinguishedName -notlike "*OU=Test,*" }

添加 -Or 运算符会导致不需要的计算机(存储在这两个 OU 中的计算机)包含在我的结果中。

[array]$Computers1 = get-adcomputer -filter '*' -SearchBase 'ou=WorkStations,dc=XXX,dc=XXX,dc=edu' | where { ($_.DistinguishedName -notlike "*OU=Test,*") -or ($_.DistinguishedName -notlike "*OU=TIS,*")}
4

1 回答 1

3

你想要-and,而不是-or

[array]$Computers1 = get-adcomputer -filter '*' -SearchBase 'ou=WorkStations,dc=XXX,dc=XXX,dc=edu' |
    where { ($_.DistinguishedName -notlike "*OU=Test,*") -and ($_.DistinguishedName -notlike "*OU=TIS,*")}
于 2016-07-05T18:33:04.487 回答