PoshCode Archive  Artifact Content

Artifact 29b5e3aeee89dbc8cd719514920ff1d0a6ade8280aa7c737365a1c227d48187c:

  • File User-Lookup-Script.ps1 — part of check-in [7e262fd0a8] at 2018-06-10 13:57:10 on branch trunk — Mass User lookup Script to query user account name / UID and resolve a user’s first last name created by Morne Loubser. This simple light-weight script can resolve as many usernames as you’d like to in one go. There aren’t any sources that performs this function on the net, so this one is a definite keeper. The first of it’s kind to date to make it’s way onto the web. Can be used by both noobies and professional scripters. (user: Morlokor size: 1715)

# encoding: ascii
# api: powershell
# title: User Lookup Script
# description: Mass User lookup Script to query user account name / UID and resolve a user’s first last name created by Morne Loubser. This simple light-weight script can resolve as many usernames as you’d like to in one go. There aren’t any sources that performs this function on the net, so this one is a definite keeper. The first of it’s kind to date to make it’s way onto the web. Can be used by both noobies and professional scripters.
# version: 0.1
# author: Morlokor
# license: CC0
# x-poshcode-id: 5568
# x-archived: 2014-11-23T11:17:22
# x-published: 2014-11-04T10:08:00
#
# HOW IT WORKS:
# Simply populate the users.csv file with a list of usernames and let the script do the rest for you. It will dump all resolved details to the users_out.csv file as seen in the code. 
# Enjoy!
# Script reads from list and dumps to a new list. Couldn’t find a sample/template online for this so I wrote this code. Feel free to share.
#
***********************************************************************
* Developed by: Morne Loubser (aka Morlokor)
* Purpose: To mass query Active Directory for user first, last and display names
* Date: 11/04/2014
***********************************************************************
$in_file = "C:\*LOCATION_TO_YOUR_FILE*\users.csv"
$out_file = "C:\*LOCATION_TO_YOUR_FILE*\users_out.csv"

$out_data = @()

ForEach ($row in (Import-Csv $in_file)) {
    If ($row.'user') {
        $out_data += Get-ADUser $row.'user' -Properties displayname
    }
} 

$out_data | 
Select SamAccountName,Mail,Name,Surname,DisplayName | 
Export-Csv -Path $out_file -NoTypeInformation