Hey All,
I’ve tried to get some automation for the backup of my Citrix base images. I have a script that adds a machine to the backup job based on the name. Of course, these machines get created and deleted like flies, and I was wanting to automatically remove them if they’ve been removed from vCenter. I guess I could use tags, but then I’d have to rely on my Citrix admin to use the tags, and if it’s forgotten then there’s no backup, so I’ve decided a script is the way to go.
So adding machines to the jobs works wonderfully, but I can’t seem to nail the way to remove the machines that aren’t in vCenter inventory. I also have the auto delete from backups turned on to prune the base images after x days.
Here’s the snippet of powershell causing issues:
#Searches the backup job to find any VM that don't have a size associated with the VM and assigns it to the variable ie. VM is still in the job but the VM is deleted.
$NullVM = Get-VBRJobObject -job $Citrixbackupjob | Where-Object -Property ApproxSizeString -eq -Value "0 B"
#Checks if the above variable is null. If it isn't, it removes them from the job.
if ($NullVM){
Remove-VBRJobObject $NullVM
}
This part of the script used to work since the approxsizestring use to report the size in vCenter, and if the machine isn’t there, it would report a size of 0GB, now it’s reporting the VM size when it was added to the job.
Anyone have a good way to automatically remove a VM from a job when the VM size is 0 (or any other programmatic method that can be nailed down in a script)?
Thanks,
Ryan