locked
Resize vxhd's with Powershell RRS feed

  • Question

  • I need to resize all the vxhd's in a RDS UserProfileDisk environment. Now I know how to do it one disk at a time, but I really want to do it globally for all existing disks. This would be done out-of-hours so no-one will be logged in and using the disks when this is run.

    My script is as follows, can anyone see any fault in it?

    $vxhdlist = Get-ChildItem "E:\UserProfileDisks"-Recurse|%{$_.FullName} |Get-VHD-ErrorAction SilentlyContinue

    foreach ($vxhd in $vxhdlist)

    {

    resize-vhd -path $vxhd -SizeBytes 10GB

    $MaxSize = Get-PartitionSupportedSize

    Resize-Partition -Size $MaxSize .SizeMax }

    Friday, May 10, 2019 1:24 PM

Answers

  • My script is as follows, can anyone see any fault in it?

    You can find this out by running the script in a test environment and making sure it works as you expect.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Bill_Stewart Tuesday, April 14, 2020 1:28 PM
    Friday, May 10, 2019 6:41 PM

All replies

  • My script is as follows, can anyone see any fault in it?

    You can find this out by running the script in a test environment and making sure it works as you expect.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by Bill_Stewart Tuesday, April 14, 2020 1:28 PM
    Friday, May 10, 2019 6:41 PM
  • $vxhdlist should be a VHDObject[] object, so $vxhd is a VHDObject, and as that has a path property. 

    So, I think you will need to point to this path property in your 4. line:

    resize-vhd -path $vxhd.Path -SizeBytes
    wizend
    Friday, May 10, 2019 7:16 PM
  • You can also just do this:

    Get-ChildItem E:\UserProfileDisks\*.vhdx -Recurse | 
        Get-VHD |
        Resize-VHD -SizeBytes 10GB 


    \_(ツ)_/

    Friday, May 10, 2019 7:42 PM