none
PowerShell Export-VMSnapshot and Backing Up all VM HOosts RRS feed

  • General discussion

  • #region Spremembe za strežnike
    Clear
    Import-Module Hyper-V
    $EXPORTPath = "C:\Temp"
    $LOCServer = (Get-VM).ComputerName
    $VMName = (Get-VM).Name
    
    #endregion
    
    #region Naredimo Snapshot / sliko da lahko uporabniki normalno delajo naprej
    ForEach ($VMHost in $VMName)
        {
            $SNAPSHOT = Checkpoint-VM -Name $VMName -SnapshotName $_+"Arhiv" -ComputerName $LOCServer -Passthru
            $Export = Export-VMSnapshot -VMSnapshot $SNAPSHOT -Path $EXPORTPath -Passthru
            $RMSnap = Get-VMSnapshot -VMName $VMName | Where-Object {$_.CreationTime -lt (Get-Date).AddDays(-1) } | Remove-VMSnapshot
        }
    
    #endregion
    

    After starting this in Task Sheduler I recive error in PS :

    Export-VMSnapshot : Export directory already exists.
    Failed to export virtual machine 'VMHOSTNAME' because export directory named 'C:\Temp\VMHOSTNAME\Virtual Machines' already exists. (Virtual machine ID F86A60CF-744
    F-482D-A3D3-BDBC8344FAC3)

    Please need solution for creating Archive and copy VM Host to dislocated location.

    Thank you.

    Thursday, September 14, 2017 1:02 PM