PowerShell script exchange
Post Reply
gvinpin
Enthusiast
Posts: 48
Liked: never
Joined: Jan 01, 2006 1:01 am
Contact:

Remote PowerShell

Post by gvinpin »

I can start remote PowerShell (2008R2) session, but specific Veeam commands will not run, as like extensions not installed.
Locally (on target server) I can run Veeam specific PowerShell commands.
Something missing?
Gostev
Chief Product Officer
Posts: 31460
Liked: 6648 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: Remote PowerShell

Post by Gostev »

I know little about PowerShell, but I would check that you have PS 2.0 installed on both servers (since 1.0 does not support remote operations), and also if you have Veeam PS extensions installed on both. Thanks.
gvinpin
Enthusiast
Posts: 48
Liked: never
Joined: Jan 01, 2006 1:01 am
Contact:

Re: Remote PowerShell

Post by gvinpin »

OK, found import-psession to do it.

$s=new-pssession -computername xxxxx
import-pssession -session $s

But, when I am trying to run job called EV, using this command:

Start-VBRJob -Job EV

getting error message.
gvinpin
Enthusiast
Posts: 48
Liked: never
Joined: Jan 01, 2006 1:01 am
Contact:

Re: Remote PowerShell

Post by gvinpin »

Another update:
I need to run locally this script to start existing job called EV

$job=Get-VBRJob | where {$_.Name –eq “EV”}
Start-VBRJob –Job $job

But, I cannot run it remotely.

Basic idea is to trigger this job remotely as a part of a Symantec Enterprise Vault backup.
Anyone has any idea on how to do it?
Vitaliy S.
VP, Product Management
Posts: 27055
Liked: 2710 times
Joined: Mar 30, 2009 9:13 am
Full Name: Vitaliy Safarov
Contact:

Re: Remote PowerShell

Post by Vitaliy S. »

Are you able to trigger the same script from a batch file locally on the backup server?
gvinpin
Enthusiast
Posts: 48
Liked: never
Joined: Jan 01, 2006 1:01 am
Contact:

Re: Remote PowerShell

Post by gvinpin »

Yes,
$job=Get-VBRJob | where {$_.Name –eq “EV”}
Start-VBRJob –Job $job

works fine locally on backup server.
gvinpin
Enthusiast
Posts: 48
Liked: never
Joined: Jan 01, 2006 1:01 am
Contact:

Re: Remote PowerShell

Post by gvinpin »

Should I raise a support call?
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Remote PowerShell

Post by Sethbartlett »

I'm guessing that when you are testing the commands locally, you are doing it within the Veeam Power shell console? It sounds like you need to do 1 of 2 things:

1. Run C:\Program Files\Veeam\Backup and Replication\Initialize-VeeamToolkit.ps1 to initialize the Veeam snap-in or
2. Run the command "Add-PSSnapin VeeamPSSnapIn" so you can use the Veeam powershell commands.
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
gvinpin
Enthusiast
Posts: 48
Liked: never
Joined: Jan 01, 2006 1:01 am
Contact:

Re: Remote PowerShell

Post by gvinpin »

Sethbartlett wrote:I'm guessing that when you are testing the commands locally, you are doing it within the Veeam Power shell console? It sounds like you need to do 1 of 2 things:

1. Run C:\Program Files\Veeam\Backup and Replication\Initialize-VeeamToolkit.ps1 to initialize the Veeam snap-in or
2. Run the command "Add-PSSnapin VeeamPSSnapIn" so you can use the Veeam powershell commands.
I can use Veeam Powershell commands locally, no problems.
But, I cannot use it remotely from other computer.
I can create a PS remote session and use native PS commands, but this remote session do not recognise that backup server has VeeamPSSnapin installed.
I will try your commands anyway, thanks.
Alexey D.

Re: Remote PowerShell

Post by Alexey D. »

To use Veeam PowerShell remotely you should perform these steps:
- install WinRM service (Windows Remote Management);
- type this command in PS console:

Code: Select all

Enable-PSRemoting
Should work! Let us know if not.
gvinpin
Enthusiast
Posts: 48
Liked: never
Joined: Jan 01, 2006 1:01 am
Contact:

Re: Remote PowerShell

Post by gvinpin »

Alexey D. wrote:To use Veeam PowerShell remotely you should perform these steps:
- install WinRM service (Windows Remote Management);
- type this command in PS console:

Code: Select all

Enable-PSRemoting
Should work! Let us know if not.
I have already told several times, that I can connect remotely.
Please spend some time reading my posts.
The problem is that during remote session, I cannot run Veeam subset of cmdlets.
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Remote PowerShell

Post by Sethbartlett »

After connecting remotely, are you doing the Add-PSSnapin VeeamPSSnapIn command? Does it give you an error stating that it doesn't exist or what? Your connection outside of the Veeam box would not know about the commands without being using the snapin first.
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
gvinpin
Enthusiast
Posts: 48
Liked: never
Joined: Jan 01, 2006 1:01 am
Contact:

Re: Remote PowerShell

Post by gvinpin »

Sethbartlett wrote:After connecting remotely, are you doing the Add-PSSnapin VeeamPSSnapIn command? Does it give you an error stating that it doesn't exist or what? Your connection outside of the Veeam box would not know about the commands without being using the snapin first.
Thanks a lot, that was a missing part.

So, the final script to start existing job named EV from remote Powershell:

$s = New-PSSession -Computername server1
Enter-PSSession $s
Add-PSSnapin VeeamPSSnapIn
$job=Get-VBRJob | where {$_.Name –eq “EV”}
Start-VBRJob –Job $job
1-0-1
Enthusiast
Posts: 58
Liked: 2 times
Joined: Nov 30, 2010 1:38 pm
Full Name: Bernd
Contact:

Re: Remote PowerShell

Post by 1-0-1 »

I noticed if I run the command manually it works but if I put it into Powershell script it stops after it connects to the remote server. My script looks like this:

Code: Select all

$s = New-PSSession -Computername srvveeam02.internal.com.na
Enter-PSSession $s
Add-PSSnapin VeeamPSSnapIn
Get-VBRJob | where {$_.Name -eq "P1DR"} | Start-VBRJob -RunAsync
So once I execute the script from the command line it just stops at the remote powershell prompt. So basically it seems to stop straight after:

Code: Select all

Enter-PSSession $s 
If I execute the command one by hand it starts the remote backup job. The whole idea is that I have this script as part of a post backup command on one VEEAM Server to start the backups on another remote VEEAM Server. Cannot schedule the jobs so basically the last job on the local VEEAM server is going to start the next job on the remote VEEAM server.

I am using VEEAM Backup and Replication v5.0.2.230 (x64) on Windows 2008 R2 Standard Edition (x64) with Powershell 2.0.
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Remote PowerShell

Post by ThomasMc » 2 people like this post

try

Code: Select all

Invoke-Command -Session $s -ScriptBlock {
   Add-PsSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
   Get-VBRJob | where {$_.Name -eq "P1DR"} | Start-VBRJob -RunAsync
} 
or v6

Code: Select all

Invoke-Command -Session $s -ScriptBlock {
   Add-PsSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
   Get-VBRJob -Name "P1DR" | Start-VBRJob -RunAsync
} 
instead of entering the session


[Added]
Don't forget the housekeeping :)

Code: Select all

Get-PSSession | Remove-PSSession
1-0-1
Enthusiast
Posts: 58
Liked: 2 times
Joined: Nov 30, 2010 1:38 pm
Full Name: Bernd
Contact:

Re: Remote PowerShell

Post by 1-0-1 »

You are a champion!

Just for anybody want to use this - make sure to add your remote session declaration in front of the code block:

Code: Select all

$s = New-PSSession -Computername srvveeam02.internal.com.na
So the whole thing will look like this:

Code: Select all

$s = New-PSSession -Computername srvveeam02.internal.com.na
Invoke-Command -Session $s -ScriptBlock {
   Add-PsSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue
   Get-VBRJob | where {$_.Name -eq "P1DR"} | Start-VBRJob -RunAsync
}
I also assume this is safe to run as a post job command as long as the VEEAM service account has accesss to the powershell script? I will be able to find out only tonight as I cannot kickstart this chain without causing issues with the schedule. In my case I have added "C:\SCRIPTS\RemoteStartP1DR.ps1" to the post activity/command section of a job.
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Remote PowerShell

Post by ThomasMc » 1 person likes this post

George
Influencer
Posts: 22
Liked: never
Joined: Jan 27, 2012 12:25 pm
Full Name: George
Contact:

Start Job Remotely

Post by George »

[merged]

Hi Guys,

Whats the script to start a backup from a remote server?

I have a Veeam Server (Server A), i would like to start the backup using a script from a different server (Server B).

Thanks! :D
svenschulze
Lurker
Posts: 1
Liked: never
Joined: Aug 28, 2013 5:52 am
Contact:

[MERGED] Starting a Backup Job per Script.

Post by svenschulze »

Hi at all,

I want to start a Backup Job per Script from another Windows 2008 R2 with no veeam Sulution on it.
After the jobs's done, I need to receive the result of the backup job on the same way.
foggy
Veeam Software
Posts: 21069
Liked: 2115 times
Joined: Jul 11, 2011 10:22 am
Full Name: Alexander Fogelson
Contact:

Re: Remote PowerShell

Post by foggy »

Hello, please review this thread for the answers. If you need additional clarification, feel free to ask here. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 20 guests