代码如下:
Clear-Host
Import-Module ActiveDirectory
$ErrorView = 'CategoryView'
Write-Host 'Searching for ADGroups...'
$ADGroups = @('Remote Desktop Users', 'M365 Migration')
If(Get-ADGroup -Filter "Name -In '$ADGroups'") {
Write-Host 'ADGroups found:'
Write-Host (Get-ADGroup -Filter "Name -In '$ADGroups'") -ForegroundColor Green
}
Else {
Write-Host 'No ADGroups found' -ForegroundColor Red
}
If(Get-ADGroup -Filter "Name -Eq 'Remote Desktop Users'") {
Write-Host 'Searching for RDLicenseConfiguration...'
Write-Host (Get-RDLicenseConfiguration -ErrorAction Continue) -ForegroundColor Green
Write-Host 'Searching for RDDeploymentGatewayConfiguration...'
Write-Host (Get-RDDeploymentGatewayConfiguration -ErrorAction Continue) -ForegroundColor Green
}
If(Get-ADGroup -Filter "Name -Eq 'Remote Desktop Users'") {
#M365 Migration
Write-Host 'Searching for applocker policy...'
Write-Host (Get-AppLockerPolicy -Local -ErrorAction Continue) -ForegroundColor Green
}
除了第13行的代码由于语法错误而不能正常运行外,它可以正常工作。
我现在得到的错误:
ParserError: (:) [Get-ADGroup], ADFilterParsingException
问题是第13行的代码,我尝试使用"Name -Like '$ADGroups*'"
,但也没有工作。
先谢谢你。
1条答案
按热度按时间tp5buhyn1#
Active Directory filter不支持
-in
,我所要做的就是添加上面的foreach
循环来循环数组中的每个对象,并将比较运算符更改为-eq
,再次感谢Doug的答案。