Invoke PoSH

Invoke PoSH

February 26, 2013 0 By Eric Shanks

powercli

I was recently integrating Veeam Backups with HP Data Protector for a backup project when I found a great Powershell command that I didn’t know about.  Invoke-Command -comp [computername] –scriptblock {script}

If you’re familiar with PSExec.exe this is an equivalent powershell command, but if you’re not, this command will allow you to execute something on another machine.

Veeam has the ability to call a script when a backup job completes, but I needed a different server to execute that script.

So here was my solution:

In my backup job, under the advanced tab, I had Veeam execute a script upon completion.

veeamscript

 

C:WindowsSystem32WindowsPowerShellv1.0powershell.exe -noninteractive -file “C:scriptsbackupscript.ps1”

This script executes a powershell console which then calls a script that I have on my Veeam server.

The Veeam server script runs the magic!  This script calls the Invoke-command –comp [computername] which runs whatever is in the –scriptblock {} section on the remote computer!

Invoke-Command -comp Dataprotector.hollow.lab -scriptblock {\dataprotectorscriptsbackupscript.bat}

So the script I had on the Dataprotector server ran a backup to tape of my Veeam backups.  But you could use this for anything you needed to.

I should mention that in order for this to work correctly, you need to have the WinRM service running on your remote server, and you need to enable the Remote Powershell options.

Log into the Remote server and run Enable-PSRemoting –force

Please see the Microsoft TechNet article about this if you’re running this on servers that are not part of the same domain.  http://technet.microsoft.com/en-us/magazine/ff700227.aspx

I hope this information is useful to you, and a big thanks to Veeam Support for pointing me in the right direction on this!