Jump to content

Recommended Posts

Posted

I think either of the following should work...

 

Get-ADUser -LDAPFilter "(&(!(givenName=*))(!(sn=*)))"

Get-ADUser -Filter {(givenName -eq $null) -and (sn -eq $null)}

Posted

As we see here:

 

Field Notes of a Computer Geek: Filtering for $null Values with Get-ADUser

 

You can't filter for $null values. It would have to be something like this:

 

Get-ADUser -Filter {(givenName -notlike "*") -and (sn -notlike "*")}

 

Remember to do an "Import-Module ActiveDirectory" first though! Would've replied last night but school's Internet went down and only had the Mac here, so had nothing to play with... :p

  • Thanks 1
Posted

On the back of that, here's a handy way to find all users who have never logged on and are not disabled:

 

get-aduser -filter {(lastlogontimestamp -notlike "*")} -properties samaccountname | where { $_.enabled -eq $true} | ft samaccountname

 

It's also useful that you can run PowerShell commands individually without the need to enter PowerShell every time. So from the command line or within a batch script:

 

powershell -command "import-module activedirectory; get-aduser -filter {(lastlogontimestamp -notlike '*')} -properties samaccountname | where { $_.enabled -eq $true} | ft samaccountname"

 

(Note that the double-quotes around the * have become single-quotes because the whole command string is now enclosed in double-quotes.)

Posted

Add on to the end of your command:

 

| Out-File

 

So for you it might be:

 

Get-ADUser -Filter {(givenName -notlike "*") -and (sn -notlike "*")} -Properties samaccountname | FT samaccountname | Out-File C:\NoNames.txt

  • Thanks 1
Posted
Add on to the end of your command:

 

| Out-File

 

So for you it might be:

 

Get-ADUser -Filter {(givenName -notlike "*") -and (sn -notlike "*")} -Properties samaccountname | FT samaccountname | Out-File C:\NoNames.txt

Thank you. Will give it a whirl tomorrow. Appreciate the help.

Posted
If usernames already have some semblance to personal data stored in SIMS, would you be interested in a bolt-on that pulls out the relevant details from the MIS and populates those user fields automatically, tying the whole thing together?
Posted

Well, our staff usernames are their staff codes in SIMS (i.e. initials), so there would need to be a report in SIMS that pulls out forename, surname and staff code. The Windows batch scripting process would then be:

 

* Output the list of usernames with no FN/SN as above to File 1;

* Output the full staff list from SIMS (using CommandReporter.exe) to File 2;

* For each staff code in File 2, check if it matches an entry in File 1;

* If it does, take the FN/SN entries in File 2 and use dsmod to enter them for that user.

 

Is your setup in a configuration that something like that could work with?

Posted
Add on to the end of your command:

 

| Out-File

 

So for you it might be:

 

Get-ADUser -Filter {(givenName -notlike "*") -and (sn -notlike "*")} -Properties samaccountname | FT samaccountname | Out-File C:\NoNames.txt

 

Very handy, I'll add that to the toolbox.

Thanks.

Posted

My two-pence-worth (please feel free to ask for change) :

 

Generally try and make use of Export-CSV rather than Out-File. You can then easily pipe that back into a command, perhaps after manipulating it in excel. So I might run the commands to identify AD accounts without (say) Forename, Surname set properly, Pipe the samaccountname to a CSV file, use excel to populate surname, forename columns as appropriate and then use the modified CSV as an input to set the properties in AD.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...