mac_shinobi Posted July 22, 2014 Posted July 22, 2014 Hi Basically have a spreadsheet and in the first worksheet it has 2 columns, first column is surname and the 2nd column is forenames of all the users I basically need powershell to check against AD and confirm each users AD Logon username and insert the correct AD username into the 3rd column So for example, my first name and last name would be Shane Russell and looking in AD manually my AD logon username would be Shane.Russell I would need powershell to output a spreadsheet something like below in the 3rd Column ( as the forename and surname columns will be pre populated with all the users first and last names ) Or at least a file that has all the users AD logon usernames Column A | Column B | Column C | Surname | Forename | Confirmed AD | Russell Shane Shane.Russell etc Thanks @Arthur or anyone else
old_n07 Posted July 30, 2014 Posted July 30, 2014 It all depends on how fully you have populated AD with the users details and what format you create names etc. but it could be quite simple. It is easier working with a CSV, so using a csv with the column names Surname and Forname. I also use a different output file for simplicity. $CSVin = "[i]path to input csv[/i]" #eg $CSVin = "d:\input.csv" $CSVout = "[i]path to output csv[/i]" #eg $CSVout = "d:\output.csv" Import-Csv $CSVin | ForEach-Object { $user = $_.forname + " " + $_.Surname #construct the search term from forename and surname Get-ADUser -Filter 'Name -like $user' | select-object Surname,GivenName,SamAccountName| Export-Csv $CSVout -NoClobber -Append -NoTypeInformation } Neil
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