Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Import-Module Hyper-V
  2.  
  3. $date = Get-Date -Format MM-dd-yyyy
  4. $path = "C:\Exports\$date"
  5.  
  6. $allVMs = Get-VM
  7.  
  8. if (!(Test-Path $path))
  9. {
  10.     New-Item $path -Type Directory
  11. }
  12. else
  13. {
  14.     $exportParam = @{
  15.         Path = $path
  16.         Name = $Null
  17.         ErrorAction = "Stop"
  18.         AsJob = $True
  19.     }
  20.    
  21.     foreach ($VM in $allVMs)
  22.     {
  23.         try
  24.         {
  25.             Export-VM @exportParam
  26.         }
  27.         catch
  28.         {
  29.             Write-Warning "Export failed. $($_.Exception.Message)"
  30.         }
  31.     }    
  32.    
  33.     While($(Get-Job -State Running).Count -gt 0)
  34.     {  
  35.         Start-Sleep -m 50
  36.     }
  37.  
  38.     $successfulExports = gci $path
  39.     Write-Verbose "Successfully exported the following VMs;"
  40.     Write-Verbose "$successfulExports"
  41.  
  42.     $rclone = 'rclone.exe -copy --transfers=30 --stats 5s "' + $path + '" gdrive:\Transfers\NewHyperV' + $date
  43.  
  44.     &$rclone
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement