รับ ADObject: มีข้อผิดพลาดในการแยกวิเคราะห์แบบสอบถามไม่รองรับ: -neq '?

Aug 19 2020

ใช้: https://docs.microsoft.com/en-us/powershell/module/addsadministration/get-adobject?view=win10-ps

ฉันจะรับผลลัพธ์ได้อย่างไรเพื่อให้แสดงเฉพาะผู้ใช้โฆษณาและคอมพิวเตอร์ที่ใช้งานอยู่ทั้งหมดเท่านั้น:

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

คำตอบ

1 Steven Aug 19 2020 at 13:52

หากคุณกำลังมองหาผู้ใช้และคอมพิวเตอร์จริงๆให้ใช้ข้อความค้นหาที่ระบุว่า:

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ได้ คุณมีคำถามที่ค่อนข้างซับซ้อนอยู่ในมือแล้วฉันจะตัดการผกผันที่ไม่จำเป็นออก ...

1 GrzegorzOchlik Aug 19 2020 at 13:40

ไม่มีสิ่งที่เรียกว่า-neq. สิ่งที่คุณกำลังมองหา-neอ่านเพิ่มเติมที่นี่:https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comparison_operators?view=powershell-5.1