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?
oBdAConnect With a Mentor Commented:
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'.
Fernando Garcia SotoAuthor Commented:
Excelent, it works
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.