Param ( [Parameter(Mandatory=$false,Position=0)][string]$Version = "3.1", #Script version [switch]$GUI, #Are we invoking this from the GUI [switch]$DFW4, #Looking for DFW4 results [switch]$IAD2, #Show all IAD2 devices [switch]$Dropouts #User wants to see the items we're not capturing in the \Dropouts directory ) ############################################################################################################################# Function ExcelTranslate ($Column,$Row) <# *********************************************************************************************************** v2.0 This function is passed a column and a row and essentially translates them from numeric or alpha values into Excel row/column values. Example 1: ExcelTranslate 2 15 Returns: B15 Example 2: ExcelTranslate H 9 Returns: H9 This function is useful when you have changing numeric data but need to reference specific columns in alpha Excel format. *********************************************************************************************************** #> { #If this is an integer we'll process it. If not we'll assume it's alphanumeric and move on if ($Column -is [int]) { #Divide the column by 26 in order to put it in a base 10 context $LetterCheck = $Column/26 #Modulus divide that number by 2 to see if we have a whole number $WholeCheck = $LetterCheck%1 #if we're further out than 26 columns (i.e. Lettercheck is >1) we need to process slightly differently because we have multiple alpha values (i.e. AZ3 rather than A3) if ($LetterCheck -gt 1) { #If WholeCheck is >0 we know we have a decimal number and we need to get the whole and decimal components of that number if ($WholeCheck -gt 0) { #Convert to string $LetterCheck = [string]$LetterCheck #Split on the decimal point $WholeNumber,$DecimalNumber = ([string]$LetterCheck).Split("{.}") #Add back the decimal point to the decimal number $DecimalNumber="."+$DecimalNumber #Convert to integer $WholeNumber = [int]$WholeNumber #Multiply the decimal number by 26 and convert to integer $DecimalNumber = [int]([decimal]$DecimalNumber*26) } else { #Divide the column by 26 and get the whole number $WholeNumber = ([math]::floor([int] $Column / [int] 26))-1 #Get the decimal remainder $DecimalNumber = $WholeCheck } } else { #If we're <1 we're in the first 26 characters and the whole number is not relevant but needs to be statically defined $WholeNumber = 0 $DecimalNumber = $Column } #Based on whether we're >26 we'll need a two-level alpha column (i.e. AD vs A). If this is zero then we only need a single letter. switch ($WholeNumber) { 0 {$ColumnProcessed=""} 1 {$ColumnProcessed="A"} 2 {$ColumnProcessed="B"} 3 {$ColumnProcessed="C"} 4 {$ColumnProcessed="D"} 5 {$ColumnProcessed="E"} 6 {$ColumnProcessed="F"} 7 {$ColumnProcessed="G"} 8 {$ColumnProcessed="H"} 9 {$ColumnProcessed="I"} 10 {$ColumnProcessed="J"} 11 {$ColumnProcessed="K"} 12 {$ColumnProcessed="L"} 13 {$ColumnProcessed="M"} 14 {$ColumnProcessed="N"} 15 {$ColumnProcessed="O"} 16 {$ColumnProcessed="P"} 17 {$ColumnProcessed="Q"} 18 {$ColumnProcessed="R"} 19 {$ColumnProcessed="S"} 20 {$ColumnProcessed="T"} 21 {$ColumnProcessed="U"} 22 {$ColumnProcessed="V"} 23 {$ColumnProcessed="W"} 24 {$ColumnProcessed="X"} 25 {$ColumnProcessed="Y"} 26 {$ColumnProcessed="Z"} } switch ($DecimalNumber) { 1 {$ColumnProcessed+="A"} 2 {$ColumnProcessed+="B"} 3 {$ColumnProcessed+="C"} 4 {$ColumnProcessed+="D"} 5 {$ColumnProcessed+="E"} 6 {$ColumnProcessed+="F"} 7 {$ColumnProcessed+="G"} 8 {$ColumnProcessed+="H"} 9 {$ColumnProcessed+="I"} 10 {$ColumnProcessed+="J"} 11 {$ColumnProcessed+="K"} 12 {$ColumnProcessed+="L"} 13 {$ColumnProcessed+="M"} 14 {$ColumnProcessed+="N"} 15 {$ColumnProcessed+="O"} 16 {$ColumnProcessed+="P"} 17 {$ColumnProcessed+="Q"} 18 {$ColumnProcessed+="R"} 19 {$ColumnProcessed+="S"} 20 {$ColumnProcessed+="T"} 21 {$ColumnProcessed+="U"} 22 {$ColumnProcessed+="V"} 23 {$ColumnProcessed+="W"} 24 {$ColumnProcessed+="X"} 25 {$ColumnProcessed+="Y"} 26 {$ColumnProcessed+="Z"} 0 {$ColumnProcessed+="Z"} } } else { $ColumnProcessed = $Column } $ColumnRow = $ColumnProcessed+[string]$Row Return $ColumnRow } ############################################################################################################################# Function GoHome { $Range=$OutSheet.Range("A1:A1") $Range.Activate() |out-null } ############################################################################################################################# Function MakeTable ($TableName,$BeginColumn,$BeginRow,$EndColumn,$EndRow) { $BeginRange = ExcelTranslate $BeginColumn $BeginRow $EndRange = ExcelTranslate $EndColumn $EndRow $Range=$OutSheet.Range("${BeginRange}:$EndRange") $Range.Activate() |out-null $ListObject = $Excel.ActiveSheet.ListObjects.Add([Microsoft.Office.Interop.Excel.XlListObjectSourceType]::xlSrcRange, $Range, $null ,[Microsoft.Office.Interop.Excel.XlYesNoGuess]::xlYes) $ListObject.Name = "$TableName" $ListObject.TableStyle = "TableStyleMedium13" } ############################################################################################################################# Function ShadeRow ($PRow,$PColumn,$PSheet) { if ($PRow %2 -ne 0) { $PSheet.cells.Item($PRow,$PColumn).Interior.ColorIndex = 23 $PSheet.cells.Item($PRow,$PColumn).font.ColorIndex = 2 } $PRow++ return $PRow } ############################################################################################################################# Function ShadeColumn ($PRow,$PColumn,$PSheet) { if ($PRow %2 -ne 0) { $PSheet.cells.Item($PRow,$PColumn).Interior.ColorIndex = 23 $PSheet.cells.Item($PRow,$PColumn).font.ColorIndex = 2 } $PColumn++ return $PColumn } ############################################################################################################################# Function Write-DeviceException ($Group,$Server,$Directory) { $Outline = $Server._id+","+$Server.device.hostname+","+$Server.device.os+","+$Server.device.os_name+","+$Server.process.os_type $OutputFile = $Directory+"\"+$Group+" Counts.csv" add-content $OutputFile $Outline } ############################################################################################################################# ###################################################################################### #Getting the current directory and importing the CTKCore module $Dir=(Get-Item -Path . -Verbose).FullName $CTKModule = [string]((get-item $Dir).parent.fullname)+"\Modules\CTKCore\CTKCore.psm1" Import-Module $CTKModule -force -DisableNameChecking ###################################################################################### #Setting TLS to v1.2 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 ###################################################################################### #Checking CORE token try { $Testing = Get-CoreDevice -Device 879665 } catch { Get-CoreToken } ###################################################################################### #Getting start time $Stopwatch = [system.diagnostics.stopwatch]::startNew() #******************************** #Excel border definitions ******* #******************************** $BorderLeft = 7 # $BorderTop = 8 # $BorderBottom = 9 # $BorderRight = 10 # $BorderInsideVertical = 11 # $BorderInsideHorizontal = 12 # #******************************** #Variable definition #Creating move groups $MoveGroups=@() if ($IAD2) { #$MoveGroups+="IAD2-IG-01" for ($i = 1; $i -le 9; $i++) { $Group = "IAD2-MG-0"+$i $MoveGroups+=$Group } for ($i = 10; $i -le 12; $i++) { $Group = "IAD2-MG-"+$i $MoveGroups+=$Group } $MoveGroups+="IAD2-CG-01" $MoveGroups+="Unassigned" $MoveGroups+="IAD2-INTERNAL" $URI = "https://dbapi.nsi.rackspace.com/migration/iad2/Find" $Destination_File = ([Environment]::GetFolderPath("Desktop"))+"\IAD2 - Counts.xlsx" $DateURI = "https://dbapi.nsi.rackspace.com/migration/iad2MoveGroups/Find" } else { for ($i = 7; $i -le 9; $i++) { $Group = "MG-0"+$i $MoveGroups+=$Group } for ($i = 10; $i -le 60; $i++) { $Group = "MG-"+$i $MoveGroups+=$Group } #$MoveGroups+="LM-99" $URI = "https://dbapi.nsi.rackspace.com/migration/dfw1/Find" $Destination_File = ([Environment]::GetFolderPath("Desktop"))+"\Counts.xlsx" $DateURI = "https://dbapi.nsi.rackspace.com/migration/dfw1MoveGroups/Find" } $Dir=(Get-Item -Path . -Verbose).FullName $AllColumn = 1 $AllRow = 1 $PhysicalColumn = 1 $PhysicalRow = 1 $MRRRow = 1 $MRRColumn = 1 $ConRow = 1 $ConColumn = 1 $CurrentMG = 0 $AllUniqueAccounts = @() ###################################################################################### #Cleaning our old dropouts if ($Dropouts) { $DropoutsDir = $Dir+"\Dropouts\" $DropoutsCSV = $DropoutsDir+"*Counts.csv" #Testing the dropouts directory and creating it if it doesn't exist if (!(test-path $DropoutsDir)) { new-item $DropoutsDir -type directory | Out-Null } #Deleting the appropriate files in the dropouts directory remove-item $DropoutsCSV } $DSANStorage = 0 $DASStorage = 0 $DNASStorage = 0 $SNASStorage = 0 $JBODStorage = 0 $Hosts = 0 foreach ($MG in $MoveGroups) { if ($MG -like "*DFW*") { } else { } $CurrentMG++ $MGPercentageComplete = ($CurrentMG/$MoveGroups.count)*100 $MGPercentageComplete = "{0:N0}" -f $MGPercentageComplete Write-Progress -Activity "Processing move group $MG" -Status "$MGPercentageComplete% Complete" -PercentComplete $MGPercentageComplete Write-Progress -Activity "Processing devices for $MG" -Status "0% Complete" -PercentComplete 0 -id 1 $JSON = @" { "query": { "move_group":"$MG" } } "@ #Querying the database write-host "Polling NSI..." -f "cyan" -nonewline $Results = (Invoke-RestMethod -Uri $URI -Body "$JSON" -ContentType "application/json" -Method "POST" -Headers @{"X-Auth"=$Global:Token} -TimeoutSec 120).result write-host "complete. $($Results.count) results found for move group $MG." -f "cyan" #Individual device counts $MRRRow = 1 $PhysicalRow = 1 $UniqueAccounts = @() $CurrentDevice = 0 $TotalAllDevices = 0 #Iterating through the devices Foreach ($Device in $Results) { $CurrentDevice++ $DevicePercentageComplete = ($CurrentDevice/$Results.result.count)*100 $ReceivedDevices = $Results.result.count $DevicePercentageComplete = "{0:N0}" -f $DevicePercentageComplete Write-Progress -Activity "Analyzing devices for $MG" -Status "Device $CurrentDevice of $ReceivedDevices, $DevicePercentageComplete% Complete" -PercentComplete $DevicePercentageComplete -id 1 $NewAccount = $True #Determining the type of device if ($Device.device.status -notlike "*ecommiss*") { $TotalAllDevices++ Switch -casesensitive -wildcard ($Device.process.os_type) { #$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ "Storage Managed" #SSAN { $SharedStorage++ } "Storage Dedicated" #SSAN { if ($Device.device.os -notlike "*Expansion Shelf*") { $DNASStorage++ } } "Storage External" #SSAN { if ($Device.device.os -like "*DSAN*" -and $Device.device.os -notlike "*Expansion Shelf*") { $DSANStorage++ $PhysicalDevices++ } } "Storage Attached" #SSAN { if ($Device.device.os -eq "Shared NAS (sNAS)") { $SNASStorage++ } elseif ($Device.device.os -like "*NAS*") { if ($Device.device.os -notlike "*Expansion Shelf*") { $DNASStorage++ } } elseif ($Device.device.os -like "*MD*") { $DASStorage++ $PhysicalDevices++ } elseif ($Device.device.os -like "*VNX*") { $DSANStorage++ $PhysicalDevices++ } } } } if ($Device.san -notlike "*alse*" -or $Device.vnx_attached -ne $Null -or $Device.vmax_attached -ne $Null) { $Hosts++ } } ###################################################################################### <#Setting the dates $DateJSON = @" { "query": { "_id":"$MG" } } "@ #$Date = ((Invoke-RestMethod -Uri $DateURI -Body "$DateJSON" -ContentType "application/json" -Method "POST" -Headers @{"X-Auth"=$Global:Token} -TimeoutSec 120).result.start.datetime| foreach {$_ -replace "/", "-"}).Split("{ }")[0] #$OutSheet.cells.Item($AllRow,$AllColumn) = $Date ###################################################################################### #Writing the individual totals for the All Devices Tab#> } write-host "DSAN: $DSANStorage" -f "green" write-host "Hosts: $Hosts" -f "cyan" write-host "NetApp: $DNASStorage" -f "yellow" ###################################################################################### #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." -foregroundcolor "green" write-host