Get-ADObject:分析查询时出错不支持:-neq'? [英] Get-ADObject : Error parsing query Not supported: -neq'?

查看:53
本文介绍了Get-ADObject:分析查询时出错不支持:-neq'?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用: https://docs.microsoft.com/zh-CN/powershell/module/addsadministration/get-adobject?view=win10-ps

如何获取结果,使其仅显示所有活动的AD用户&仅限计算机:

How can I get the result so that it only shows all active AD Users & Computers only:

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

推荐答案

如果您只是在寻找用户&计算机上,使用如下查询:

If you are really just looking for users & computers, use a query that says that:

Get-ADObject -Filter 'ObjectClass -eq "user" -or ObjectClass -eq "computer"'

尽管已经提到了运算符错误,但 Get-ADObject 不能使用双引号并在其中使用$ true/$ false.这些将扩展并以简单的对/错形式出现.运行类似 Get-ADObject -Filter"Enabled -eq $ true" 的命令将返回错误:

Withstanding the already mentioned operator error, Get-ADObject can't double quote and use $true/$false inside. Those will expand and come out as simply true/false. Running a command like Get-ADObject -Filter "Enabled -eq $true" returns an error:

Get-ADObject : Error parsing query: 'Enabled -eq True' Error Message: 'syntax error' at position: '13'.

如果您使用单引号将其运行,则它将运行,但是在我的环境中它不会返回任何内容,这可能是因为"Enabled"不是 Get-ADObject 返回的更通用对象的可查询属性,与 Get-ADUser/Computer 不同.因此,您必须处理引号和查询本身.

If you do run it with single quotes it'll run but in my environment it doesn't return anything, likely because "Enabled" isn't a query-able property from the more generic objects returned by Get-ADObject and unlike Get-ADUser/Computer. So you'll have to play with the quoting and the query itself.

除了可以只说 isRecycled -eq $ false 时,为什么使用类似 -not(isRecycled -eq $ true)的东西.您已经掌握了一个相对复杂的查询,我会砍掉不必要的反转...

An aside why use something like -not (isRecycled -eq $true) when you can just say isRecycled -eq $false. You've already got a relatively complex query on your hands, I'd chop the unnecessary inversions...

这篇关于Get-ADObject:分析查询时出错不支持:-neq'?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆