Get-ADObject : 쿼리 구문 분석 오류 지원되지 않음 : -neq '?
사용 : https://docs.microsoft.com/en-us/powershell/module/addsadministration/get-adobject?view=win10-ps
모든 활성 AD 사용자 및 컴퓨터 만 표시하도록 결과를 얻으려면 어떻게해야합니까?
Get-ADObject -Filter 'Enabled -eq $True -and isDeleted -neq $True -and -not (isRecycled -eq $True) -and name -ne "Deleted Objects"'
오류:
Get-ADObject : Error parsing query: 'Enabled -eq $True -and isDeleted -neq $True -and -not (isRecycled -eq $True) -and name -ne "Deleted Objects"' Error Message: 'Operator Not supported: -neq' at position:
'34'. At line:1 char:1
+ Get-ADObject -Filter 'Enabled -eq $True -and isDeleted -neq $True -an ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Get-ADObject], ADFilterParsingException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADFilterParsingException,Microsoft.ActiveDirectory.Management.Commands.GetADObject
답변
정말로 사용자와 컴퓨터를 찾고 있다면 다음과 같은 쿼리를 사용하십시오.
Get-ADObject -Filter 'ObjectClass -eq "user" -or ObjectClass -eq "computer"'
이미 언급 된 연산자 오류를 견디고 Get-ADObject
큰 따옴표를 사용하여 사용할 수 없습니다.$true/$거짓 내부. 그것들은 단순히 참 / 거짓으로 확장되고 나올 것입니다. 다음과 같은 명령을 실행 Get-ADObject -Filter "Enabled -eq $true"
하면 오류가 반환됩니다.
Get-ADObject : Error parsing query: 'Enabled -eq True' Error Message: 'syntax error' at position: '13'.
당신은 작은 따옴표로 실행할 경우이 실행하겠습니다하지만 내 환경에서 가능성이 "사용"때문에에 의해 반환되는보다 일반적인 객체에서 쿼리 수있는 재산없는, 아무 것도 반환하지 않습니다 Get-ADObject
와는 달리 Get-ADUser/Computer
. 따라서 인용문과 쿼리 자체를 가지고 놀아야합니다.
-not (isRecycled -eq $true)
그냥 말할 수있을 때 와 같은 것을 사용하는 이유 isRecycled -eq $false
. 당신은 이미 비교적 복잡한 쿼리를 가지고 있습니다. 불필요한 반전을 잘라내겠습니다.
와 같은 것은 없습니다 -neq
. 당신이 찾고있는 것은 -ne
여기에서 더 많은 것을 읽으십시오 :https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comparison_operators?view=powershell-5.1