Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This will run a VMWare defrag, prepare, shrink, and MS Contig defrag on a given list of VMDK files
- # requires:
- # Run as administrator
- # vmware-mount.exe, found at vmware: https://my.vmware.com/web/vmware/details?downloadGroup=VSP510-VDDK-510&productId=268
- # contig.exe, found at Microsoft: http://technet.microsoft.com/en-au/sysinternals/bb897428
- # Location of vmware-vdiskmanager.exe
- $vdiskmanager='C:\Program Files (x86)\VMware\VMware Workstation\vmware-vdiskmanager.exe'
- # Location of vmware-mount.exe
- $vmount='C:\Program Files (x86)\VMware\VMware Virtual Disk Development Kit\bin\vmware-mount.exe'
- # Location of contig.exe
- # Run it once first by double clicking it to agree with the EULA
- $contig='c:\program files (x86)\sysinternals\contig.exe'
- # Text file containing the full path of the VMDK files to shrink, one per line
- $sourcefile="d:\vmdkmaintenance\vmdklist.txt"
- # Test file containing the file size before and after shrinking
- $resultsfile="d:\vmdkmaintenance\maint.txt"
- # Drive letter to mount the VMDK as
- $mount_DriveLetter="m:"
- # ---------------------------------------------------------------------------#
- $vdisk_Defrag="-d"
- $vdisk_Prepare="-p"
- $vdisk_shrink="-k"
- $vmount_Volume="/v:"
- $vmount_Partitions="/p"
- $vmount_Dismount="/d"
- $contig_verbose="-v"
- # get the list of VMDK files and list the size
- get-content $sourcefile | foreach-object {get-childitem $_} | select fullname,length >> $resultsfile
- get-content $sourcefile | ForEach-Object {
- $activeMachine=$_;
- # Use the VMWare Disk Manager defrag on the active VMDK
- write-host "Defrag $activeMachine"
- & $vdiskmanager $vdisk_defrag $activeMachine
- # VMDK files may have multiple partitions, get the number of partitions for the active VMDK
- write-host "List Partitions $activeMachine"
- & $vmount $vmount_partitions "$activeMachine" > "$ENV:temp\VMDKPartition.txt"
- $TotalPartitions=get-content "$ENV:temp\VMDKPartition.txt" | measure-object -line
- # For each partition in the active VMDK, mount the partition to the drive letter,
- # prepare for shrinking and dismount
- for($activepartition=1; $activepartition -le $Totalpartitions.Lines; $activepartition++){
- write-host "Preparing $activeMachine partition $activepartition"
- & $vmount $mount_DriveLetter $activeMachine $vmount_Volume$activepartition
- & $vdiskmanager $vdisk_prepare $mount_DriveLetter
- & $vmount $mount_DriveLetter $vmount_Dismount
- }
- # Shrink the active VMDK
- write-host "Shrink $activeMachine"
- & $vdiskmanager $vdisk_shrink $activeMachine
- # perform contig on the active VMDK
- & $contig $contig_verbose $activeMachine
- }
- # get the list of VMDK files and list the size
- get-content $sourcefile | foreach-object {get-childitem $_} | select fullname,length >> $resultsfile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement