i am trying to write a script to check my Backup copy Job Status, if none of them are in a 'working' status, execute another script, which would essentially shutdown my Azure VM
i have this so far, it seems to work when i run it from ISE
Code: Select all
Add-PSSnapin Veeampssnapin
$jobStatus = Get-VBRJob| Where {$_.GetLastState() -ne "Working"}
$JobStatus = ($jobs.GetLastState())
If ($JobStatus -like "Working"){$JobActive ++}
if ($JobActive -eq 0) {
write-host "Shutdown Azure Backup Server"
}
else {
write-host "Backup is running - cycle in 1 hour." }
when i run it from powershell i get this error
Code: Select all
PS E:\Cloud Backups> .\AzureCheck2.ps1
You cannot call a method on a null-valued expression.
At E:\Cloud Backups\AzureCheck2.ps1:5 char:1
+ $JobStatus = ($jobs.GetLastState())
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : InvokeMethodOnNull
any ideas?