Merge branch 'main' of https://gitea.ackcentuate.com/ackitsme/PowerShell
This commit is contained in:
commit
37adc4f178
1 file changed
+61
-48
@@ -8,8 +8,8 @@ param (
|
||||
)
|
||||
|
||||
# Variables
|
||||
$fileVersion = "1.3.1"
|
||||
$fileDate = "2026-07-02"
|
||||
$fileVersion = "1.3.3"
|
||||
$fileDate = "2026-08-04"
|
||||
$scriptName = Split-Path -Path $PSCommandPath -Leaf
|
||||
|
||||
# Display Script Banner
|
||||
@@ -160,6 +160,7 @@ for ($x = 0; $x -lt $vmlist.length; $x++) {
|
||||
$vmname = $thisvm.Name;
|
||||
$vmcpu = $thisvm.NumCPU
|
||||
$vmram = $thisvm.MemoryGB
|
||||
$vmpowerstate = ($thisvm.PowerState -eq "PoweredOn") ? "X" : ""
|
||||
$vmstorageprov = [Math]::Round($thisvm.ProvisionedSpaceGB,2)
|
||||
$vmstorageused = [Math]::Round($thisvm.UsedSpaceGB,2)
|
||||
if ((($thisvm | Get-HardDisk) | Where-Object StorageFormat -ne "Thin").length -gt 0) {
|
||||
@@ -195,6 +196,7 @@ for ($x = 0; $x -lt $vmlist.length; $x++) {
|
||||
"Name" = $vmname
|
||||
"CPU" = $vmcpu
|
||||
"RAM" = $vmram
|
||||
"Powered On" = $vmpowerstate
|
||||
"Has ISO Mounted" = $vmisomounted
|
||||
"Has Snapshots" = $vmhassnapshots
|
||||
"Provisioned Storage" = $vmstorageprov
|
||||
@@ -234,75 +236,79 @@ try {
|
||||
try {
|
||||
$sheet = $exceltable.Workbook.Worksheets["vCenter VM Data"]
|
||||
$sheet.InsertColumn(1,1)
|
||||
$sheet.Column(8) | Set-ExcelRange -NFormat '#,##0 " GB"'
|
||||
$sheet.Column(9) | Set-ExcelRange -NFormat '#,##0.00 " GB"'
|
||||
$sheet.Column(9) | Set-ExcelRange -NFormat '#,##0 " GB"'
|
||||
$sheet.Column(10) | Set-ExcelRange -NFormat '#,##0.00 " GB"'
|
||||
$sheet.Column(11) | Set-ExcelRange -NFormat '#,##0.00 " GB"'
|
||||
$sheet.Column(12) | Set-ExcelRange -NFormat '#,##0.00 " GB"'
|
||||
Set-Format -Address $sheet.Cells["2:2"] -WrapText
|
||||
$sheet.Column(1).Width = 2
|
||||
$sheet.Column(2).Width = 8
|
||||
$sheet.Cells["I:T"].Style.HorizontalAlignment = "Center"
|
||||
$sheet.Cells["D2:T2"].Style.HorizontalAlignment = "Center"
|
||||
$sheet.Cells["F:H"].Style.HorizontalAlignment = "Center" # Center align ISO and Snapshots
|
||||
$sheet.Cells["J:V"].Style.HorizontalAlignment = "Center" # Center align most columns
|
||||
$sheet.Cells["D2:U2"].Style.HorizontalAlignment = "Center" # Center align most column headings
|
||||
$sheet.Column(5).Width = 10
|
||||
$sheet.Column(6).Width = 10
|
||||
$sheet.Column(7).Width = 10
|
||||
$sheet.Column(8).Width = 10
|
||||
$sheet.Column(9).Width = 13
|
||||
$sheet.Column(10).Width = 13
|
||||
$sheet.Column(11).Width = 13
|
||||
$sheet.Column(12).Width = 12
|
||||
$sheet.Column(18).Width = 12
|
||||
$sheet.Column(12).Width = 13
|
||||
$sheet.Column(13).Width = 12
|
||||
$sheet.Column(19).Width = 12
|
||||
$sheet.Column(20).Width = 12
|
||||
$sheet.Column(21).Width = 12
|
||||
$sheet.Column(22).Width = 12
|
||||
$sheet.Column(23).Width = 12
|
||||
for($counter = 3; $counter -lt 3 + $vmcount; ++$counter) {
|
||||
Write-Progress -ID 1 -Activity "Collecting VM Information" -Status "Processing VM $($counter-2) of $($vmcount)" -PercentComplete $percent
|
||||
$CalculatedSpaceFormula = '=if(AND($J' + $counter + '>0,$J' + $counter + '<>""), $I' + $counter + ',"")'
|
||||
Set-ExcelRange -Address $sheet.Cells["K" + $counter] -Formula $CalculatedSpaceFormula
|
||||
$InProgFormula = '=IF(AND(COUNTIF(P' + $counter + ':R' + $counter + ',"X")<3,COUNTIF(P' + $counter + ':R' + $counter + ',"")<3),"X","")'
|
||||
Set-ExcelRange -Address $sheet.Cells["S" + $counter] -Formula $InProgFormula
|
||||
$MigratingFormula = '=IF(OR(P' + $counter + '="O",Q' + $counter + '="O",R' + $counter + '="O"),"X","")'
|
||||
Set-ExcelRange -Address $sheet.Cells["T" + $counter] -Formula $MigratingFormula
|
||||
$CompleteFormula = '=IF(OR(AND(P' + $counter + '="X",Q' + $counter + '="X",R' + $counter + '="X"),L' + $counter + '="O"),"X","")'
|
||||
Set-ExcelRange -Address $sheet.Cells["U" + $counter] -Formula $CompleteFormula
|
||||
$CalculatedSpaceFormula = '=if(AND($K' + $counter + '>0,$K' + $counter + '<>""), $J' + $counter + ',"")'
|
||||
Set-ExcelRange -Address $sheet.Cells["L" + $counter] -Formula $CalculatedSpaceFormula
|
||||
$InProgFormula = '=IF(OR(AND(COUNTIF(Q' + $counter + ':S' + $counter + ',"X")<3,COUNTIF(Q' + $counter + ':S' + $counter + ',"")<3),M' + $counter + '="O"),"X","")'
|
||||
Set-ExcelRange -Address $sheet.Cells["T" + $counter] -Formula $InProgFormula
|
||||
$MigratingFormula = '=IF(OR(Q' + $counter + '="O",R' + $counter + '="O",S' + $counter + '="O"),"X","")'
|
||||
Set-ExcelRange -Address $sheet.Cells["U" + $counter] -Formula $MigratingFormula
|
||||
#$CompleteFormula = '=IF(AND(Q' + $counter + '="X",R' + $counter + '="X",S' + $counter + '="X"),"X","")'
|
||||
$CompleteFormula = '=IF(AND(Q' + $counter + '="X",R' + $counter + '="X",S' + $counter + '="X",M' + $counter + '="Thin"),"X","")'
|
||||
Set-ExcelRange -Address $sheet.Cells["V" + $counter] -Formula $CompleteFormula
|
||||
}
|
||||
Write-Progress -ID 1 -Completed
|
||||
$datarange = "B3:U" + (2+$vmcount)
|
||||
$datarange = "B3:V" + (2+$vmcount)
|
||||
Add-ConditionalFormatting -Worksheet $sheet -Address $datarange -RuleType Expression -ConditionValue '=INDIRECT("VMData[@Disk Format]")="Thick"' -BackgroundColor Red -ForegroundColor White
|
||||
Add-ConditionalFormatting -Worksheet $sheet -Address $datarange -RuleType Expression -ConditionValue '=INDIRECT("VMData[@Disk Format]")="O"' -BackgroundColor Orange
|
||||
Add-ConditionalFormatting -Worksheet $sheet -Address $datarange -RuleType Expression -ConditionValue '=INDIRECT("VMData[@In Prog]")="X"' -BackgroundColor Yellow
|
||||
Add-ConditionalFormatting -Worksheet $sheet -Address $datarange -RuleType Expression -ConditionValue '=INDIRECT("VMData[@Complete]")="X"' -BackgroundColor Green
|
||||
$sheet.Cells["V4"].Value = "Total VMs:"
|
||||
$sheet.Cells["V5"].Value = "Thick Provisioned:"
|
||||
$sheet.Cells["V6"].Value = "Converting to Thin:"
|
||||
$sheet.Cells["V7"].Value = "Partially Migrated:"
|
||||
$sheet.Cells["V8"].Value = "In Progress:"
|
||||
$sheet.Cells["V9"].Value = "Completed:"
|
||||
$sheet.Cells["V10"].Value = "Remaining:"
|
||||
$sheet.Cells["V12"].Value = "Original Space Usage:"
|
||||
$sheet.Cells["V13"].Value = "New Space Usage:"
|
||||
$sheet.Cells["V14"].Value = "Space Saved:"
|
||||
$sheet.Cells["V15"].Value = "Savings:"
|
||||
$sheet.Cells["V4:V15"].Style.HorizontalAlignment = "Right"
|
||||
$sheet.Column(22).Width = 22
|
||||
$sheet.Column(23).Width = 18
|
||||
Set-ExcelRange -Address $sheet.Cells["W4"] -Formula '=COUNTA(VMData[Name])'
|
||||
Set-ExcelRange -Address $sheet.Cells["W5"] -Formula '=COUNTIF(VMData[Disk Format], "<>Thin")'
|
||||
Set-ExcelRange -Address $sheet.Cells["W6"] -Formula '=COUNTIF(VMData[Disk Format], "O")'
|
||||
Set-ExcelRange -Address $sheet.Cells["W7"] -Formula '=COUNTIF(VMData[Migrating],"X")'
|
||||
Set-ExcelRange -Address $sheet.Cells["W8"] -Formula '=COUNTIF(VMData[In Prog], "X")'
|
||||
Set-ExcelRange -Address $sheet.Cells["W9"] -Formula '=COUNTIF(VMData[Complete], "X")'
|
||||
Set-ExcelRange -Address $sheet.Cells["W10"] -Formula '=W4-W9'
|
||||
$formula = '=SUM(H3:H' + (2+$vmcount) +')'
|
||||
Set-ExcelRange -Address $sheet.Cells["W12"] -Formula $formula
|
||||
Set-ExcelRange -Address $sheet.Cells["W12"] -NFormat '#,##0.00 " GB"'
|
||||
Set-ExcelRange -Address $sheet.Cells["W13"] -Formula '=SUM(VMData[Used Space Now])'
|
||||
Set-ExcelRange -Address $sheet.Cells["W13"] -NFormat '#,##0.00 " GB"'
|
||||
Set-ExcelRange -Address $sheet.Cells["W14"] -Formula '=W12-W13'
|
||||
Set-ExcelRange -Address $sheet.Cells["W14"] -NFormat '#,##0.00 " GB"'
|
||||
Set-ExcelRange -Address $sheet.Cells["W15"] -Formula '=IF(W12>0,W14/W12,"")'
|
||||
Set-ExcelRange -Address $sheet.Cells["W15"] -NFormat '#.00%'
|
||||
$sheet.Column(11).Hidden = $true
|
||||
$sheet.Cells["W4"].Value = "Total VMs:"
|
||||
$sheet.Cells["W5"].Value = "Thick Provisioned:"
|
||||
$sheet.Cells["W6"].Value = "Converting to Thin:"
|
||||
$sheet.Cells["W7"].Value = "Partially Migrated:"
|
||||
$sheet.Cells["W8"].Value = "In Progress:"
|
||||
$sheet.Cells["W9"].Value = "Completed:"
|
||||
$sheet.Cells["W10"].Value = "Remaining:"
|
||||
$sheet.Cells["W12"].Value = "Original Space Usage:"
|
||||
$sheet.Cells["W13"].Value = "New Space Usage:"
|
||||
$sheet.Cells["W14"].Value = "Space Saved:"
|
||||
$sheet.Cells["W15"].Value = "Savings:"
|
||||
$sheet.Cells["W4:W15"].Style.HorizontalAlignment = "Right"
|
||||
$sheet.Column(23).Width = 22
|
||||
$sheet.Column(24).Width = 18
|
||||
Set-ExcelRange -Address $sheet.Cells["X4"] -Formula '=COUNTA(VMData[Name])'
|
||||
Set-ExcelRange -Address $sheet.Cells["X5"] -Formula '=COUNTIF(VMData[Disk Format], "<>Thin")'
|
||||
Set-ExcelRange -Address $sheet.Cells["X6"] -Formula '=COUNTIF(VMData[Disk Format], "O")'
|
||||
Set-ExcelRange -Address $sheet.Cells["X7"] -Formula '=COUNTIF(VMData[Migrating],"X")'
|
||||
Set-ExcelRange -Address $sheet.Cells["X8"] -Formula '=COUNTIF(VMData[In Prog], "X")'
|
||||
Set-ExcelRange -Address $sheet.Cells["X9"] -Formula '=COUNTIF(VMData[Complete], "X")'
|
||||
Set-ExcelRange -Address $sheet.Cells["X10"] -Formula '=X4-X9'
|
||||
$formula = '=SUM(I3:I' + (2+$vmcount) +')'
|
||||
Set-ExcelRange -Address $sheet.Cells["X12"] -Formula $formula
|
||||
Set-ExcelRange -Address $sheet.Cells["X12"] -NFormat '#,##0.00 " GB"'
|
||||
Set-ExcelRange -Address $sheet.Cells["X13"] -Formula '=SUM(VMData[Used Space Now])'
|
||||
Set-ExcelRange -Address $sheet.Cells["X13"] -NFormat '#,##0.00 " GB"'
|
||||
Set-ExcelRange -Address $sheet.Cells["X14"] -Formula '=X12-X13'
|
||||
Set-ExcelRange -Address $sheet.Cells["X14"] -NFormat '#,##0.00 " GB"'
|
||||
Set-ExcelRange -Address $sheet.Cells["X15"] -Formula '=IF(X12>0,X14/X12,"")'
|
||||
Set-ExcelRange -Address $sheet.Cells["X15"] -NFormat '#.00%'
|
||||
$sheet.Column(12).Hidden = $true
|
||||
} catch {
|
||||
Write-Host
|
||||
Write-Host "ERROR! Unable to create file $filename" -ForegroundColor Yellow
|
||||
@@ -323,4 +329,11 @@ try {
|
||||
$exceltable.Workbook.WorkSheets[1].Tables["VMData"].ShowFilter = $false
|
||||
Close-ExcelPackage $exceltable
|
||||
Write-Host " Success" -ForegroundColor Green
|
||||
Write-Host "Disconnecting from vCenter $vCenter... " -NoNewLine
|
||||
try {
|
||||
Disconnect-ViServer $vcconn -confirm:$false
|
||||
Write-Host "Success" -ForegroundColor Green
|
||||
} catch {
|
||||
Write-Host "Failure" -ForegroundColor Red
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user