我想排除特定的计算机对象。我尝试过类似下面的东西。但没有运气。
这是我的脚本:
$ADComputers = @()
$ADGroups = @()
$ComputersNotInAD = @()
$GroupsNotInAD = @()
# Create a single query filter str
$OU = 'OU=Tier1,DC=contoso,DC=local','OU=Servers,DC=contoso,DC=local'
$ADComputersRaw = $OU | ForEach-Object {Get-ADComputer -Filter {Enabled -eq $True Name -notlike 'server11*' -and Name -notlike 'tstsrv11*'} -SearchBase $PSItem -Properties * | Select-Object name}
# Rebuild the lists to make them text instead of objects
ForEach($ComputerRaw in $ADComputersRaw)
{
$ADComputers += $ComputerRaw.Name
}
您的过滤器中缺少 - 和
{Get-ADComputer -Filter {启用-eq $True Name -notlike 'server11*' -and Name -notlike 'tstsrv11*'}
{Get-ADComputer -Filter {启用 -eq $True -and 名称 -notlike 'server11*' -and 名称 -notlike 'tstsrv11*'}