People,
I need some help in the RegEx pattern for the below PowerShell code, so it can show any AD objects which has more than three digits as the name.
Ideally to match like:
Test-DL1-1-25932404
Firstname LastName-1810023568
SERVER-1-2102285680
Script:
Get-ADObject -Filter * |
Where-Object { $_.Name -match '\d\d\d\d' } |
Format-Table -AutoSize
The script above returns all AD objects with numbers.
CodePudding user response:
Get-ADObject -Filter * |
Where-Object { ($_.Name -replace '\D').Length -gt 3 } |
Format-Table -AutoSize
This will get rid of all non-digits and count how many remain, and will get 1-2-3-4-5 as well.