I want to create a script and configure it in a backup job so that it checks before launching the backup task if the VM has a snapshot in the vCenter, if it does, that the backup task is cancelled, but continues with it.
I have tried to create it in powershell format, but it is not able to read all the Veeam commands, therefore it does not run well, instead if I launch the script by hand from powershell if the check runs well and even stops the job if there is a snapshot .
I have also tried it with a file in .bat format and the same thing happens, the check does not perform well.
The script that I have the powershell is the following:
Code: Select all
Connect-VIserver -Server IPVCENTER -Username XXXX -Password XXX
if (Get-Snapshot -VM "NAME VM"){
Write-Host "The VM has a snapshot in progress. The backup job will not run."
Stop-VBRJob -Job CORP_PRUEBASSCRIPT -Confirm:$false
Exit 1
}
else{
Write-Host "The VM does not have any snapshots in progress. The backup job will run normally."
Exit 0
}
Code: Select all
@echo off
REM Connect to vCenter server using PowerCLI
powershell -Command "Connect-VIServer -Server IPVCENTER -User XXX -Password XXX"
REM Check if the snapshot exists in the virtual machine
powershell -Command if(Get-Snapshot -VM "VM NAME") { Write-Host 'The snapshot exists. stopping the job...'; exit 1 } else { Write-Host 'The snapshot does not exist. Continuing with the backup...'; exit 0 }"
REM Disconnect from vCenter server
powershell -Command "Disconnect-VIServer -Server IPVCENTER -Confirm:$false"
As I indicated before, both scripts do not work for me with Veeam, let's see if someone can help me to make it work, either in powershell or .bat format, since Veeam support does not support these issues.