Active Directory Migrations: Parameters file & Ping

So at this point in our continuing series we’ve generated our include files for the various steps we’re going to run today and we’ve also added DNS suffixes to our user workstations and rebooted them. Now we want to make sure that they’ve actually come back from the reboots.

You could do a simple command/batch file and ping them all and that might be the easier way to go, but I prefer powershell and since we’re already in powershell, why wouldn’t want to do it that way?

This is also the point where we want to make sure that our Powershell session contains all the variables we need for the rest of our scripts. There’s a ton of stuff that’s going on depending on who you’re moving, from what source/target environment you’re going to, etc. So rather than re-init those variables for each script it makes more sense to load them once and save them everywhere.

The first thing we want to do is open Powershell.

We need to launch this script as . .\params.p1  The extra dot space in front of it allows us to use these variables elsewhere. It’s actually pretty powerful. I liken it to old days of building web pages where we’d use an include file for using the same footer everywhere.

## filename params.ps1

## Set variables
## In this script I want to check to see if the variable is already loaded in memory (hence the if statements)
## If they are, ignore. If they're not, load them in

if (!$ImportFile){$ImportFile="D:\Migration\admtincludes\UserIncludes.csv"}
if (!$SourceDC){$SourceDc=""}
if (!$TargetDC){$TargetDC=""}

## Get credentials for both sides for the scripts
if (!$LocalCredentials){
 write-host "Input Target Creds" -backgroundcolor red -foregroundcolor white
if (!$RemoteCredentials){
 write-host "Input Source creds" -backgroundcolor red -foregroundcolor white

if (!$TargetDeliveryDomain){$TargetDeliveryDomain=""}
if (!$ExchURI){$ExchURI=""}
if (!$LyncURI){$LyncURI=""}
if (!$LyncFEURI){$LyncFEURI=""}
if (!$LyncFEUSourceRI){$LyncFESourceURI=""}
if (!$LyncURISource){$LyncURISource=""}
if (!$SourceDomain){$SourceDomain=""}
if (!$TargetDomain){$TargetDomain=""}
if (!$RegistrarPool){$RegistrarPool=""}
if (!$TargetOU){$TargetOU="OU1/OU2"}
if (!$MasterGroup){$MasterGroup="d:\migration\mastergrouplist.txt"}
if (!$date){$date=get-date -format "yyyyMMdd"}
if (!$ComputerList){$ComputerList = Import-Csv "D:\Migration\admtincludes\BitLockerCompIncludes.csv"}
if (!$PrecheckCompList){$PrecheckCompList = import-csv "d:\migration\admtincludes\compincludes.csv"}

## Make sure you have the Quest AD tools installed

if ( (Get-PSSnapin -Name Quest.ActiveRoles.ADManagement -ErrorAction SilentlyContinue) -eq $null )
{Add-PSSnapin Quest.ActiveRoles.ADManagement}


## File name dnsping.ps1
## Set date and transcript

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


## Similar to previous script, set array for machines you can't connect to
## Add them to the array

$Computer=import-csv "d:\migration\admtincludes\CompIncludes.csv"
foreach ($comp in $computer){
 $ok=test-connection $ -count 1 -quiet
 write-host "Testing..." $ -foregroundcolor yellow
 if (-not($ok)){

## For each machine you can't ping, output to the host in a nice bright color that you couldn't connect to it
## In my case, of running migrations in the middle of the night, if I can't connect I remove them from the migration list and continue on.

foreach ($item in $NoPing){write-host "The following computers are not responding:" $item -backgroundcolor "red"}
if (!$NoPing){write-host "All computers responding" -foregroundcolor yellow}



Leave a Reply

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

You are commenting using your 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