Working with VHD files and converting them
To get VHD file type information from hyper-v machines you can use this oneliner. It lists vhd and vhdx files within a folder structure and lists if the disk is Fixed or dynamic in size.
1 |
Get-ChildItem *.vhd* -Recurse | get-vhd | select path,vhdtype | ft -AutoSize |
To convert the files from a fixed format to a dynamic format, use the information from the last command.
1 |
Get-ChildItem "*.vhd*" -Recurse | ForEach-Object {Convert-VHD -path $_.fullname -vhdtype Dynamic -DestinationPath ($_.DirectoryName + "\Dyn-" + $_.BaseName + $_.Extension) | Optimize-VHD -path $_.fullname} |
I use the same file and folder name as the original but add an text before.
I use this for servers that are decommissioned but I do not want to delete. This way, they use not a lot of storage space.