Active Directory Migrations: Generating Files

So as you can probably tell from my last few posts I’ve been embroiled in an AD forest to forest migration for the past little while (and a little while longer). I have approximately 3000 users to migrate and am responsible for the mailbox move, user move, computer move, groups moves, Lync move, etc, etc. Basically I’ve got everything that makes a user a user.

I’ve scripted all of it and it took a ton of hours to get the scripts working right and to get all the little tweaks in there. It’s working pretty smoothly right now and I’m going to impart my wisdom in the next series of posts. My first bit of wisdom is to stay away from these types of migrations if you can help it 🙂 They’re a pain and there are so many moving parts that it’s difficult to get everything working just quite right.

But now that you’ve been told you just gotta do this, let me help where I can.

This first script is what I call my master script. I have the PM’s generating what I call the gold sheet for every migration that we do. In it is every field I need for every single script that I run. What this script here does is take the CSV file I get from them and generate all the various include files I need for the other scripts to run (some can’t take the massive initial file).

Modify this for your needs:

## Get the date in a format we want
## Set our transcript file and start the transcript so we have a log

$date=get-date -format "yyyyMMdd"
$Tranoutput="d:\migration\Outputs\" + $date + "ADMTIncludes.txt"
start-transcript -path $Tranoutput

## Set output variables. Declare them as arrays
$output=@()

$compOutput=@()
$ADMTCompOutput=@()
$BLCompOutput=@()

## Import our initial include file for all the users we're migrating today
## For each item in the include file, pull some of the variables and set them in the multi-column array
## Write them to an output array
## Set our various arrays to the output format

import-csv "d:\migration\admtincludes\Userincludes.csv"| ForEach-Object {
 $obj = New-Object PSObject | Select-Object SourceName, TargetRDN, TargetUPN
 $obj.SourceName = $_.sourceName
 $obj.TargetRDN = $_.TargetRDN
 $obj.TargetUPN = $_.TargetUPN
 $output += $obj

$CompObj=new-object PSObject|select-object Computer
 $CompObj.Computer=$_.computer
 $CompOutput+=$compobj

$ADMTCompObj="DOMAINNAME\"+$_.computer
 $ADMTCompOutput+=$ADMTcompobj

$ADMTCompObj2="DOMAINNAME\"+$_.computer
 $ADMTCompOutput2+=$ADMTcompobj2+";"
 $BLCompObj=new-object PSObject|select-object Computer
 $BLCompObj.Computer=$_.computer+".DOMAIN.COM"
 $BLCompOutput+=$BLcompobj

}

## Take all of our arrays we just populated and export them to a standard output filename
## all the other scripts look for these files in this format
## A couple are exported as CSV's, some are outputted as text files. Note the difference

write-host "...Generating Files..." -foregroundcolor red
$output|export-csv d:\migration\admtincludes\$date"ADMTMigration.csv" -notypeinformation
$CompOutput|export-csv d:\migration\admtincludes\CompIncludes.csv -notypeinformation
$ADMTCompOutput|out-file d:\migration\admtincludes\ADMTCompIncludes.txt
$ADMTCompOutput2|out-file d:\migration\admtincludes\ADMTCompMigIncludes.txt
$BLCompOutput|export-csv d:\migration\admtincludes\BitLockerCompIncludes.csv -notypeinformation

## Stop our screen transcript and read the log if necessary

stop-transcript

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s