通过powershell脚本排除特定服务器

问题描述 投票:0回答:1

我想排除特定的计算机对象。我尝试过类似下面的东西。但没有运气。

这是我的脚本:

$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
}
powershell
1个回答
0
投票

您的过滤器中缺少 - 和

{Get-ADComputer -Filter {启用-eq $True Name -notlike 'server11*' -and Name -notlike 'tstsrv11*'}

{Get-ADComputer -Filter {启用 -eq $True -and 名称 -notlike 'server11*' -and 名称 -notlike 'tstsrv11*'}

© www.soinside.com 2019 - 2024. All rights reserved.