PowerShell script exchange
Post Reply
Andreas Neufert
VP, Product Management
Posts: 6748
Liked: 1408 times
Joined: May 04, 2011 8:36 am
Full Name: Andreas Neufert
Location: Germany
Contact:

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

Post by Andreas Neufert » 1 person likes this post

Hi,

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" 
#
#
#gpedit.msc
#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"

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

#conversations
$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 30 guests