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

如何查找DisplayName属性中非空白字符及括号前无空格的AD用户?

AD User Filtering Solutions for DisplayName Requirements

Hey there! Let's tackle your two AD user filtering needs with straightforward PowerShell commands and clear explanations:

1. Filter Users with Non-Blank DisplayName

To find AD users where the DisplayName property has actual non-whitespace content (excluding empty values or entries with only spaces), use this command:

Get-ADUser -Filter * -Properties DisplayName | Where-Object { $_.DisplayName -notmatch '^\s*$' }
  • The regex ^\s*$ matches strings that are either empty or made up entirely of whitespace characters.
  • Using -notmatch reverses this logic, so we only retain users with a DisplayName that contains meaningful text.

2. Filter Users with DisplayName Format Like John Wick(IT Engineer) (No Space Before Parentheses)

You already have the command to find users with two or more spaces before parentheses (\s{2,}\(). To target the opposite scenario—where there's no space at all before the opening parenthesis—we'll use a negative lookbehind assertion in regex:

Get-ADUser -Filter * -Properties DisplayName | Where-Object { $_.DisplayName -match '(?<!\s)\(' }
  • The regex (?<!\s)\( translates to: "match an opening parenthesis ( that is NOT preceded by a whitespace character".
  • This will accurately catch entries like John Wick(IT Engineer) where the parenthesis directly follows the name without any space, while excluding users with spaces before the (.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 03:31:24