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="SourceDC1.domain1.com"}
if (!$TargetDC){$TargetDC="TargetDC1.domain2.com"}

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

if (!$TargetDeliveryDomain){$TargetDeliveryDomain="domain2.com"}
if (!$ExchURI){$ExchURI="http://TargetExchange.domain2.com/powershell"}
if (!$LyncURI){$LyncURI="https://TargetLyncPool.domain2.com/ocspowershell"}
if (!$LyncFEURI){$LyncFEURI="https://TargetLyncFe.domain2.com/ocspowershell"}
if (!$LyncFEUSourceRI){$LyncFESourceURI="https://SourceDomainLyncFE.domain.com/ocspowershell"}
if (!$LyncURISource){$LyncURISource="https://SourcedomainLyncDir.domain.com/ocspowershell"}
if (!$SourceDomain){$SourceDomain="domain1.com"}
if (!$TargetDomain){$TargetDomain="domain2.com"}
if (!$RegistrarPool){$RegistrarPool="lyncregistrar.domain2.com"}
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}

DNSPing.ps1


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

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

clear-host

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

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

## 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}

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