I have researched this like crazy! And I can not get my script working to export VMs to a network location. Going through the GUI this works. I have no idea why this isn't working in my script. P.S. I am trying to run this from the Share Server. not the hypervisor.
I understand that the export process is happening under the system account, so I have granted the HyperVisor full control under NTFS and Share permissions of the network location. The fact that I am able to manually kick this off via the GUI tells me my permissions are fine?? Maybe :) Any help is much appreciated
Here is what I am doing... its very simple!
# I only want to retain 1 exported backup of my VMs
# So the first Step is to delete the old backup
Remove-ItemC:\Backup\HyperV\*-Recurse
# Setting a variable to get a list of all the VMs running on the host
$ServerList=Get-VM-ComputerNameHyperNode1.Domain.net
# Setting a variable to get all the VMs currently running
$RunningVMs=Get-VM-ComputerNameHyperNode1.Domain.net|where {$_.state -eq"running"}
# Using that variable to shut down the VMs that are running
$RunningVMs|Stop-VM-Force
# Exporting the VMs
$ServerList|Export-VM-Path\\NetworkLocation\Backup
# Starting the VMs $ServerList|Start-VM