PowerShell script exchange
Post Reply
Andreas Neufert
Veeam Software
Posts: 3300
Liked: 577 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert Director of Product Management Global Alliances
Location: Germany

Script: Start-Job without console and Remote B&R SQL Server

Post by Andreas Neufert » Jun 12, 2018 1:17 pm 1 person likes this post


I had to connect from a Server to the VBR Server without the possibillity to add a VBR client on that server and run some Veeam commands there.
As well the VBR SQL Database Server used Windows Authentication and PS had to forward the credentials to it (WSMAN CredSSP used).

Code: Select all

#On the BRE/SQL Server
#Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
#enable-wsmancredssp -role server
#set-item wsman:localhost\Shell\MaxMemoryPerShellMB 512
#Enable-PSRemoting –Force

#On the Client
#Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
#winrm quickconfig
#enable-wsmancredssp -role client -delegatecomputer fqdnofbackupserver
#set-item wsman:localhost\Shell\MaxMemoryPerShellMB 512
#winrm set winrm/config/client '@{TrustedHosts="fqdnofbackupserver"}'
#Set-Item WSMan:\localhost\Client\TrustedHosts -Value "fqdnofbackupserver" 
#Computer Configuration -> Administrative Templates -> System -> Credentials Delegation -> Allow Fresh Credentials with NTLM-only Server Authentication
#Enable and add SPN and FQDN of the Servers in the list,like this:
# WSMAN/vbrServername               
# WSMAN/vbrservername.domain.tld   
#PS with Administrative rights "gpupdate /force"

$backupserver = "fqdnofbackupserver"
$username = "domain\username"
$passwordtxt = "password"
$JobName = "jobname"

$password = convertto-securestring -string $passwordtxt -asplaintext -force
$credentials = new-object -typename System.Management.Automation.PSCredential -argumentlist $Username, $Password

#Connect to the Server
$session = New-PSSession $backupserver -authentication CredSSP -Credential $credentials

#Run PS commands there
invoke-command -session $session -scriptblock{
#now you execute commands on the target Server

#Load Veeam PS Plugin
Add-PSSnapin -Name VeeamPSSnapIn -ErrorAction SilentlyContinue

#Connect to the VBR Server
Disconnect-VBRServer | out-null
connect-vbrserver -server HQ-VBR1 -user $args[0] -password $args[1] 

#Start the Job 
$JobObject = Get-VBRJob -name $args[2]
Start-VBRJob $JobObject

#Disconnect the VBR Server
Disconnect-VBRServer | out-null

#End of the processing on the server, hand over args and close the PS session
} -argumentlist $username,$passwordtxt,$JobName
Remove-PSSession $session

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests