{"id":1313,"date":"2013-09-27T10:30:24","date_gmt":"2013-09-27T14:30:24","guid":{"rendered":"http:\/\/enterpriseadmins.org\/blog\/?p=1313"},"modified":"2026-01-02T09:51:23","modified_gmt":"2026-01-02T14:51:23","slug":"resize-guest-system-partition-with-powercli","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/resize-guest-system-partition-with-powercli\/","title":{"rendered":"Resize Guest System Partition with PowerCLI"},"content":{"rendered":"<p>I recently needed to resize system partitions on several Windows 2008R2 virtual machines. To do this with Set-HardDisk the virtual machines must be powered off and you need a helper VM. I was looking for a way to do this without downtime, as that can be arranged when executing the steps manually (grow the disk, log into the guest, rescan disks and then extend the partition). I came up with the following workaround and thought it would be worth sharing. The idea is to set the hard disk to the new size with Set-HardDisk and then use Invoke-VMScript to run diskpart from within the VM. I included the -ResizeGuestPartition switch on Set-HardDisk as that appears to complete the task of re-scanning for disks within disk manager.<\/p>\n<pre><code class=\"language-powershell\">\n$guestName=\"newDiskTest\"\n$guestUser=\"Administrator\"\n$guestPass=\"Aw3s0m3pwd\"\n$newSizeGB=40\n \nGet-HardDisk -vm \"newDiskTest\" | \n?{$_.name -eq \"hard disk 1\"} | \nSet-HardDisk -CapacityKB ($newSizeGB*1MB) -ResizeGuestPartition -GuestUser $guestUser -GuestPassword $guestPass -confirm:$false -ErrorAction:SilentlyContinue\n\nInvoke-VMScript -vm $guestName -ScriptText \"echo select vol c &gt; c:\\diskpart.txt &amp;&amp; echo extend &gt;&gt; c:\\diskpart.txt &amp;&amp; diskpart.exe \/s c:\\diskpart.txt\" -GuestUser $guestUser -GuestPassword $guestPass -ScriptType BAT\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I recently needed to resize system partitions on several Windows 2008R2 virtual machines. To do this with Set-HardDisk the virtual machines must be powered off and you need a helper VM. I was looking for a way to do this &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/resize-guest-system-partition-with-powercli\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-1313","post","type-post","status-publish","format-standard","hentry","category-scripting","category-virtualization"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=1313"}],"version-history":[{"count":2,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1313\/revisions"}],"predecessor-version":[{"id":2382,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1313\/revisions\/2382"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=1313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=1313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=1313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}