+ Post New Thread
Results 1 to 2 of 2
Coding Thread, PowerShell - Need confirmation of AD SAM Account Names / user names in Coding and Web Development; Hi Basically have a spreadsheet and in the first worksheet it has 2 columns, first column is surname and the ...
  1. #1

    mac_shinobi's Avatar
    Join Date
    Aug 2005
    Posts
    9,817
    Thank Post
    3,335
    Thanked 1,056 Times in 977 Posts
    Rep Power
    365

    PowerShell - Need confirmation of AD SAM Account Names / user names

    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

  2. #2
    old_n07's Avatar
    Join Date
    Jun 2012
    Location
    North Staffordshire
    Posts
    99
    Thank Post
    10
    Thanked 17 Times in 15 Posts
    Rep Power
    7
    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.

    Code:
    $CSVin = "path to input csv"                 #eg $CSVin = "d:\input.csv" 
    $CSVout = "path to output csv"               #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

SHARE:
+ Post New Thread

Similar Threads

  1. Adding User Name To Print Jobs
    By Richie1972 in forum Network and Classroom Management
    Replies: 20
    Last Post: 26th August 2014, 04:54 PM
  2. Do I need any of these protocols enabled on my printers?
    By sidewinder in forum Wireless Networks
    Replies: 4
    Last Post: 17th October 2007, 11:05 AM
  3. Need to reset a local account's password
    By timbo343 in forum Scripts
    Replies: 1
    Last Post: 21st September 2007, 01:16 PM
  4. Replies: 0
    Last Post: 2nd July 2007, 03:27 PM
  5. web version of AD
    By johnie65 in forum Windows
    Replies: 15
    Last Post: 20th February 2007, 06:09 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •