Edu-IT Posted September 14, 2013 Posted September 14, 2013 Is there any script I can run to output a list of users who don't have anything in these fields in AD?
Ephelyon Posted September 14, 2013 Posted September 14, 2013 I'd use PowerShell's Get-ADUser command as below, searching for what you need: Get-ADUser
Edu-IT Posted September 14, 2013 Author Posted September 14, 2013 How would that work exactly, for finding blanks? Powershell noob here.
Arthur Posted September 14, 2013 Posted September 14, 2013 I think either of the following should work... Get-ADUser -LDAPFilter "(&(!(givenName=*))(!(sn=*)))" Get-ADUser -Filter {(givenName -eq $null) -and (sn -eq $null)}
Ephelyon Posted September 15, 2013 Posted September 15, 2013 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... 1
Ephelyon Posted September 15, 2013 Posted September 15, 2013 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.)
Edu-IT Posted September 15, 2013 Author Posted September 15, 2013 Will give that a try, thanks! Is there anyway to make it output to a text file?
Ephelyon Posted September 15, 2013 Posted September 15, 2013 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 1
Arthur Posted September 15, 2013 Posted September 15, 2013 You can't filter for $null values. Good point. I was using my phone at the time so couldn't test. I thought it didn't look quite right.
Ephelyon Posted September 15, 2013 Posted September 15, 2013 Hehe, we were both in the same position last night then. It's a bit like losing an arm when you're in the creative throes!
Edu-IT Posted September 15, 2013 Author Posted September 15, 2013 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.
Edu-IT Posted September 16, 2013 Author Posted September 16, 2013 Worked a treat and was such a timesaver. :-)
Ephelyon Posted September 16, 2013 Posted September 16, 2013 No worries Is it so you can add names in for those without them?
Ephelyon Posted September 16, 2013 Posted September 16, 2013 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?
Ephelyon Posted September 17, 2013 Posted September 17, 2013 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?
SiJones Posted September 17, 2013 Posted September 17, 2013 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.
pcstru Posted September 17, 2013 Posted September 17, 2013 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.
Ephelyon Posted September 17, 2013 Posted September 17, 2013 Perhaps even open that file in Excel in the meantime, wait for the user to edit it, then resume the script?
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now