<# .DESCRIPTION This is a multi-purpose script for the DFW1 migration .EXAMPLE .\Downmaster.ps1 -MG MG-01 Displays information and all of the shutdown commands for all Windows devices in MG-01 .EXAMPLE .\Downmaster.ps1 -MG MG-01 -AllDevices Displays information and all of the shutdown commands for all devices in MG-01 .EXAMPLE .\Downmaster.ps1 -MG MG-01 -AllDevices -report Displays information on all of the devices in MG-01. Each device represents a line .EXAMPLE .\Downmaster.ps1 -MG MG-01 -AllDevices -Report -CSV Writes information on all of the devices in MG-01 to a CSV file. Each device represents a line .EXAMPLE .\Downmaster.ps1 -Account 23874 Displays information and all of the shutdown commands for all Windows devices in account 23874 .EXAMPLE .\Downmaster.ps1 -Account 23874 -AllDevices Displays information and all of the shutdown commands for all devices in account 23874 .EXAMPLE .\Downmaster.ps1 -Device 619501 Displays information and shutdown command for device 619501 .EXAMPLE .\Downmaster.ps1 -MG MG-01 -Cluster Displays information and all of the shutdown commands for all clusters in MG-01 .EXAMPLE .\Downmaster.ps1 -MG MG-01 -ClusReg Displays registry key commands for all clusters in MG-01 #> Param ( [Parameter(Mandatory=$false,Position=0)][string]$Version = "9.6.7", #Script version [Parameter(Mandatory=$false,Position=0)][string]$MG, #Move group [Parameter(Mandatory=$false,Position=0)][string]$Account, #Account number [Parameter(Mandatory=$false,Position=0)][string]$Device, #Device number [Parameter(Mandatory=$false,Position=0)][string]$Team, #Team number [switch] $DRAC, #Pull DRAC data [switch] $Revert, #Return settings to source DC [switch] $Cluster, #Show information for clusters [switch] $CSV, #Output a CSV [switch] $Report, #Output a list of devices [switch] $Registry, #Output registry keys [switch] $hyp, #Show information for hypervisors [switch] $AllDevices, #Show all devices [switch] $VLANs, #Show all VLAN translations [switch] $Voyage, #Show all Voyage data [switch] $Purge, #Eliminates and old files in the home directory [switch] $WindowsAudit, #Show only Windows devices [switch] $ClusReg, #Write only registry [switch] $SNet, #Cluster ServiceNet Audit, to be used in conjunction with -MG [switch] $ORD1_07, #Operate out of the ORD1-07 collection [switch] $AccountSNet, #Account ServiceNet Audit, to be used in conjunction with -Account [switch] $AllSNet, #All ServiceNet Audit, to be used in conjunction with -MG [switch] $AllManual #Show manual device steps ) ########################################################################################################### Function Write-AccountDetails ($PulledDevicePassed) { <# *********************************************************************************************************** This function takes the current pulled device the specific details for an account. The format should be similar to the following Account Name: Xerox Mortgage Services Account Number: 20120 Account Status: Active Account Manager: Todd Smith Lead Tech: Joel Valdez Service Level: Intensive ***************************************************** *********************************************************************************************************** #> write-host write-host write-host "Account Name:`t`t"$PulledDevicePassed.account.name write-host "Account Number:`t`t"$PulledDevicePassed.account.number ###################################################################################### #Depending on account status we'll change the color and flag if not something we expect if ($PulledDevicePassed.account.status -eq "Active") {$FGColor = "green"} else {$FGColor = "yellow"} write-host "Account Status:`t`t " -nonewline write-host $PulledDevicePassed.account.status -foregroundcolor $FGColor write-host "Account Manager:`t"$PulledDevicePassed.account.manager write-host "Lead Tech:`t`t"$PulledDevicePassed.account.lead_tech write-host "Service Level:`t`t"$PulledDevicePassed.account.type write-host write-host "*****************************************************" write-host } ########################################################################################################### Function Write-DeviceDetails ($PulledDevicePassed) { <# *********************************************************************************************************** This function takes the current pulled device and outputs the details related to the device and the syntax for running the shutdown.ps1 manually. The format should be roughly as follows: Device Number: 702372 Device Hostname: 702372-db2 Device Type: HP DL380 G9 Windows Move Group: MG-35 Device Status: Online/Complete .\Shutdown.ps1 -oldsnip 10.143.106.112 -oldsngw 10.143.106.109 -newsnip 10.147.143.164 -newsngw 10.147.143.161 -newsnmask 255.255.255.224 -DC DFW -Account 20083 -DeviceNumber 362993 -NoShutDown *********************************************************************************************************** #> #Output of device headings write-host "Device Number:`t`t"$PulledDevicePassed._id $Hostname,$Position = ParseLine $PulledDevicePassed.device.hostname 0 "." " " write-host "Device Hostname:`t"$Hostname write-host "Device Type:`t`t"$PulledDevicePassed.device.make_model write-host "Process Type:`t`t"$PulledDevicePassed.process.os_type write-host "Move Group:`t`t"$PulledDevicePassed.move_group ###################################################################################### #Setting the color of the status output based on the status of the device if ($PulledDevicePassed.device.status -eq "Online/Complete" -or $PulledDevicePassed.device.status -eq "Ready for Account Team" -or $PulledDevicePassed.device.status -eq "Support Maintenance") { $FGColor = "green" } elseif ($PulledDevicePassed.device.status -eq "Decommission" -or $PulledDevicePassed.device.status -eq "No longer active") { $FGColor = "red" } else { $FGColor = "yellow" } ###################################################################################### #Writing status write-host "Device Status:`t`t " -nonewline write-host $PulledDevicePassed.device.status -foregroundcolor $FGColor write-host ###################################################################################### #Checking if there are appropriate source and destination ServiceNet or MBU IPs and if it is Datapipe or Rackspace #If not a Datapipe then it is Rackspace if (($PulledDevicePassed.linked.specific_id).length -lt 1) { if ($PulledDevicePassed.network.address.service_net_ips.source.ip_address -eq $Null -and $PulledDevicePassed.network.address.mbu_ips.source.ip_address -eq $Null) { write-host "Rackspace device with out ServiceNet." -foregroundcolor "yellow" write-host "Device not configured for ServiceNet in source DC." -foregroundcolor "yellow" write-host write-host ".\Shutdown.ps1 -oldsnip none -oldsngw none -newsnip none -newsngw none -newsnmask none -dc"$PulledDevicePassed.device.datacenter"-Account"$PulledDevicePassed.account.number"-DeviceNumber"$PulledDevicePassed._id"-dpaccount none -dpdevice none -DnsSource"$(if ($PulledDevicePassed.dns.source -ne $null -and $PulledDevicePassed.dns.source -gt 1) {'"{0}"' -f ($PulledDevicePassed.dns.source -join '","')} else {"none"})"-DnsMigration"$(if ($PulledDevicePassed.dns.migration -ne $null -and $PulledDevicePassed.dns.migration -gt 1) {'"{0}"' -f ($PulledDevicePassed.dns.migration -join '","')} else {"none"})"-NtpMigration"$(if ($PulledDevicePassed.ntp.migration -ne $null -and $PulledDevicePassed.ntp.migration -gt 1) {'"{0}"' -f ($PulledDevicePassed.ntp.migration -join '","')} else {"none"})"-BackupNetworks"$(if ($PulledDevicePassed.network.backup.network -ne $null -and $PulledDevicePassed.network.backup.network -gt 1) {'"{0}"' -f ($PulledDevicePassed.network.backup.network -join '","')} else {"none"})"-Backup_Server"$(if ($PulledDevicePassed.network.backup_server -ne $null -and $PulledDevicePassed.network.backup_server -gt 1) {$PulledDevicePassed.network.backup_server} else {"none"})"-NoShutDown" -foregroundcolor "cyan" $SNIPNotConfiguredCount++ } elseif (($PulledDevicePassed.network.address.service_net_ips.migration).length -lt 1 -and ($PulledDevicePassed.network.address.mbu_ips.migration).length -lt 1) { ###################################################################################### #If there is a source IP address but no destination we need to flage this as NetSec will need to take care of the assignment for Rackspace device write-host "Rackspace device with out destination ServiceNet." -foregroundcolor "yellow" write-host "WARNING: Device has a ServiceNet IP in source DC but does not have a ServiceNet IP in destination" -foregroundcolor "red" write-host "If this is a newton deployment and not changing IP's then use the following shutdown command if needed." -foregroundcolor "red" $ShutdownCommand = ".\Shutdown.ps1 -oldsnip "+$PulledDevicePassed.network.address.service_net_ips.source.ip_address+" -oldsngw "+$PulledDevicePassed.network.address.service_net_ips.source.gateway+" -newsnip none -newsngw none -newsnmask none -dc "+$PulledDevicePassed.device.datacenter+" -Account "+$PulledDevicePassed.account.number+" -DeviceNumber "+$PulledDevicePassed._id+" -dpaccount none -dpdevice none -DnsSource "+$(if ($PulledDevicePassed.dns.source -ne $null -and $PulledDevicePassed.dns.source -gt 1) {'"{0}"' -f ($PulledDevicePassed.dns.source -join '","')} else {"none"})+" -DnsMigration "+$(if ($PulledDevicePassed.dns.migration -ne $null -and $PulledDevicePassed.dns.migration -gt 1) {'"{0}"' -f ($PulledDevicePassed.dns.migration -join '","')} else {"none"})+" -NtpMigration "+$(if ($PulledDevicePassed.ntp.migration -ne $null -and $PulledDevicePassed.ntp.migration -gt 1) {'"{0}"' -f ($PulledDevicePassed.ntp.migration -join '","')} else {"none"})+" -BackupNetworks "+$(if ($PulledDevicePassed.network.backup.network -ne $null -and $PulledDevicePassed.network.backup.network -gt 1) {'"{0}"' -f ($PulledDevicePassed.network.backup.network -join '","')} else {"none"})+" -Backup_Server "+$(if ($PulledDevicePassed.network.backup_server -ne $null -and $PulledDevicePassed.network.backup_server -gt 1) {$PulledDevicePassed.network.backup_server} else {"none"})+" -NoShutDown" $NoDestinationServiceNet++ } else { ###################################################################################### #If we're all good then generate the shutdown syntax for Rackspace device if ($PulledDevicePassed.network.address.service_net_ips.source.ip_address -eq $Null) { write-host "Rackspace device with MBU shutdown command." -foregroundcolor "yellow" $ShutdownCommand = ".\Shutdown.ps1 -oldsnip "+$PulledDevicePassed.network.address.mbu_ips.source.ip_address+" -oldsngw "+$PulledDevicePassed.network.address.mbu_ips.source.gateway+" -newsnip "+$PulledDevicePassed.network.address.service_net_ips.migration.ip_address+" -newsngw "+$PulledDevicePassed.network.address.service_net_ips.migration.gateway+" -newsnmask "+$PulledDevicePassed.network.address.service_net_ips.migration.netmask+" -dc "+$PulledDevicePassed.device.datacenter+" -Account "+$PulledDevicePassed.account.number+" -DeviceNumber "+$PulledDevicePassed._id+ "-dpaccount none -dpdevice none -DnsSource "+$(if ($PulledDevicePassed.dns.source -ne $null -and $PulledDevicePassed.dns.source -gt 1) {'"{0}"' -f ($PulledDevicePassed.dns.source -join '","')} else {"none"})+" -DnsMigration "+$(if ($PulledDevicePassed.dns.migration -ne $null -and $PulledDevicePassed.dns.migration -gt 1) {'"{0}"' -f ($PulledDevicePassed.dns.migration -join '","')} else {"none"})+" -NtpMigration "+$(if ($PulledDevicePassed.ntp.migration -ne $null -and $PulledDevicePassed.ntp.migration -gt 1) {'"{0}"' -f ($PulledDevicePassed.ntp.migration -join '","')} else {"none"})+" -BackupNetworks "+$(if ($PulledDevicePassed.network.backup.network -ne $null -and $PulledDevicePassed.network.backup.network -gt 1) {'"{0}"' -f ($PulledDevicePassed.network.backup.network -join '","')} else {"none"})+" -Backup_Server "+$(if ($PulledDevicePassed.network.backup_server -ne $null -and $PulledDevicePassed.network.backup_server -gt 1) {$PulledDevicePassed.network.backup_server} else {"none"})+" -NoShutDown" } else { write-host "Rackspace device with ServiceNet shutdown command." -foregroundcolor "yellow" $ShutdownCommand = ".\Shutdown.ps1 -oldsnip "+$PulledDevicePassed.network.address.service_net_ips.source.ip_address+" -oldsngw "+$PulledDevicePassed.network.address.service_net_ips.source.gateway+" -newsnip "+$PulledDevicePassed.network.address.service_net_ips.migration.ip_address+" -newsngw "+$PulledDevicePassed.network.address.service_net_ips.migration.gateway+" -newsnmask "+$PulledDevicePassed.network.address.service_net_ips.migration.netmask+" -dc "+$PulledDevicePassed.device.datacenter+" -Account "+$PulledDevicePassed.account.number+" -DeviceNumber "+$PulledDevicePassed._id+" -dpaccount none -dpdevice none -DnsSource "+$(if ($PulledDevicePassed.dns.source -ne $null -and $PulledDevicePassed.dns.source -gt 1) {'"{0}"' -f ($PulledDevicePassed.dns.source -join '","')} else {"none"})+" -DnsMigration "+$(if ($PulledDevicePassed.dns.migration -ne $null -and $PulledDevicePassed.dns.migration -gt 1) {'"{0}"' -f ($PulledDevicePassed.dns.migration -join '","')} else {"none"})+" -NtpMigration "+$(if ($PulledDevicePassed.ntp.migration -ne $null -and $PulledDevicePassed.ntp.migration -gt 1) {'"{0}"' -f ($PulledDevicePassed.ntp.migration -join '","')} else {"none"})+" -BackupNetworks "+$(if ($PulledDevicePassed.network.backup.network -ne $null -and $PulledDevicePassed.network.backup.network -gt 1) {'"{0}"' -f ($PulledDevicePassed.network.backup.network -join '","')} else {"none"})+" -Backup_Server "+$(if ($PulledDevicePassed.network.backup_server -ne $null -and $PulledDevicePassed.network.backup_server -gt 1) {$PulledDevicePassed.network.backup_server} else {"none"})+" -NoShutDown" } } } else { ###################################################################################### #If we're all good then generate the shutdown syntax for Datapipe device if ($PulledDevicePassed.network.address.service_net_ips.source.ip_address -eq $Null) { write-host "Datapipe device with unknown source ServiceNet shutdown command." -foregroundcolor "yellow" write-host "Device backup configuration unknown in source DC." -foregroundcolor "yellow" write-host $ShutdownCommand = ".\Shutdown.ps1 -oldsnip none -oldsngw none -newsnip "+$PulledDevicePassed.network.address.service_net_ips.migration.ip_address+" -newsngw "+$PulledDevicePassed.network.address.service_net_ips.migration.gateway+" -newsnmask "+$PulledDevicePassed.network.address.service_net_ips.migration.netmask+" -dc "+$PulledDevicePassed.device.datacenter+" -Account "+$PulledDevicePassed.account.number+" -DeviceNumber "+$PulledDevicePassed._id+" -DpAccount "+$PulledDevicePassed.linked.account_number+" -DpDevice "+$PulledDevicePassed.linked.specific_id+" -DnsSource "+$(if ($PulledDevicePassed.dns.source -ne $null -and $PulledDevicePassed.dns.source -gt 1) {'"{0}"' -f ($PulledDevicePassed.dns.source -join '","')} else {"none"})+" -DnsMigration "+$(if ($PulledDevicePassed.dns.migration -ne $null -and $PulledDevicePassed.dns.migration -gt 1) {'"{0}"' -f ($PulledDevicePassed.dns.migration -join '","')} else {"none"})+" -NtpMigration "+$('"{0}"' -f ($PulledDevicePassed.ntp.migration -join '","'))+" -BackupNetworks "+$('"{0}"' -f ($PulledDevicePassed.network.backup.network -join '","'))+" -Backup_Server "+$(if ($PulledDevicePassed.network.backup_server -ne $null -and $PulledDevicePassed.network.backup_server -gt 1) {$PulledDevicePassed.network.backup_server} else {"none"})+" -NoShutDown" } else { write-host "Datapipe device with ServiceNet shutdown command." -foregroundcolor "yellow" $ShutdownCommand = ".\Shutdown.ps1 -oldsnip "+$PulledDevicePassed.network.address.service_net_ips.source.ip_address+" -oldsngw "+$PulledDevicePassed.network.address.service_net_ips.source.gateway+" -newsnip "+$PulledDevicePassed.network.address.service_net_ips.migration.ip_address+" -newsngw "+$PulledDevicePassed.network.address.service_net_ips.migration.gateway+" -newsnmask "+$PulledDevicePassed.network.address.service_net_ips.migration.netmask+" -dc "+$PulledDevicePassed.device.datacenter+" -Account "+$PulledDevicePassed.account.number+" -DeviceNumber "+$PulledDevicePassed._id+" -DpAccount "+$PulledDevicePassed.linked.account_number+" -DpDevice "+$PulledDevicePassed.linked.specific_id+" -DnsSource "+$(if ($PulledDevicePassed.dns.source -ne $null -and $PulledDevicePassed.dns.source -gt 1) {'"{0}"' -f ($PulledDevicePassed.dns.source -join '","')} else {"none"})+" -DnsMigration "+$(if ($PulledDevicePassed.dns.migration -ne $null -and $PulledDevicePassed.dns.migration -gt 1) {'"{0}"' -f ($PulledDevicePassed.dns.migration -join '","')} else {"none"})+" -NtpMigration "+$('"{0}"' -f ($PulledDevicePassed.ntp.migration -join '","'))+" -BackupNetworks "+$('"{0}"' -f ($PulledDevicePassed.network.backup.network -join '","'))+" -Backup_Server "+$(if ($PulledDevicePassed.network.backup_server -ne $null -and $PulledDevicePassed.network.backup_server -gt 1) {$PulledDevicePassed.network.backup_server} else {"none"})+" -NoShutDown" } } ###################################################################################### #This is mostly for use with the DFW3 test environment. It allows us to revert changes made by the shutdown script during a test migration if ($Revert) { ###################################################################################### #If we're all good then generate the shutdown syntax for Rackspace device if ($PulledDevicePassed.network.address.service_net_ips.source.ip_address -eq $Null) { $ShutdownCommand = ".\Shutdown.ps1 -oldsnip "+$PulledDevicePassed.network.address.mbu_ips.migration.ip_address+" -oldsngw "+$PulledDevicePassed.network.address.mbu_ips.migration.gateway+" -newsnip "+$PulledDevicePassed.network.address.service_net_ips.source.ip_address+" -newsngw "+$PulledDevicePassed.network.address.service_net_ips.source.gateway+" -newsnmask "+$PulledDevicePassed.network.address.service_net_ips.source.netmask+" -Account "+$PulledDevicePassed.account.number+" -DeviceNumber "+$PulledDevicePassed._id+" -NoShutDown" } else { $ShutdownCommand = ".\Shutdown.ps1 -oldsnip "+$PulledDevicePassed.network.address.service_net_ips.migration.ip_address+" -oldsngw "+$PulledDevicePassed.network.address.service_net_ips.migration.gateway+" -newsnip "+$PulledDevicePassed.network.address.service_net_ips.source.ip_address+" -newsngw "+$PulledDevicePassed.network.address.service_net_ips.source.gateway+" -newsnmask "+$PulledDevicePassed.network.address.service_net_ips.source.netmask+" -Account "+$PulledDevicePassed.account.number+" -DeviceNumber "+$PulledDevicePassed._id+" -NoShutDown" } } ###################################################################################### #Write the appropriate shutdown command write-host write-host $ShutdownCommand -foregroundcolor "cyan" write-host write-host } ########################################################################################################### Function Write-DeviceSlack ($CSVFilePassed,$PulledDevicePassed) { <# *********************************************************************************************************** This function takes the current pulled device and outputs device information in the format for the SlackAttack script. *********************************************************************************************************** #> ###################################################################################### #Removing the phoney FQDN $Hostname,$Position= ParseLine $PulledDevicePassed.device.hostname 0 "." " " ###################################################################################### #Replacing any commas in the accountname $AccountName = $PulledDevicePassed.account.name | foreach {$_ -replace ",", ""} if ($PulledDevicePassed.device.status -ne "Deleted" -and !($PulledDevicePassed.device.make_model -like "*Cluster*") -and $PulledDevice.device.status -notlike "*omputer No Longer Activ*" -and $PulledDevice.device.status -notlike "*ecommiss*") { $Outline = [string]$PulledDevicePassed._id+","+$PulledDevicePassed.device.hostname+","+$PulledDevicePassed.device.make_model+","+$AccountName+","+$PulledDevicePassed.account.number+","+$PulledDevicePassed.device.status+","+$PulledDevicePassed.device.primary_ip Add-Content $CSVFilePassed $Outline } } ########################################################################################################### Function Write-DeviceLineCSV ($CSVFilePassed,$PulledDevicePassed) { <# *********************************************************************************************************** This function takes the current pulled device and outputs device information as a CSV. *********************************************************************************************************** #> ###################################################################################### #Removing the phoney FQDN $AccountName = $PulledDevicePassed.account.name | foreach {$_ -replace ",", ""} $Hostname = (ParseLine $PulledDevicePassed.device.hostname 0 "." " ")[0] $Outline = [string]$PulledDevicePassed._id+","+$Hostname+","+$AccountName+","+$PulledDevicePassed.device.make_model+","+$PulledDevicePassed.device.os_name+","+$PulledDevicePassed.device.os+","+$PulledDevicePassed.device.status+","+$PulledDevicePassed.account.number+","+$PulledDevicePassed.move_group+","+$PulledDevicePassed.account.type+","+$PulledDevicePassed.has_mbu+","+$PulledDevicePassed.move_group+","+$PulledDevicePassed.process.os_type+","+$PulledDevicePassed.device.status ###################################################################################### #Write line Add-Content $CSVFilePassed $Outline } ########################################################################################################### Function Write-DeviceVLANCSV ($CSVFilePassed,$PulledDevicePassed) { <# *********************************************************************************************************** This function takes the current pulled device and outputs the pre and post VLANs configuration as a CSV *********************************************************************************************************** #> ###################################################################################### #Removing the phoney FQDN $Hostname,$Position= ParseLine $PulledDevicePassed.device.hostname 0 "." " " ###################################################################################### #Iterate through the VLANs and output source and destination foreach ($VLAN in $PulledDevice.network.vlans) { $Outline = [string]$PulledDevicePassed._id+","+$Hostname+","+$VLAN.source.vlan_number+","+$VLAN.migration.vlan_number+","+$VLAN.source.zone_name+","+$VLAN.migration.zone_name+","+$VLAN.source.network_segments+","+$VLAN.migration.network_segments Add-Content $CSVFilePassed $Outline } } ########################################################################################################### Function Write-DeviceHypCSV ($CSVFilePassed,$PulledDevicePassed) { <# *********************************************************************************************************** This function takes the current pulled device and outputs the pre and post VLANs configuration as a CSV *********************************************************************************************************** #> ###################################################################################### #Removing the phoney FQDN $Hostname=(ParseLine $PulledDevicePassed.device.hostname 0 "." " ")[0] ###################################################################################### #Iterate through the VLANs and output source and destination foreach ($VLAN in $PulledDevice.network.vlans) { $AccountName = $PulledDevicePassed.account.name | foreach {$_ -replace ",", ""} $Outline = [string]$PulledDevicePassed._id+","+$Hostname+","+$AccountName+","+$PulledDevicePassed.account.number+",,," Add-Content $CSVFilePassed $Outline } } ########################################################################################################### Function Write-DeviceSNetCSV ($CSVFilePassed,$PulledDevicePassed) { <# *********************************************************************************************************** This function takes the current pulled device and outputs the pre and post VLANs configuration as a CSV *********************************************************************************************************** #> ###################################################################################### #Removing the phoney FQDN $Hostname=(ParseLine $PulledDevicePassed.device.hostname 0 "." " ")[0] ###################################################################################### # Looking for the source data for the cluster object. It could be in two different places if ($PulledDevicePassed.network.address.mbu_ips.source.ip_address -ne $Null) { $SourceSNIP = $PulledDevicePassed.network.address.mbu_ips.source.ip_address } elseif ($PulledDevicePassed.network.address.service_net_ips.source.ip_address -ne $Null) { $SourceSNIP = $PulledDevicePassed.network.address.service_net_ips.source.ip_address } else { $SourceSNIP = "No source ServiceNet IP" } # Checking the destination SNet data for the node. It could be in two different places. if ($PulledDevicePassed.network.address.service_net_ips.migration.ip_address -ne $Null) { $NewSNIP = $PulledDevicePassed.network.address.service_net_ips.migration.ip_address } elseif ($PulledDevicePassed.network.address.mbu_ips.migration.ip_address -ne $Null) { $NewSNIP = $PulledDevicePassed.network.address.mbu_ips.migration.ip_address } else { $NewSNIP = "No destination SNet IP" } $AccountName = $PulledDevicePassed.account.name | foreach {$_ -replace ",", ""} $Outline = $AccountName+","+$PulledDevicePassed.account.number+","+$PulledDevicePassed._id+","+$Hostname+","+$PulledDevicePassed.process.os_type+","+$SourceSNIP+","+$NewSNIP Add-Content $CSVFilePassed $Outline } ########################################################################################################### Function Write-DeviceRegKey ($PulledDevicePassed,$ClusRegReport,$OutFile) { <# *********************************************************************************************************** This function takes the current pulled device and outputs the appropriate registry command to change the CommVault registry entry. *********************************************************************************************************** #> $Hostname,$Position = ParseLine $PulledDevicePassed.device.hostname 0 "." " " ###################################################################################### #Make sure we have a destination SNet IP address if ($PulledDevicePassed.network.address.service_net_ips.migration.ip_address -ne $Null) { $NewSNIP = $PulledDevicePassed.network.address.service_net_ips.migration.ip_address $RegistryCommand = "REG ADD `"HKLM\SOFTWARE\CommVault Systems\Galaxy\Instance001\Machines\"+[string]$($PulledDevicePassed.account.number)+"-"+[string]$($PulledDevicePassed._id)+"`" /v `"sHOSTNAME`" /t REG_SZ /d `""+$NewSNIP+"`" /f" } ###################################################################################### #The SNet nmight be in a couple of places elseif ($PulledDevicePassed.network.address.mbu_ips.migration.ip_address -ne $Null) { $NewSNIP = $PulledDevicePassed.network.address.mbu_ips.migration.ip_address $RegistryCommand = "REG ADD `"HKLM\SOFTWARE\CommVault Systems\Galaxy\Instance001\Machines\"+[string]$($PulledDevicePassed.account.number)+"-"+[string]$($PulledDevicePassed._id)+"`" /v `"sHOSTNAME`" /t REG_SZ /d `""+$NewSNIP+"`" /f" } ###################################################################################### #If the SNet IP is in neither of the two known places then notify the user else { $RegistryCommand = "Device does hot have destination ServiceNet IPs" } ###################################################################################### #Actually output the command if ($ClusRegReport) { if ($Hostname -notlike "*MSDTC*" -and $Hostname -notlike "*NTCLUS*" -and $Hostname -notlike "*NTClus*" -and $Hostname -notlike "*inux*") { $Outline = [string]$($PulledDevicePassed._id)+","+$Hostname+","+$PulledDevicePassed.device.os_name+","+$PulledDevicePassed.device.os+","+$RegistryCommand add-content $OutFile $Outline } } else { write-host $RegistryCommand -foregroundcolor "cyan" write-host write-host } } ########################################################################################################### Function Write-DeviceDRAC ($PulledDevicePassed) { <# *********************************************************************************************************** This function takes the current pulled device and outputs the destination DRAC IP information. *********************************************************************************************************** #> ###################################################################################### #Make sure we have a destination SNet IP address if ($PulledDevicePassed.network.address.drac_ips.migration.ip_address -ne $Null) { write-host "Source DRAC IP:`t`t$($PulledDevicePassed.network.address.drac_ips.source.ip_address)" -foregroundcolor "cyan" write-host "Source Mask:`t`t$($PulledDevicePassed.network.address.drac_ips.source.netmask)" -foregroundcolor "cyan" write-host "Source Gateway:`t`t$($PulledDevicePassed.network.address.drac_ips.source.gateway)" -foregroundcolor "cyan" write-host write-host write-host "Destination DRAC IP:`t$($PulledDevicePassed.network.address.drac_ips.migration.ip_address)" -foregroundcolor "cyan" write-host "Destination Mask:`t$($PulledDevicePassed.network.address.drac_ips.migration.netmask)" -foregroundcolor "cyan" write-host "Destination Gateway:`t$($PulledDevicePassed.network.address.drac_ips.migration.gateway)" -foregroundcolor "cyan" write-host write-host "If DHCP is set:" -foregroundcolor "yellow" write-host write-host "racadm set iDRAC.Nic.Enable 1" -foregroundcolor "cyan" write-host $DRACPWD = (Get-CoreDeviceDrac -DeviceNumber $PulledDevicePassed._id).DracPassword write-host "racadm config -g cfgUserAdmin -o cfgUserAdminPassword -i 2 `"$DRACPWD`"" -foregroundcolor "cyan" write-host "racadm setniccfg -s $($PulledDevicePassed.network.address.drac_ips.migration.ip_address) $($PulledDevicePassed.network.address.drac_ips.migration.netmask) $($PulledDevicePassed.network.address.drac_ips.migration.gateway)" -foregroundcolor "cyan" write-host "racadm racreset" -foregroundcolor "cyan" write-host write-host "OR" -foregroundcolor "yellow" write-host write-host "racadm set iDRAC.Users.2.Password `"$DRACPWD`"" -foregroundcolor "cyan" } ###################################################################################### #If the SNet IP is in neither of the two known places then notify the user else { write-host "Device does not have a destination DRAC IP" } } ########################################################################################################### Function Write-DeviceLine ($PulledDevicePassed) { <# *********************************************************************************************************** This function takes the current pulled device and outputs a formatted line to screen for reporting purposes *********************************************************************************************************** #> ###################################################################################### #Removing the phoney FQDN $Hostname, $Position = ParseLine $PulledDevicePassed.device.hostname 0 "." " " ###################################################################################### #Writing the hostname and an appropriate number of tabs write-host $PulledDevicePassed._id"`t"$Hostname -nonewline if ($Hostname.length -le 6) {write-host "`t`t`t`t`t" -nonewline} elseif ($Hostname.length -le 14) {write-host "`t`t`t`t" -nonewline} elseif ($Hostname.length -le 22) {write-host "`t`t`t" -nonewline} elseif ($Hostname.length -le 30) {write-host "`t`t" -nonewline} else {write-host "`t" -nonewline} ###################################################################################### #Writing the make/model and an appropriate number of tabs write-host $PulledDevicePassed.device.make_model -nonewline if ($PulledDevicePassed.device.make_model.length -le 7) {write-host "`t`t`t`t`t`t`t" -nonewline} elseif ($PulledDevicePassed.device.make_model.length -le 15) {write-host "`t`t`t`t`t`t" -nonewline} elseif ($PulledDevicePassed.device.make_model.length -le 23) {write-host "`t`t`t`t`t" -nonewline} elseif ($PulledDevicePassed.device.make_model.length -le 31) {write-host "`t`t`t`t" -nonewline} elseif ($PulledDevicePassed.device.make_model.length -le 39) {write-host "`t`t`t" -nonewline} elseif ($PulledDevicePassed.device.make_model.length -le 46) {write-host "`t`t" -nonewline} else {write-host "`t" -nonewline} ###################################################################################### #Writing the OS name and an appropriate number of tabs write-host $PulledDevicePassed.device.os_name -nonewline if ($PulledDevicePassed.device.os_name.length -le 7) {write-host "`t`t`t" -nonewline} elseif ($PulledDevicePassed.device.os_name.length -le 14) {write-host "`t`t" -nonewline} else {write-host "`t" -nonewline} ###################################################################################### #Determining what color to use for status output based on online status if ($PulledDevicePassed.device.status -eq "Online/Complete" -or $PulledDevicePassed.device.status -eq "Ready for Account Team" -or $PulledDevicePassed.device.status -eq "Support Maintenance") { $FGColor = "green" } elseif ($PulledDevicePassed.device.status -eq "Decommission" -or $PulledDevicePassed.device.status -eq "No longer active" ) { $FGColor = "red" } else { $FGColor = "yellow" } ###################################################################################### #Output the online status in the appropriate color write-host $PulledDevicePassed.device.status -foregroundcolor $FGColor -nonewline ###################################################################################### #Writing the appropriate number of tabs to make things line up if ($PulledDevicePassed.device.status.length -le 7) {write-host "`t`t`t`t" -nonewline} elseif ($PulledDevicePassed.device.status.length -le 15) {write-host "`t`t`t" -nonewline} elseif ($PulledDevicePassed.device.status.length -le 23) {write-host "`t`t" -nonewline} else {write-host "`t" -nonewline} ###################################################################################### #Writing the account number and an appropriate number of tabs write-host $PulledDevicePassed.account.number -nonewline if ($PulledDevicePassed.account.type.length -le 5) {write-host "`t`t`t" -nonewline} elseif ($PulledDevicePassed.account.type.length -le 12) {write-host "`t`t" -nonewline} else {write-host "`t" -nonewline} ###################################################################################### #Writing the account type write-host $PulledDevicePassed.account.type } ########################################################################################################### Function Write-DeviceIPChanges ($PulledDevicePassed) { <# *********************************************************************************************************** This function takes the current pulled device and builds the manual steps if automation is a total failure and there is some issue with PowerShell. *********************************************************************************************************** #> $DeviceNumber = $PulledDevicePassed.account.number $AccountNumber = $PulledDevicePassed._id ###################################################################################### #Allocating the old ServiceNet IP the appropriate value if whether it exists or not if ($PulledDevicePassed.network.address.service_net_ips.source.ip_address -eq $Null) { $OldSNIP = $PulledDevicePassed.network.address.mbu_ips.source.ip_address } else { $OldSNIP = $PulledDevicePassed.network.address.service_net_ips.source.ip_address } ###################################################################################### #If the device has a destination IP allocate the variables appropriately if ($PulledDevicePassed.network.address.service_net_ips.migration.ip_address -ne $Null) { $NewSNIP = $PulledDevicePassed.network.address.service_net_ips.migration.ip_address $NewSNMask = $PulledDevicePassed.network.address.service_net_ips.migration.netmask $NewSNGW = $PulledDevicePassed.network.address.service_net_ips.migration.gateway } ###################################################################################### #Take all the data we've compiled above and output the appropriate commands if ($PulledDevicePassed.device.datacenter -like "*hkg*") { write-host "netsh interface ip add address "-nonewline -foregroundcolor "cyan" write-host " " -nonewline -foregroundcolor "yellow" write-host "$NewSNIP $NewSNMask" -foregroundcolor "cyan" write-host "netsh interface ip delete address " -nonewline -foregroundcolor "cyan" write-host " " -nonewline -foregroundcolor "yellow" write-host "addr="$OldSNIP -foregroundcolor "cyan" write-host write-host "route delete 10.226.255.0" -foregroundcolor "cyan" write-host "netsh int ip add route 10.226.255.0/24 " -foregroundcolor "cyan" -nonewline write-host " " -nonewline -foregroundcolor "yellow" write-host $NewSNGW -foregroundcolor "cyan" write-host write-host "route delete 10.191.192.0" -foregroundcolor "cyan" write-host "netsh int ip add route 10.191.192.0/20 " -nonewline -foregroundcolor "cyan" write-host " " -nonewline -foregroundcolor "yellow" write-host $NewSNGW -foregroundcolor "cyan" write-host } elseif ($PulledDevicePassed.device.datacenter -like "*lon*") { write-host "netsh interface ip add address "-nonewline -foregroundcolor "cyan" write-host " " -nonewline -foregroundcolor "yellow" write-host "$NewSNIP $NewSNMask" -foregroundcolor "cyan" write-host "netsh interface ip delete address " -nonewline -foregroundcolor "cyan" write-host " " -nonewline -foregroundcolor "yellow" write-host "addr="$OldSNIP -foregroundcolor "cyan" write-host write-host "route delete 10.252.0.0" -foregroundcolor "cyan" write-host "netsh int ip add route 10.252.0.0/24 " -foregroundcolor "cyan" -nonewline write-host " " -nonewline -foregroundcolor "yellow" write-host $NewSNGW -foregroundcolor "cyan" write-host write-host "route delete 10.253.0.0" -foregroundcolor "cyan" write-host "netsh int ip add route 10.253.0.0/24 " -foregroundcolor "cyan" -nonewline write-host " " -nonewline -foregroundcolor "yellow" write-host $NewSNGW -foregroundcolor "cyan" write-host write-host "route delete 10.191.192.0" -foregroundcolor "cyan" write-host "netsh int ip add route 10.191.192.0/20 " -nonewline -foregroundcolor "cyan" write-host " " -nonewline -foregroundcolor "yellow" write-host $NewSNGW -foregroundcolor "cyan" write-host } else { write-host "netsh interface ip add address "-nonewline -foregroundcolor "cyan" write-host " " -nonewline -foregroundcolor "yellow" write-host "$NewSNIP $NewSNMask" -foregroundcolor "cyan" write-host "netsh interface ip delete address " -nonewline -foregroundcolor "cyan" write-host " " -nonewline -foregroundcolor "yellow" write-host "addr="$OldSNIP -foregroundcolor "cyan" write-host write-host "route delete 10.191.192.0" -foregroundcolor "cyan" write-host "netsh int ip add route 10.191.192.0/20 " -nonewline -foregroundcolor "cyan" write-host " " -nonewline -foregroundcolor "yellow" write-host $NewSNGW -foregroundcolor "cyan" write-host } } ########################################################################################################### Function CountOS ($PulledDevicePassed,$CountArray) { <# *********************************************************************************************************** This function takes the current pulled device and builds the manual steps if automation is a total failure and there is some issue with PowerShell. *********************************************************************************************************** #> Switch -casesensitive ($PulledDevicePassed.device.os_name) { "Microsoft" {$CountArray.Windows++} "Linux" {$CountArray.Linux++} "Unknown" { if ($PulledDevicePassed.device.make_model -like "*for Microsoft Hyper-V*") {$CountArray.Windows++} else {$CountArray.Unknown++} } } return $CountArray } ########################################################################################################### Function Audit-ServiceNet ($ClusterObjects,$AllDevices) { <# *********************************************************************************************************** This function takes the current pulled device and builds the manual steps if automation is a total failure and there is some issue with PowerShell. *********************************************************************************************************** #> #Nodes <2 ###################################################################################### #Variable declaration $CurrentDevice = 0 #Variable for writing progress $ReturnObjects = [PSCustomObject]@{ Clusters = @(); SNetProblems = @() } ###################################################################################### # Iterating through the clusters Foreach ($Device in $ClusterObjects) { ###################################################################################### # Writing progress $CurrentDevice++ $DevicePercentageComplete = ($CurrentDevice/$ClusterObjects.count)*100 $DevicePercentageComplete = "{0:N0}" -f $DevicePercentageComplete Write-Progress -Activity "Analyzing cluster $CurrentDevice of $($ClusterObjects.count)..." -Status "$DevicePercentageComplete% Complete" -PercentComplete $DevicePercentageComplete ###################################################################################### # Checking the destination ServiceNet IP addresses. It could be in several places. if ($Device.network.address.service_net_ips.migration.ip_address -ne $Null) { $ClusterNewSNVLAN = $Device.network.address.service_net_ips.migration.vlan $ClusterNewSNIP = $Device.network.address.service_net_ips.migration.ip_address $ClusterNewMask = $Device.network.address.service_net_ips.migration.netmask $ClusterNewSNGW = $Device.network.address.service_net_ips.migration.gateway } elseif ($Device.network.address.mbu_ips.migration.ip_address -ne $Null) { $ClusterNewSNVLAN = $Device.network.address.mbu_ips.migration.vlan $ClusterNewSNIP = $Device.network.address.mbu_ips.migration.ip_address $ClusterNewMask = $Device.network.address.mbu_ips.migration.netmask $ClusterNewSNGW = $Device.network.address.mbu_ips.migration.gateway } else { $ClusterNewSNVLAN = "No destination VLAN detected." $ClusterNewSNIP = "" } # Looking for the source ServiceNet IP data for the cluster object. It could be in two different places if ($Device.network.address.mbu_ips.source.ip_address -ne $Null) { $SourceSNIP = $Device.network.address.mbu_ips.source.ip_address } elseif ($Device.network.address.service_net_ips.source.ip_address -ne $Null) { $SourceSNIP = $Device.network.address.service_net_ips.source.ip_address } else { $SourceSNIP = "No source cluster ServiceNet IP detected" } ###################################################################################### # Getting the details in Core for the individual cluster object. $CoreResults = Get-CoreDevice -Device $Device._id # Iterating through the list of nodes we've received. foreach ($Node in $CoreResults.attached_devices) { $DeviceNumber = $Node.load_value ###################################################################################### # Iterating through all the devices in our NSI dataset to grab the individual nodes foreach ($PolledDevice in $AllDevices.result) { # Filtering out everything but Windows devices if ($PolledDevice._id -eq $Node.load_value -and $PolledDevice.process.os_type -like "*indows*") { # Checking the destination SNet data for the node. It could be in two different places. if ($PolledDevice.network.address.service_net_ips.migration.ip_address -ne $Null) { $NewSNVLAN = $PolledDevice.network.address.service_net_ips.migration.vlan $NewSNIP = $PolledDevice.network.address.service_net_ips.migration.ip_address $RegistryCommand = "REG ADD `"HKLM\SOFTWARE\CommVault Systems\Galaxy\Instance001\Machines\"+[string]$($Device.account.number)+"-"+[string]$($Device._id)+"`" /v `"sHOSTNAME`" /t REG_SZ /d `""+$ClusterNewSNIP+"`" /f" $PS1_Command = ".\ChangeClusterIP.ps1 -OldSNIP "+$SourceSNIP+" -NewSNIP "+$ClusterNewSNIP+" -NewSNGW "+$ClusterNewSNGW+" -NewSNMask "+$clusterNewMask+" -DeviceNumber "+[string]$($Device._id)+" -Account "+[string]$($Device.account.number)+" -manual" } elseif ($PolledDevice.network.address.mbu_ips.migration.ip_address -ne $Null) { $NewSNVLAN = $PolledDevice.network.address.mbu_ips.migration.vlan $NewSNIP = $PolledDevice.network.address.mbu_ips.migration.ip_address $RegistryCommand = "REG ADD `"HKLM\SOFTWARE\CommVault Systems\Galaxy\Instance001\Machines\"+[string]$($Device.account.number)+"-"+[string]$($Device._id)+"`" /v `"sHOSTNAME`" /t REG_SZ /d `""+$NewSNIP+"`" /f" $PS1_Command = ".\ChangeClusterIP.ps1 -OldSNIP "+$SourceSNIP+" -NewSNIP "+$ClusterNewSNIP+" -NewSNGW "+$ClusterNewSNGW+" -NewSNMask "+$clusterNewMask+" -DeviceNumber "+[string]$($Device._id)+" -Account "+[string]$($Device.account.number)+" -manual" } else { $NewSNVLAN = "No destination VLAN detected." $NewSNIP = "" } # Comparing the destination VLAN numbers for the node and for the cluster. Flag if they are not the same if ($NewSNVLAN -ne $ClusterNewSNVLAN) {$VLANStatus = "WARNING - VLAN MISMATCH"} else {$VLANStatus = "Good"} # Build a PSO for each node for later writing and add to our array to return. $ClusterObject = [PSCustomObject]@{ AccountName = $Device.account.name | foreach {$_ -replace ",", ""}; AccountNumber = $Device.account.number; DeviceNumber = $Device._id; ClusterHostname = (ParseLine $Device.device.hostname 0 "." " ")[0] ClusterSourceSNIP = $SourceSNIP; ClusterNewSNVLAN = $ClusterNewSNVLAN; ClusterNewSNIP = $ClusterNewSNIP; ClusterProcessType = $Device.process.os_type; ClusterStatus = $Device.device.status NodeNumber = $Node.load_value; NodeDestSNetVLAN = $NewSNVLAN; NodeNewSNIP = $NewSNIP; NodeProcessType = $PolledDevice.process.os_type; NodeStatus = $PolledDevice.device.status; VLANStatus = $VLANStatus; RegistryCommand = $RegistryCommand; PS1_Command = $PS1_Command } $ReturnObjects.Clusters+=$ClusterObject } } } } #Resetting progress variable $CurrentDevice = 0 ###################################################################################### # Auditing the ServiceNet status of all Windows devices. foreach ($Device in $AllDevices.result) { #Writing progress $CurrentDevice++ $DevicePercentageComplete = ($CurrentDevice/$AllDevices.result.count)*100 $DevicePercentageComplete = "{0:N0}" -f $DevicePercentageComplete Write-Progress -Activity "Analyzing ServiceNet for device $CurrentDevice of $($AllDevices.result.count)..." -Status "$DevicePercentageComplete% Complete" -PercentComplete $DevicePercentageComplete -id 1 ###################################################################################### # If we've got a Windows device and it's not marked "deleted" within NSI process the device #Added in a line to include VMR devices in our audits if (($Device.process.os_type -like "*indows*" -or ($Device.process.os_type -like "*Appliance VM*" -and ($Device.device.hostname -like "*vmr*" -or $Device.device.hostname -like "*VMR*"))) -and $Device.device.status -ne "deleted" -and $Device.process.os_type -notlike "*luster*" -and $Device.device.status -ne "Computer No Longer Active" -and $Device.device.status -ne "Decommission") { # Resetting our check variables $Warning = $False $WarningMessage = "" $NoSource = $False $NoDestination = $False ###################################################################################### # Checking destination SNet IPs # If the destination SNet IP is not null and there are more than 1, flag for warning. We have to check both places destination SNet IP could be. if ($Device.network.address.service_net_ips.migration.ip_address -ne $Null) { if ($Device.network.address.service_net_ips.migration.ip_address.count -gt 1) { $Warning = $True $WarningMessage="Multiple destination ServiceNet IPs" } } elseif ($Device.network.address.mbu_ips.migration.ip_address -ne $Null) { if ($Device.network.address.mbu_ips.migration.ip_address.count -gt 1) { $Warning = $True $WarningMessage="Multiple destination ServiceNet IPs" } } else { # We get to here if there is no destination SNet assigned. We flag as such with $NoDestination. $Warning = $True $WarningMessage = "No destination ServiceNet IP detected." $NoDestination = $True } ###################################################################################### # Checking source SNet IP addresses # If the source SNet IP is not null and there are more than 1, flag for warning. We have to check both places the source SNet IP can be. if ($Device.network.address.mbu_ips.source.ip_address -ne $Null) { if ($Device.network.address.mbu_ips.source.ip_address.count -gt 1) { $Warning = $True $WarningMessage+=" Multiple source ServiceNet IPs" } } elseif ($Device.network.address.service_net_ips.source.ip_address -ne $Null) { if ($Device.network.address.service_net_ips.source.ip_address.count -gt 1) { $Warning = $True $WarningMessage+=" Multiple source ServiceNet IPs" } } else { # We get to here if there is no source SNet assigned. We flag as such with $NoSource. $Warning = $True $WarningMessage += " No source ServiceNet IP detected" $NoSource = $True } #If the device has no source and no destination IP they cancel each other out and we clear the warning flag if ($NoSource -and $NoDestination) {$Warning = $False} ###################################################################################### #If we've determined there's an issue we'll build a PSO and add it to the array that gets returned. if ($Warning -and $Device.device.status -ne "Deleted" -and $Device.device.status -notlike "*Computer No Longer Active*" -and $Device.device.status -notlike "*ecommissio*") { $SNetObject = [PSCustomObject]@{ AccountName = $Device.account.name | foreach {$_ -replace ",", ""}; AccountNumber = $Device.account.number; Type = $Device.process.os_type; DeviceNumber = $Device._id; SNetProblems = $WarningMessage } $ReturnObjects.SNetProblems+=$SNetObject } } } return $ReturnObjects } ########################################################################################################### Function Write-ClusterSNet ($Objects,$OutFile) { <# *********************************************************************************************************** This function takes an array of objects and outputs the cluster servicenet audit *********************************************************************************************************** #> ###################################################################################### # Writing the header row $OutLine = "Account Name,Account Number,Cluster Object Number,Cluster Hostname,Cluster Source SN IP,Cluster New SN VLAN,Cluster New SN IP,Cluster Process Type,Cluster Status,Node Number,Node Status,Node Dest SNet VLAN,Node New SNIP,Node Process Type,Node Status,VLAN Status,Manual Reg Command,ChangeClusterIP.ps1 Command" Set-Content $OutFile $OutLine ###################################################################################### # Iterating through cluster nodes we've found ForEach ($ClusterObject in $Objects.Clusters) { if ($ClusterObject.NodeProcessType -notlike "*inux*") { if ($ClusterObject.ClusterNewSNIP -eq "") { $OutLine = $ClusterObject.AccountName+","+$ClusterObject.AccountNumber+","+$ClusterObject.DeviceNumber+","+$ClusterObject.ClusterHostname+","+$ClusterObject.ClusterSourceSNIP+","+$ClusterObject.ClusterNewSNVLAN+","+$ClusterObject.ClusterNewSNIP+","+$ClusterObject.ClusterProcessType+","+$ClusterObject.ClusterStatus+","+$ClusterObject.NodeNumber+","+$ClusterObject.NodeStatus+","+$ClusterObject.NodeDestSNetVLAN+","+$ClusterObject.NodeNewSNIP+","+$ClusterObject.NodeProcessType+","+$ClusterObject.NodeStatus+","+$ClusterObject.VLANStatus } else { $OutLine = $ClusterObject.AccountName+","+$ClusterObject.AccountNumber+","+$ClusterObject.DeviceNumber+","+$ClusterObject.ClusterHostname+","+$ClusterObject.ClusterSourceSNIP+","+$ClusterObject.ClusterNewSNVLAN+","+$ClusterObject.ClusterNewSNIP+","+$ClusterObject.ClusterProcessType+","+$ClusterObject.ClusterStatus+","+$ClusterObject.NodeNumber+","+$ClusterObject.NodeStatus+","+$ClusterObject.NodeDestSNetVLAN+","+$ClusterObject.NodeNewSNIP+","+$ClusterObject.NodeProcessType+","+$ClusterObject.NodeStatus+","+$ClusterObject.VLANStatus+","+$ClusterObject.RegistryCommand+","+$ClusterObject.PS1_Command } Add-Content $OutFile $OutLine } } ###################################################################################### # Adding two lines in between reports Add-Content $OutFile "" Add-Content $OutFile "" ###################################################################################### # Writing header for individually identified issues $OutLine = "Account Name,Account Number,Device Number,Device Type,ServiceNet Problems" Add-Content $OutFile $OutLine ###################################################################################### # Iterating through the issues and writing them to the CSV ForEach ($SNetObject in $Objects.SNetProblems) { $OutLine = $SNetObject.AccountName+","+$SNetObject.AccountNumber+","+$SNetObject.DeviceNumber+","+$SNetObject.Type+","+$SNetObject.SNetProblems Add-Content $OutFile $OutLine } } ########################################################################################################### Function Audit-VLANs ($Objects) { <# *********************************************************************************************************** This function takes the current pulled device and builds the manual steps if automation is a total failure and there is some issue with PowerShell. *********************************************************************************************************** #> ###################################################################################### #Variable declaration $CurrentDevice = 0 #Variable for writing progress $UniqueAccounts = @() #Collecting accounts for return $UniqueAccount = $True #Check variable for unique account $UniqueEnvironment = $True #Check variable for unique environment ###################################################################################### # Iterating through the clusters Foreach ($Device in $Objects) { $CurrentDevice++ $DevicePercentageComplete = ($CurrentDevice/$Objects.count)*100 $DevicePercentageComplete = "{0:N0}" -f $DevicePercentageComplete Write-Progress -Activity "Analyzing device $CurrentDevice of $($Objects.count)..." -Status "$DevicePercentageComplete% Complete" -PercentComplete $DevicePercentageComplete $UniqueAccount = $True $UniqueEnvironment = $True foreach ($Account in $UniqueAccounts) { if ($Account.AccountNumber -eq $Device.account.number) { $UniqueAccount = $False foreach ($Environment in $Account.Environments) { if ($Environment.EnvName -eq $Device.environment.number) { $UniqueEnvironment = $False } } if ($UniqueEnvironment) { $EnvObject = [PSCustomObject]@{ EnvName = $Device.environment.number; SourceVLAN = $Device.network.vlans.source.vlan_number; DestVLAN = $Device.network.vlans.migration.vlan_number } $Account.Environments+=$EnvObject $Account.Devices+=$Device } } } if ($UniqueAccount) { $VMObject = [PSCustomObject]@{ AccountName = $Device.account.name | foreach {$_ -replace ",", ""}; AccountNumber = $Device.account.number; Environments = @() Devices = @() } $EnvObject = [PSCustomObject]@{ EnvName = $Device.environment.number; SourceVLAN = $Device.network.vlans.source.vlan_number; DestVLAN = $Device.network.vlans.migration.vlan_number } $VMObject.Environments+=$EnvObject $VMObject.Devices+=$Device $UniqueAccounts+=$VMObject } } return $UniqueAccounts } ########################################################################################################### Function Write-VLANs ($AccountList, $OutFile) { <# *********************************************************************************************************** This function takes the current pulled device and builds the manual steps if automation is a total failure and there is some issue with PowerShell. *********************************************************************************************************** #> $OutLine = "Account Name,Account Number,Environment,Source VLAN,Destination VLAN" Set-Content $OutFile $OutLine $CurrentSourceVL = $Results.result.network.vlans.source.vlan_number $CurrentDestVL = $Results.result.network.vlans.migration.vlan_number $CurrentSourceSeg = $Results.result.network.vlans.migration.network_segments ForEach ($Account in $AccountList) { foreach ($Environment in $Account.Environments) { write-host $Account.name write-host $Environment.EnvName write-host $Environment.SourceVLAN -foregroundcolor "yellow" write-host $Environment.DestVLAN -foregroundcolor "yellow" } foreach ($Device in $Account.Devices) { for ($i = 0; $i -lt $Device.network.vlans.source.vlan_number.count; $i++) { if ($Device.network.vlans.migration.vlan_number[$i] -ne 0) { $OutLine = $Account.AccountName+","+$Account.AccountNumber+","+$Device.environment.number+","+$Device.network.vlans.source.vlan_number[$i]+","+$Device.network.vlans.migration.vlan_number[$i] Add-Content $OutFile $OutLine } } } } } ########################################################################################################### #Getting start time $Stopwatch = [system.diagnostics.stopwatch]::startNew() ########################################################################################################### #Setting TLS to v1.2 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ########################################################################################################### #Getting the current directory and importing the required modules $ModuleDir=(Get-Item -Path . -Verbose).FullName $CTKModule = [string]((get-item $ModuleDir).fullname)+"\Modules\CTKCore\CTKCore.psm1" Import-Module $CTKModule -force -DisableNameChecking $VoyageModule = [string]((get-item $ModuleDir).fullname)+"\Modules\VoyageHandlers\VoyageHandlers.psm1" Import-Module $VoyageModule -force -DisableNameChecking $TextModule = [string]((get-item $ModuleDir).fullname)+"\Modules\TextHandlers\TextHandlers.psm1" Import-Module $TextModule -force -DisableNameChecking ########################################################################################################### #Checking CORE token try {$Testing = Get-CoreDevice -Device 879665} catch {Get-CoreToken} ########################################################################################################### #Construct the appropriate URI based on input if ($ORD1_07) { $URI = "https://dbapi.nsi.rackspace.com/migration/ord1_07/Find" } <#/ elseif ($SYD2) { $URI = "https://dbapi.nsi.rackspace.com/migration/syd2_02/Find" } elseif ($FRA1) { $URI = "https://dbapi.nsi.rackspace.com/migration/fra1_01/Find" } #> else { write-host “No DC specified” -foregroundcolor "red" exit } ###################################################################################### #Variable declaration $Found = $False #Was the device found $NoDestinationServiceNet = 0 #Count of devices that do not have destination ServiceNet addresses assigned $SNIPNotConfigured = 0 #Count of devices that do not have ServiceNet addresses in the source DC $NoServiceNet = @() #Array of decices that do not have ServiceNet addresses in the source DC $SNIPNotConfigured = @() #Array of decices that do not have destination ServiceNet addresses assigned $dir=([Environment]::GetFolderPath("Desktop")) #The output directory $TimeStamp = Get-Date -Format s | foreach {$_ -replace ":", "."} $OSCount = [PSCustomObject]@{ Linux = 0; Windows = 0; Unknown = 0 } $Clusters = @() $AnalysisObject = @() ###################################################################################### #Set the appropriate output file and switches if ($Slack) { ###################################################################################### #If we've got the Slack switch enabled set the file name, set the WindowsAudit and CSV flags to true $CSVFile = "$dir\SlackDevices.csv" $WindowsAudit=$True $CSV=$True } elseif ($Voyage) { ###################################################################################### #If we've got the Voyage switch enabled set the file name, set the AllDevices and CSV flags to true $CSVFile = "$dir\$MG Voyage $TimeStamp.csv" $CSV = $True $AllDevices = $True } elseif ($hyp) {$CSVFile = "$dir\$MG Hypervisors.csv"} elseif ($ClusReg) { $Registry = $True $Cluster = $True $CSVFile = "$dir\$MG Registry Commands.csv" set-content $CSVFile "Device Number,Hostname,OS Type,OS Name,Registry Command" } elseif ($SNet) { $CSVFile = "$dir\ServiceNet Cluster Audit - $MG - $TimeStamp.csv" $Cluster = $True $Report = $True } elseif ($VLANs) { $CSVFile = "$dir\VLAN Report - $MG - $TimeStamp.csv" } elseif ($AccountSNet) { $AllDevices = $True if ($Account -eq $Null) { write-host "No account number supplied. We have nothing to go on here." -foregroundcolor "red" write-host write-host exit } else { $CSVFile = "$dir\$MG ServiceNet Report - $Timestamp.csv" $CSV = $True } } elseif ($AllSNet) { if ($MG -eq $Null) { write-host "No move group supplied. We have nothing to go on here." -foregroundcolor "red" write-host write-host exit } else { $CSVFile = "$dir\$MG ServiceNet Report - $Timestamp.csv" $CSV = $True } } ###################################################################################### #All other options we just set the CSV file name else {$CSVFile = "$dir\Device Report - $TimeStamp.csv"} ###################################################################################### #Delete existing reports if the Purge flag is set if ($Purge) {Remove-Item $dir\"Device Report*".csv} ###################################################################################### #If we've been asked for VLAN translations or hypervisors we'll automatically set the CSV file too if ($VLANs -or $Highlight -or $hyp) {$CSV = $True} ###################################################################################### #Building JSON blob based on switches submitted. We'll submit the same query but will manipulate the blob to give us different information. if ($Device) { ###################################################################################### #If we're passed a single Device we'll create the JSON blob to query just one device $JSON = @" { "query": { "_id": $Device } } "@ } elseif ($MG) { ###################################################################################### #If we're passed a move group we'll query the entire move group $JSON = @" { "query": { "move_group": "$MG" } } "@ } elseif ($Account -or ($AccountSNet -and $Account -ne $Null)) ###################################################################################### #If we're passed an account number we'll query that only { $JSON = @" { "query": { "account.number": $Account } } "@ } elseif ($Team) ###################################################################################### #Building a blob that will query on a specific team { $JSON = @" { "query": { "account.team_name": "$Team" } } "@ } else { ###################################################################################### #If we have insufficient data or switches then we stop write-host "No device number, account number, or move group supplied. We have nothing to go on here." -foregroundcolor "red" write-host write-host exit } ###################################################################################### #Pulling data from NSI database based on the switches that have been submitted write-host "Polling NSI..." -foregroundcolor "green" $Results = Invoke-RestMethod -Uri $URI -Body "$JSON" -ContentType "application/json" -Method "POST" -Headers @{"X-Auth"=$Global:Token} -TimeoutSec 120 ###################################################################################### #We've got only one device so we'll output that if ($Device) { if (!($ClusReg)) {Write-AccountDetails $Results.Result} if ($AllManual) { #Write all manual steps$ Write-DeviceIPChanges $Results.Result Write-DeviceRegKey $Results.Result $ClusReg $CSVFile } elseif ($Registry) { #Writing the registry change command Write-DeviceRegKey $Results.Result $ClusReg $CSVFile } elseif ($DRAC) { #Writing the registry change command Write-DeviceDRAC $Results.Result } else { #Write the device details Write-DeviceDetails $Results.Result } } ###################################################################################### #Anything other than $Device will likely entail output of multiple devices elseif ($MG -or $Account -or $Team -or $Highlight -or $AccountSNet -or $AllSnet) { ###################################################################################### #If the CSV file is set we'll output CSV formats for the various things if ($CSV) { if ($Voyage -or $Highlight) { #Writing headers for the Voyage CSV file Write-VoyageCSVHead $CSVFile } else { if ($VLANs) { #Writing headers for the VLAN CSV file $Outline = "Device #,Hostname,Source VLAN Number,Destination VLAN Number,Source VLAN Zone,Destination VLAN Zone, Source Network Segment,Destination Network Segment" } elseif ($Slack) { #Writing headers for the Slack CSV file $Outline = "DeviceNumber,Hostname,Type,AccountName,AccountNumber,Status,PrimaryIP" } elseif ($hyp) { #Writing headers for the Hypervisor CSV file $Outline = "DeviceNumber,Hostname,AccountName,AccountNumber,Assigned,DRAC,VMNet,HA" } elseif ($AccountSNet -or $AllSnet) { $Outline = "Account Name,Account Number,Device Number,Host Name,Device Type,Source ServiceNet IP,Destination ServiceNet IP" } else { #Writing headers for the basic CSV file $Outline = "CoreDeviceID,Hostname,Account Name,device.type,device.os_name,device.os,Status,Account Number,move_group,Service Level,device.has_mbu,MG,device.processtype,Status" } #Write the headings for the output file Set-Content $CSVFile $Outline } } ###################################################################################### #If the CSV switches are not set then output to the screen the headers if ($AllDevices -or $Report -and -not $CSV -and -not $Voyage -and -not $Highlight) { if ($Account -and -not $AccountSNet) { #If we get the account number we want to output various account details to screen Write-AccountDetails ($Results.Result[0]) } #Write the header for all devices write-host write-host "Device # Hostname`t`t`t`tDevice Type`t`t`t`t`t`tOS Type`t`t`tStatus`t`t`t`tAccount Number`tService Level" -foregroundcolor "darkgreen" } ###################################################################################### #Iterating throught the results for appropriate output foreach ($PulledDevice in $Results.result) { $Write = $False #Assuming we won't write the device unless we filter it out below ########################################################################################## #Filtering out non-Windows devices and cluster devices if (!( $PulledDevice.device.status -eq "Deleted" -or $PulledDevice.device.status -like "*ecommissi*" -or $PulledDevice.device.status -like "*omputer No Longer Activ*" -or $AllDevices -or $Cluster -or $hyp -or $VLANs -or $Voyage -or $Highlight -or $WindowsAudit -or $PulledDevice.device.make_model -like "*inux*" -or $PulledDevice.device.make_model -like "*Cisco*" -or $PulledDevice.device.make_model -like "*R720 Hyp*" -or $PulledDevice.device.make_model -like "**SAN*" -or $PulledDevice.device.make_model -like "**silon*" -or $PulledDevice.device.make_model -like "**sor Cluster*" -or $PulledDevice.device.make_model -like "**NAS*" -or $PulledDevice.device.make_model -like "**SAN*" -or $PulledDevice.device.make_model -like "**witch*" -or $PulledDevice.device.make_model -like "**alancer*" -or $PulledDevice.device.make_model -like "**irewall*" -or $PulledDevice.device.make_model -like "**aged Stor*" -or $PulledDevice.device.make_model -like "**Red Hat*" -or $PulledDevice.device.make_model -like "**etAp*" -or $PulledDevice.device.make_model -like "**MD*" -or $PulledDevice.device.make_model -like "**Appliance*" -or $PulledDevice.device.make_model -like "**VMware*" -or $PulledDevice.device.make_model -like "**Logic*" -or $PulledDevice.device.make_model -like "**indows Clus*"-or $PulledDevice.device.os_name -like "*Linux*" -or $PulledDevice.device.make_model -like "*onitoring*" -or $PulledDevice.device.make_model -like "*Rackspace DDoS Mitigation*" -or $PulledDevice.device.make_model -like "*ged Secu*" -or $PulledDevice.device.make_model -like "*DAS*" -or $PulledDevice.device.make_model -like "*VNX*" -or $PulledDevice.device.make_model -like "*Virtual Server Backup Client*" -or $PulledDevice.device.make_model -like "*Cloud Server*" -or $PulledDevice.device.make_model -like "*Virtual Server Cluster*" -or $PulledDevice.device.make_model -like "*Colocation*" -or $PulledDevice.device.make_model -eq "Virtual Machine" -or $PulledDevice.device.make_model -eq "Reserved Space" -or $PulledDevice.device.make_model -eq "PS Server" -or $PulledDevice.device.make_model -eq "Leased Line" -or $PulledDevice.device.make_model -eq "Two-Factor Authentication" -or $PulledDevice.device.make_model -eq "RackConnect RegionLink")) { ###################################################################################### #If this survives our filtering, set the write flag to true and add to appropriate count $Write = $True $OSCount = CountOS $PulledDevice $OSCount } ###################################################################################### #Identify devices that we sometimes need to keep in mind if ($Highlight) { if (( $PulledDevice.device.make_model -like "*Cluster*" -and !($PulledDevice.device.make_model -like "*Hypervisor*") -and !($PulledDevice.device.make_model -like "*NetApp*") -and !($PulledDevice.process.os_type -like "*Linux*") -and !($PulledDevice.device.hostname -like "*NTClus*") -and !($PulledDevice.device.hostname -like "*ntclus*")) -or $PulledDevice.device.make_model -like "*Duo*") { ###################################################################################### #If this survives our filtering, set the write flag to true and add to appropriate count $Write = $True $OSCount = CountOS $PulledDevice $OSCount } } ###################################################################################### #If the WindowsAudit flag is set then filter out anything that's not Windows if ($WindowsAudit) { if ($PulledDevice.process.os_type -like "*indows*" -or ($PulledDevice.device.make_model -like "*Cluster*" -and !($PulledDevice.device.make_model -like "*Hypervisor*") -and !($PulledDevice.device.make_model -like "*NetApp*") -and !($PulledDevice.process.os_type -like "*Linux*") -and !($PulledDevice.device.hostname -like "*NTClus*") -and !($PulledDevice.device.hostname -like "*ntclus*")) -or !$PulledDevice.device.make_model -like "*Duo*") { ###################################################################################### #If this survives our filtering, set the write flag to true and add to appropriate count $Write = $True $OSCount = CountOS $PulledDevice $OSCount } } ########################################################################################## #Filtering cluster devices elseif ($Cluster) { if ($PulledDevice.device.make_model -like "*Cluster*" -and $PulledDevice.device.make_model -notlike "*Hypervisor*") { $Write = $True #Setting the write flag to true #Adding things up for statistics. $OSCount = CountOS $PulledDevice $OSCount if ($PulledDevice.device.hostname -notlike "*MSDTC*" -and $PulledDevice.device.hostname -notlike "*mstdc*" -and $PulledDevice.device.hostname -notlike "*ntclus*" -and $PulledDevice.device.hostname -notlike "*NTClus*") { $Clusters+=$PulledDevice } } } elseif ($hyp) { if ($PulledDevice.device.make_model -like "*ypervisor*") { $Write = $True #Setting the write flag to true #Adding things up for statistics. $OSCount = CountOS $PulledDevice $OSCount } } #################################################################################################################################################################################### #Flagging the device for writing if we've been passed the $AllDevices flag or the $Account field elseif ($AllDevices -or $Account -or $Team -or $Voyage) { $Write = $True #Setting the write flag to true #Adding things up for statistics. $OSCount = CountOS $PulledDevice $OSCount } elseif ($VLANs -and $PulledDevice.process.os_type -like "*VM*") { $AnalysisObject+=$PulledDevice } ########################################################################################## #After we've filtered everything down if the device is flagged for writing we'll perform the the appropriate action if ($Write -and $PulledDevice.device.status -ne "Deleted" -and $PulledDevice.device.status -notlike "*omputer No Longer Activ*" -and $PulledDevice.device.status -notlike "*ecommiss*") { if ($CSV) { ########################################################################################## #If we've got the CSV flag set we'll write it out in the appropriate format if ($VLANs) {Write-DeviceVLANCSV $CSVFile $PulledDevice} elseif ($Voyage -or $Highlight) {Write-VoyageCSVLine $MG $CSVFile $PulledDevice} elseif ($Slack) {write-DeviceSlack $CSVFile $PulledDevice} elseif ($hyp) {Write-DeviceHypCSV $CSVFile $PulledDevice} elseif ($AccountSNet -or $AllSNet) {Write-DeviceSNetCSV $CSVFile $PulledDevice} else {Write-DeviceLineCSV $CSVFile $PulledDevice} } elseif ($AllManual) { if ($PulledDevice.process.os_type -like "*indows*") { Write-DeviceDetails $PulledDevice Write-DeviceIPChanges $PulledDevice Write-DeviceRegKey $PulledDevice $ClusReg $CSVFile } } ########################################################################################## #Otherwise we'll write out each device in a format commensurate with the switches passed elseif ($Report) {Write-DeviceLine $PulledDevice} elseif ($Registry) {Write-DeviceRegKey $PulledDevice $ClusReg $CSVFile} else {Write-DeviceDetails $PulledDevice} } } if (!($Report) -and !($Voyage) -and !($VLANs) -and !($ClusReg)) { ########################################################################################## #If we're not outputting a report we'll write a warning to sanity check work write-host write-host "DOUBLE CHECK ALL DEVICE DATA BEFORE RUNNING ANY COMMANDS" -foregroundcolor "red" write-host } ########################################################################################## #Writing some statsitics write-host write-host "Microsoft devices identified:`t"$OSCount.Windows -foregroundcolor "DarkCyan" write-host "Linux devices identified:`t"$OSCount.Linux -foregroundcolor "DarkCyan" write-host "Unknown devices identified:`t"$OSCount.Unknown -foregroundcolor "DarkCyan" $Total = $OSCount.Windows+$OSCount.Linux+$OSCount.Unknown write-host "Total:`t`t`t`t"$Total -foregroundcolor "green" write-host } if ($VLANs) { $AnalysisObject = Audit-VLANs $AnalysisObject $URI Write-VLANS $AnalysisObject $CSVFile } if ($SNet) { $AnalysisObject = Audit-ServiceNet $Clusters $Results Write-ClusterSNet $AnalysisObject $CSVFile } ########################################################################################## #Open Excel with the CSV we've built if ($CSV -or $ClusReg -or $SNet -or $AccountSNet -or $AllSnet) {Invoke-Item $CSVFile} ###################################################################################### #Timing functions $Stopwatch.stop() write-host write-host "Complete." -foregroundcolor "green" write-host write-host "Execution time: $($Stopwatch.Elapsed.Minutes) minutes $($Stopwatch.Elapsed.Seconds) seconds $($Stopwatch.Elapsed.Milliseconds) milliseconds." -foregroundcolor "green" write-host