Powershell ';错误消息:';不支持运算符:-notcontain';在Get-ADUser筛选器cmdlet中?

Powershell ';错误消息:';不支持运算符:-notcontain';在Get-ADUser筛选器cmdlet中?,powershell,active-directory,Powershell,Active Directory,无法获取过去1年中创建的广告用户,该广告用户不包含特定的域名模式: $laterThan = (Get-Date).AddYears(-1) $filter = { (whenCreated -gt $laterThan) -and (userPrincipalName -notcontain $((Get-ADDomain).Name)) } $properties = 'canonicalName', 'whenCreated', 'displayName', 'lastlogondate'

无法获取过去1年中创建的广告用户,该广告用户不包含特定的域名模式:

$laterThan = (Get-Date).AddYears(-1)
$filter = { (whenCreated -gt $laterThan) -and (userPrincipalName -notcontain $((Get-ADDomain).Name)) }
$properties = 'canonicalName', 'whenCreated', 'displayName', 'lastlogondate'

Get-ADUser -Filter $filter -Properties $properties
错误显示为:

Get ADUser:分析查询“”时出错(创建时-gt$laterThan)-和 (userPrincipalName-notcontain$((Get ADDomain).Name))'错误 消息:“不支持操作员:-notcontain”位于位置:“55”。在 行:5字符:1

  • 获取ADUser-Filter$Filter-Properties$Properties
但是,IDE没有显示任何问题:
这是因为正确的运算符是
-notcontains


请全部检查。

您可能指的是
-notcontains
,但该cmdlet不支持该运算符。看

此外,该操作符处理集合,而不是字符串。如果要检查字符串是否包含其他字符串,请使用
-like
运算符和通配符:

Get-ADUser -Filter "UserPrincipalName -like '*$((Get-ADDomain).Name)*'"

不是运算符-notcontains吗?我想你遗漏了一点,也许我猜错了,但是ActiveDirectory筛选器似乎不支持
contains
notcontains
可能的筛选器运算符是
“-eq”|“-le”|“-ge”|“-ne”|“-lt”|“-gt”|“-approx”|-bor”| band”|-recursivematch”|-like”|-notlike”
。参考:是的,这是有道理的@Paxz,谢谢你的建议。@Isaac没问题,希望你也能在这篇文章中学习。
Get-ADUser -Filter "UserPrincipalName -like '*$((Get-ADDomain).Name)*'"