Why? Why would you ever need to do this remotely? And why with powershell? Those are the questions that come to mind when I created this title, except its a bit biased because I already know the answer as to why I needed to do this. Basically, I ran into a situation where I could not rdp into my Veeam backup server, nor could I get into the console. I did however need to power this server off, but didn't want to do so as it was still running replication jobs (didn't want to leave snapshots hanging around). Thus, remote powershell was the only option that I had in order to stop the replication jobs gracefully.
Hopefully you already have remote powershell setup before you get into this predicament, but if not, here's a good article on how to set it up, there is even some group policy stuff in there you can force remote powershell down.
Ok, so now that you have remote powershell setup the process of stopping the replication or backup jobs is as follows.
1. Get into a remote session with your Veeam Server (Depending on if your Veeam server is a member of the domain or if you have trusted hosts setup you may need to append -Credential Username to the end of this line)
enter-pssession VEEAM_SERVER_NAME2. Load the Veeam CMDLETS by running their initialize script.
cd C:\Program Files\Veeam\Backup and Replication ./Initialize-VeeamToolkit.ps13. Get a list of the running jobs. ( I tried get-vbrjob | where { $_.State -eq "Working" } but this didn't seem to want to return anything )
get-vbrjob
4. Assign the job you want to stop to a variable. Jobs that are currenly running have a State value of Working
$job = get-vbrjob | where { $_.Name -eq "Veeam Job Name" }5. Stop the job
stop-vbrjob $jobJust a note, you could combine steps 3, 4, and 5 by piping and doing the following but I tend to like to do things linear (its just in my nature :))
Get-VBRJOB | where {$_.name -eq "Veeam Job Name"} | Stop–
Update 10/26/2011 I got a tip from @vPowerCli from vpowercli.wordpress.com on how to get the jobs that are currently running. This is a great blog focusing solely on Veeam and Veeam CMDLETS. I recommend checking it out. Essentially you could run the command Get-VBRJob | ?{$_.GetLastState() -eq "Working"} | Stop-VBRJobThis will loop through all the running jobs and stop them respectively. For those that aren't 'linear' |
When the job has canceled you will be returned to your prompt. Just repeat steps 4 and 5 for every job you want to cancel. If you want to see a list of all of the Veeam Backup and Replication commands just type Get-VBRCommands inside Veeam Powershell. I couldn't get this command to work remotely, you have to do it on the Veeam server by going to Tools->Powershell.
Thanks for this, will add this to the teams notes if they ever need it. We had a issue where no matter what we did we could not kill a veeam job, it sat in a stopping state for ages.
we referened http://www.techieshelp.com/cancel-a-veeam-job-hung-in-a-stopping-state/
Thanks Denny for the comment….hopefully it will help you some day… I’m not the greatest powershell guy but I’m learning more and more everyday…Nice write-up as well..
Mike