Security in Obscurity

A script by Jeff Stein

Add-empID.ps1

Adds an employee ID attribute to user objects in Active Directory, June 2017

The script entitled "Add-empID" will import the AD module and adds data to the employee ID attribute in the user object of Active Directory from an imported CSV file. The script is designed for the Microsoft Windows operating system, leveraging PowerShell 4.0 and above.

DISCLAIMER

This script is offered 'as is' with no warranty. While it has been tested and verified to work in my environment, it is recommended that you test this script in a test environment before utilizing in your own production environment.

Installation

To get started download the files listed in the resource section and save the Add-empID.txt as a .ps1 file. It should be extracted to the desktop of the Windows machine where the script will run from. The CSV template file should be placed in the same directory. The Active Directory module should be installed on the machine for the script to run properly. Once extracted, the Add-empID.ps1 file can be right-clicked and "Run with PowerShell" can be selected. It is recommended that this is an account that has administrator privileges. Alternatively, PowerShell can be manually opened on the system and the terminal navigated to the appropriate directory where the script is located and executed from there. With either option, it is recommended the action to run the script is done with an account that has administrator privileges.

Overview

The script will add employee IDs to the attribute in the active directory user object from a CSV file. You can see an sample of the code below:

Import CSV file

$csvFilename = ".\empid.csv"
$csv = Import-Csv $csvFilename -Header @("ID","Last","First","SAM") | select -Skip 1

After importing the CSV file and stripping the template header from it the commands are run to add the ID to each account using a foreach loop using the following fields:

  1. ID
  2. Last
  3. First
  4. SAM
You can see the sample code to do this below:

Add ID to User Object

foreach ($line in $csv) {
set-aduser -Identity $line.SAM -EmployeeID $line.ID
}


Tags

Security Vulnerabilities IDS/IPS Malware Policies PowerShell Python Splunk Cloud Script PKI