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 {    
      [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.

Rudolf Kleijwegt

I am an experienced IT professional with over 20 years of hands-on experience designing, deploying, and maintaining IT infrastructure in both enterprise and service provider environments. My skills span across Linux and Windows and a multitude of server applications, allowing me to excel in a wide range of IT roles. Currently, my primary focus is on Software Defined DataCenter and DevOps. I am passionate about staying up to date with the latest trends in the industry to achieve superior outcomes.


Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *