0

How can I search for user using quest cmdlets (Get-QADUser) for accounts containing an "_" (underscore) followed by any 3 characters for eg.

User01_ad1, User55_a2d, User116_arr, User9999_1ad

I tried following but it does seem to work:

Get-QADUser -LdapFilter '(samaccountname=*_???)'

does get-qaduser does not recognize "?" as wildcard?

sk8er_boi47
  • 383
  • 1
  • 4
  • 15

1 Answers1

1

Single character wildcard is not available (MSDN). You can get accounts with _ using Get-QADUser and fine-tune the results with a -match regex-pattern using Where-Object.

Ex getting all accounts that end with underscore and three chars:

Get-QADUser -SamAccountName "*_*" | Where-Object { $_.SamAccountName -match '_\w{3}$' }
Frode F.
  • 52,376
  • 9
  • 98
  • 114
  • Got it thx, just one follow up question though, which one would work faster, your method or this: #Get-QADUser -SizeLimit 10000 | Where-Object {$_.SamAccountName -like '*_???'} – sk8er_boi47 Apr 24 '17 at 08:38
  • My solution is faster. Regex (`-match`) is faster than `-like`, but it won't matter unless `Get-QADUser` returns thousands of accounts, which your unfiltered query in the comment probably will. If you use filter on `Get-QADUser` to limit the accounts to process with `where-object`, then `-match \ -like` won't matter as much. – Frode F. Apr 24 '17 at 08:47
  • understood, once again thx a ton for response. Much appreciated! :) – sk8er_boi47 Apr 24 '17 at 09:42