201611- PS – Bulk Transfer AD Username, email, Display Name etc

I create the Serials of scripts to manage the issue I face when do bulk CI records import to Ivanti ITSM portal. Local ITs are provided people information in all kind of format.
e.g Display Name; First Name, Last Name;First Name Last Name; Last Name First Name; First Name Last Name (LoginID);Last Name First Name (LoginID); LoginID ; Email etc
How to convert those data to a ‘clean’ data is a challenge for me.

Script # 1: Transfer LoginID to Display Name


#########Steps##################################################################
#Step 1: Create a file as Owner2CI.csv in C:\temp with Column Name as 'LoginID'
#Step 2: Execute This script in Powershell with Administrator right
#Step 3: Output file is Owner2CI_Export.csv in C:\temp
#----------------------------------------------------------------#
Import-Module ActiveDirectory
$path='c:\temp\'
$in=$path+'Owner2CI.csv' #File 1, #Column Name: LoginID
$export=$path+'Owner2CI_Export.csv' #File 2 #Column Name: LoginID, DisplayName
$Table=@{} #Define an Empty hash table
cd $path
#File 1#---------------------------------------------------------#
Import-csv -path $in |foreach{
$Table.Add($_.LoginID,$_)
}
#File 2#---------------------------------------------------------#
$users=Foreach($user in $(Import-csv $in|Select $_.LoginID))
{
Get-ADUser $user.LoginID -Properties SamAccountName, DisplayName
}
$users|Select @{n='LoginID';e={$_.SamAccountName}}, @{n='DisplayName';e={$_.DisplayName}}|Export-csv $export -NoTypeInformation

Script # 2: Transfer CN to Display Name


#----------------------------------------------------------------#
Import-Module ActiveDirectory
$path='c:\temp\'
$in=$path+'D2FL.csv' #File 1, #Column Name: Name
$out=$path+'D2FL_export.csv'
#$Table=@{} #Define an Empty hash table
cd $path
#File 1#---------------------------------------------------------#
#Import-csv -path $in |foreach{$Table.Add($_.Name,$_)}
$Datafile =Import-csv -path $in
#File 2#---------------------------------------------------------#
$StringA=Foreach($user in $Datafile)
{
#Get-ADUser -Filter {Name -like $N2} -Searchbase 'OU=TetraPak,DC=tp1,DC=ad1,DC=tetrapak,DC=com' -Properties DisplayName| Select @{n='Name';e={$_.Name}}, @{n='DisplayName';e={$_.DisplayName}} |Export-csv $out -NoTypeInformation
$user=("$user").split(" ",3)
$user
}
$StringA|select Name |FL

Script # 3 Transfer LoginID to First Name, Last Name


Import-Module ActiveDirectory
$path='c:\temp\'
$in=$path+'L2FL.csv' #File 1, #Column Name: Name
$out=$path+'L2FL_export.csv'
#$Table=@{} #Define an Empty hash table
cd $path
#File 1#---------------------------------------------------------#
#Import-csv -path $in |foreach{$Table.Add($_.Name,$_)}
$Datafile =Import-csv -path $in
#File 2#---------------------------------------------------------#
$StringA=Foreach($user in $Datafile)
{
Get-ADUser $user.LoginID -Properties SamAccountName, Givenname, Surname
}
$StringA|Select @{n='LoginID';e={$_.SamAccountName}}, @{n='FirstName';e={$_.Givenname}}, @{n='LastName';e={$_.Surname}}| Export-csv $out -NoTypeInformation

Script # 4: Transfer Email to LoginID


Import-Module ActiveDirectory
$path='c:\temp\'
$in=$path+'Email2LoginID.csv' #File 1, #Column Name: mail
$export=$path+'Email2LoginID_Export.csv' #File 2 #Column Name: LoginID, mail, targetAddress
$Table=@{} #Empty hash table
cd $path
#---------------------------------------------------------
$users=foreach($user in $(Get-content $in )){
Get-ADUser -Filter {mail -eq $user} -Properties SamAccountName, mail, targetAddress
}
$users|select @{n='LoginID';e={$_.SamAccountName}}, @{n='mail';e={$_.mail}},@{n='targetAddress';e={$_.targetAddress}}|Export-csv $export -NoTypeInformation

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s