You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用-filter参数查找包含数字的UPN(UserPrincipalName)

查找包含数字的UPN的正确PowerShell写法

要筛选出UPN(UserPrincipalName)中包含数字且域名是contoso.com的AD用户,你需要调整-Filter参数的写法,利用AD查询支持的通配符和字符范围匹配规则:

正确代码

Get-ADUser -Filter "UserPrincipalName -like '*[0-9]*@contoso.com'" -Properties UserPrincipalName | Select-Object UserPrincipalName

关键说明

  • 使用-like操作符配合通配符实现模糊匹配:
    • *代表任意长度的任意字符
    • [0-9]匹配0到9之间的单个数字
  • *[0-9]*@contoso.com表示:UPN前缀部分包含至少一个数字,且域名是contoso.com
  • 若要匹配所有域名下包含数字的UPN,可简化过滤规则:
    Get-ADUser -Filter "UserPrincipalName -like '*[0-9]*'" -Properties UserPrincipalName | Select-Object UserPrincipalName
    
  • 微软推荐-Filter参数使用双引号包裹,而非脚本块{},能避免一些解析异常

内容的提问来源于stack exchange,提问作者ak2595

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.23 11:24:17