Script in Powershell to find user non-numerical on AD.

I have an active directory of about 1500 users, the user accounts are numeric, however I would like to have a script in powershell that allows me to search in the active directory those accounts that are not numeric, or at least that do not start by number. I have this script but I do not know how to add the condition that only those non-numerical ones export me. Any idea how I can do this search?

Get-ADUser -Filter * -SearchBase "OU=<myOU>,DC=<mydomain>,DC=<mydomain>" -Properties GivenName,Sn,SamAccountName,DistinguishedName | % {
New-Object PSObject -Property @{
Name = $_.GivenName
Surname = $_.Sn
Login = $_.SamAccountName
UO = $_.DistinguishedName
}
} | Select Name,Surname,Login,UO | Export-Csv D:\Data_user.csv

}
Fernando Garcia SotoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

oBdACommented:
You filter using a regular expression; "\D" matches any non-digit. And note that you can use "calculated expressions" to rename fields on the fly.
Get-ADUser -Filter * -SearchBase "OU=<myOU>,DC=<mydomain>,DC=<mydomain>" -ResultSetSize $null -Properties GivenName, Sn, SamAccountName, DistinguishedName |
	Where-Object {$_.SamAccountName -match '\D'} |
	Select-Object -Property `
		@{n='Name'; e={$_.GivenName}},
		@{n='Surname'; e={$_.Sn}},
		@{n='Login'; e={$_.SamAccountName}},
		@{n='UO'; e={$_.DistinguishedName}} |
	Export-Csv D:\Data_user.csv

Open in new window


Edit: To filter for those that do not start by number, replace the '\D' pattern with '\A\D'.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Fernando Garcia SotoAuthor Commented:
Excelent, it works
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.