Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Import-Module Hyper-V
- $date = Get-Date -Format MM-dd-yyyy
- $path = "C:\Exports\$date"
- $allVMs = Get-VM
- if (!(Test-Path $path))
- {
- New-Item $path -Type Directory
- }
- else
- {
- $exportParam = @{
- Path = $path
- Name = $Null
- ErrorAction = "Stop"
- AsJob = $True
- }
- foreach ($VM in $allVMs)
- {
- try
- {
- Export-VM @exportParam
- }
- catch
- {
- Write-Warning "Export failed. $($_.Exception.Message)"
- }
- }
- While($(Get-Job -State Running).Count -gt 0)
- {
- Start-Sleep -m 50
- }
- $successfulExports = gci $path
- Write-Verbose "Successfully exported the following VMs;"
- Write-Verbose "$successfulExports"
- $rclone = 'rclone.exe -copy --transfers=30 --stats 5s "' + $path + '" gdrive:\Transfers\NewHyperV' + $date
- &$rclone
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement