Hi Guys,
I've had the same problem not to know which File was generated by Start-VBRZip.
I've created a Script which would be called by the VMware Orchestrator and a "Invoke-Command". The Script returns the Filename which was created by VBRZip or the Returncode "FAILED".
Maybe it's useful for you to expand the script to move the File to another location or rename it...
What the Script is doing:
- Getting the vCenter-Object
- Getting the VM-Object
- Creating an MD5-Hash as Foldername
- Starting VBRZip using the MD5-Hash
- Extracting the Returncode of VBRZip
- Returning "FAILED" or the Filename
Code: Select all
###############
# Definitions #
###############
$vcenter = "<MYVCENTERNAME>"
$myRepository = "\\<MYSERVERNAME>\<MYFILESHARE>"
$logfile = "<MYLOGFILE.LOG>"
if ( $args.length -ne 1 )
{
Write-Warning "Calling Script with Paramenter: <VMName>"
exit
}
#Loads Veeam Powershell Snapin
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
# Mapping Argument to internal variable
$vmname = $args[0]
$tmp_date = get-date -format o
$tmp_log = $tmp_date +" START VeeamZIP for VM: $vmname" >> $logfile
############### Getting VM-Object ###############
write-host "Getting vCenter-Server-Object"
$myVcenter = Get-VBRserver | where {$_.Name -eq $vcenter}
$tmp_date = get-date -format o
$tmp_log = $tmp_date +" - Using vCenter $myVcenter" >> $logfile
write-host "Getting VM-Infos from vCenter"
$myVM = Find-VBRViEntity -Server $myVcenter -Name $vmname
if($myVM.name -ne $vmname)
{
$tmp_date = get-date -format o
$tmp_log = $tmp_date +" - VM not found in vCenter - EXITING" >> $logfile
return 99
}
$tmp_date = get-date -format o
$tmp_log = $tmp_date +" - Using VM-Entity $myVM" >> $logfile
$tmp_date = get-date -format o
$tmp_log = $tmp_date +" - Using VM-Object $myVM.Reference" >> $logfile
############### Creating MD5-Hash for FolderName ###############
$myString = get-date -format o
$cryptoServiceProvider = [System.Security.Cryptography.MD5CryptoServiceProvider];
$hashAlgorithm = new-object $cryptoServiceProvider
$hashByteArray = $hashAlgorithm.ComputeHash([Char[]]$myString);
$myMD5 = ""
foreach ($byte in $hashByteArray)
{
$myMD5 += “{0:X2}” -f $byte
}
$myFolder = "$myRepository\$myMD5\"
$tmp_date = get-date -format o
$tmp_log = $tmp_date +" - Using Target-Folder "+ $myFolder >> $logfile
############### Starting VeeamZIP ###############
write-host "Starting VeeamZIP"
$tmp_date = get-date -format o
$tmp_log = $tmp_date +" - Starting VeeamZIP: Start-VBRZip -Folder"+ $myFolder +" -Entity "+ $myVM.Name >> $logfile
$myZip = Start-VBRZip -Folder $myFolder -Entity $myVM
$tmp_date = get-date -format o
$tmp_log = $tmp_date +" - Finished VeeamZIP with Errorcode " + $myZip.Result >> $logfile
write-host $myFolder
write-host $myZip
############### Checking Result ###############
if(($myZip.Result -eq "Failed") -or $myZip.Result -eq "null")
{
$myReturn = "FAILED"
}
else
{
$myFile = Get-Childitem -Path $myFolder
$myReturn = $myFile.FullName
}
############### Return Filename or Returncode "FAILED" ###############
return $myReturn
Feel free to use, modify and extend this Script!
Regards,
Marc