Get-ADUser -Filter存在的问题

huangapple go评论63阅读模式
英文:

Problems with Get-ADUser -Filter

问题

我想知道以两个数字结尾的用户有多少个,其中"UserParameters"属性为null。到目前为止,这是我的命令:

```powershell
$var1 = Get-ADUser -Filter {SamAccountName -like "*[0-9][0-9]"} -SearchBase "OU=xxxxxxxxxxxxxx,DC=xxxxxxx,DC=xx" | Where-Object {$_.UserParameters -eq $null}

如果我键入 $var1.count,它只会回复0。为什么会这样?是因为筛选器(-Filter)的问题,因为如果我只键入 -Filter *,它就可以正常工作。请帮助我!


<details>
<summary>英文:</summary>

I want to know how many Users whose ending are two numbers there are where the Attribute &quot;UserParameters&quot; is null. This is my command so far:

$var1 = Get-ADUser -Filter {SamAccountName -like "*[0-9][0-9]"} -SearchBase "OU=xxxxxxxxxxxxxx,DC=xxxxxxx,DC=xx" | Where-Object {$_.UserParameters -eq $null}

If I type in ```$var1.count``` it just replies with 0. Why is that so? And yes there are users that end with two numbers. I think the -Filter is the Problem because if I just type ```-Filter *``` it works just fine.
Please help me!


</details>


# 答案1
**得分**: 1

AD筛选器提供程序不知道通配符`[0-9]`的含义。如果需要的话,您可以自己构造一个LDAP筛选器,它本质上是一个OR模式`|`:

```none
(|(samAccountName=*00)(samAccountName=*01)(samAccountName=*02)(samAccountName=*03)...)

例如:

$filter = &quot;(|&quot;
foreach($i in 0..9) {
    foreach($x in 0..9) {
        $filter += &quot;(samAccountName=*$i$x)&quot;
    }
}
$filter += &quot;)&quot;
Get-ADUser -LDAPFilter $filter -SearchBase &#39;OU=xxxxxxxxxxxxxx,DC=xxxxxxx,DC=xx&#39;
英文:

The AD Filter provider has no clue what the wildcard [0-9] means. You can construct an LDAP Filter yourself if needed which would essentianlly be an OR pattern |:

(|(samAccountName=*00)(samAccountName=*01)(samAccountName=*02)(samAccountName=*03)...)

For example:

$filter = &quot;(|&quot;
foreach($i in 0..9) {
    foreach($x in 0..9) {
        $filter += &quot;(samAccountName=*$i$x)&quot;
    }
}
$filter += &quot;)&quot;
Get-ADUser -LDAPFilter $filter -SearchBase &#39;OU=xxxxxxxxxxxxxx,DC=xxxxxxx,DC=xx&#39;

huangapple
  • 本文由 发表于 2023年6月5日 22:36:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76407536.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定