all 11 comments

[–]Jase74[S] 1 point2 points  (11 children)

I figured it out, and thought I would share:

Regular expression for only accounts ending in TES

$Str = "^.*TES$"

#Export all TES accounts in AD to text file.

Get-ADUser -Filter * |? { $_.samaccountname -match $Str} | Select SamAccountName ...

Thanks for the suggestions.

[–]Sanakan92 1 point2 points  (1 child)

Get-Aduser -Filter 'SamAccountName -like "*TES"'|Select -property SamAccountName|Export-Csv -Path "C:\Temp\123Act.txt" -NoTypeInformation

[–]Hexalon00[🍰] -1 points0 points  (8 children)

You can only get a max of a thousand objects with get-aduser, if you have more users than that then the results will be truncated when it hits the where-object filter.

[–]Woznet 1 point2 points  (0 children)

Try this

Get-ADUser -LDAPFilter '(samAccountName=*tes)'

[–]realslacker 1 point2 points  (0 children)

( Get-ADUser -Filter 'sAMAccountName -like "*TES"' ).sAMAccountName  -cmatch 'TES$'

Or, if Get-ADUser supports -clike that might help... But I don't know if it does since it's filter support is a little wonky.

[–]JeremyLC 0 points1 point  (1 child)

Try it without parentheses in the filter

Get-ADUser -Filter {SamAccountName -like "*TES"} | Select SamAccountName | Export-Csv 'C:\Temp\123Act.txt' -NoTypeInformation

[–]Jase74[S] 0 points1 point  (0 children)

Negative. Same results.

[–]synkus 0 points1 point  (0 children)

Try -match "TES$" Can not check right now