Quick post of something I ran into this week. When creating new VMs it makes sense to create disks that have a certain size in GB. But sometimes when migrating workload from one platform to another you might see some funky hard disk sizes like this.
{@{Name=Hard disk 1; CapacityGB=49,875}, @{Name=Hard disk 2; CapacityGB=49,875}}
Fixing this for a large number of VMs can be a tedious task. So let’s automate this using a Powershell function.
function RoundUp-CapacityGB { [CmdletBinding(SupportsShouldProcess)] Param( [parameter(Mandatory=$true, ValueFromPipeline=$true)]$VMDisks ) process { foreach($VMDisk in $VMDisks){ write-host "Current size in GB`t: " -NoNewline; write-host $VMDisk.CapacityGB -ForegroundColor Yellow $Capacity = ([math]::round($VMDisk.CapacityGB,0)) write-host "New size in GB`t`t: " -NoNewline; write-host $Capacity -ForegroundColor Green Set-HardDisk -HardDisk $_ -CapacityGB $Capacity } } }
This function even supports the use of a WhatIf parameter so you can safely test it before actually changing the disk size.
0 Comments