Hoppa till innehåll

  • Logga in via Facebook Logga in via Twitter Logga in via Windows Live Log In with LinkedIn Log In with Google      Sign In   
  • Registrera dig nu!





Foto
- - - - -

Nice to know: optimize-vhd in Windows Server 2012

  Skriven av Mikael Nystrom , 02 August 2012 · 1132 visningar

I needed to compress a bunch of VHD’s and of course that means PowerShell so I did a (very simple) script for it. Its easy to use, just remember to set execution policy correctly before you use it otherwise the script does not run. So here it isParam
(
[parameter(mandatory=$true,HelpMessage="Please, Give a folder to start from, ok?")][ValidateNotNullOrEmpty()]$VHDPath,
[parameter(mandatory=$true,HelpMessage="Please, Give the mode, quick or full?")][ValidateNotNullOrEmpty()]$Mode
)
get-childitem $VHDPath -recurse -filter *.vhd | ForEach-Object {optimize-vhd -Path $_.FullName -Mode $Mode}

The script takes to parameters, –VHDPath and –Mode
  • The VHDPath is the starting point from where to start search for VHD and VHDx files in the form of –VHDPath C:VMs
  • The Mode is also simple to use, it takes Full, Quick, Retrim, Pretrimmed and Prezeroed. Now that does require some understanding I believe. So here is the explanation from TechNet:
Specifies the mode in which the virtual hard disk is to be optimized. For a VHD disk, the default mode is Full. For a VHDX disk, the default mode is Quick. Retrim – sends down retrims without scanning for zero blocks or reclaiming unused blocks. (Allowable only if the virtual hard disk is mounted read-only.) Quick – reclaims unused blocks, but does not scan for zero blocks. (Allowable only if the virtual hard disk is mounted read-only.) Full – scans for zero blocks and reclaims unused blocks. (Allowable only if the virtual hard disk is mounted read-only.) Pretrimmed – performs as Quick mode, but does not require the virtual hard disk to be mounted read-only. The unused space detection will be less effective than quick mode where the virtual hard disk had been mounted read-only as the scan will be unable to query information about free space in the NTFS file system within the virtual hard disk. Useful when the VHDX has been used by OS instances which are Win8 or greater or the VHDX has already been the target of this cmdlet in Retrim mode. Prezeroed – performs as Quick mode, but does not require the virtual hard disk to be mounted read-only. The unused space detection will be less effective than if the virtual hard disk had been mounted read-only as the scan will be unable to query information about free space in the NTFS file system within the virtual hard disk. Useful if a tool was run previously to zero all the free space on the virtual disk as this mode of compaction can then reclaim that space for subsequent block allocations. This form of compaction can also be useful in handling virtual hard disk containing file systems other than NTFS.
/mike
  http://feeds.wordpress.com/1.0/comments/anothermike2.wordpress.com/551/ Postad bild

Källa





Trackbacks för detta inlägg [ Trackback URL ]

Det finns inga Trackbacks för detta inlägg