After you punish the admin that didn't change the default Virtual Machine Location you can use this script to move the paths to same folder as the first VHD of each VM.
$vms = get-vm -ComputerName SOMEHYPERVBOX | where {$_.smartpagingfilepath -like "c:\*"} | select Name, SmartPagingfilepath
foreach ($vm in $vms) { [string]$newpath = [system.io.path]::getdirectoryname((Get-VM -ComputerName SOMEHYPERVBOX -Name $vm.name | Get-VMHardDiskDrive|select -first 1).path) [string]$name = $vm.name Move-VMStorage -ComputerName SOMEHYPERVBOX -VMName $name -SmartPagingFilePath "$newpath" -SnapshotFilePath "$newpath" } |
This works for us, you may need to tweak it to comply with the particular requirements of your environment.
Good luck and make sure that Admin never rolls servers into prod with default settings again!
Hi Ben,
ReplyDeleteDoes the smart page file location and snapshot file path should be under same path always?
Works great and correctly changes the path on the VM, but the hypervisor still puts the paging file in the old location. I've restarted the host and everything, any ideas? All I can think of is deleting the VM and starting fresh!
ReplyDeleteNevermind, I was confusing the paging file with the .bin files, which are set upon creation only and can't be moved without exporting and importing the VM. Task for another day!
ReplyDelete