PowerShell script exchange
Post Reply
Smor42
Lurker
Posts: 2
Liked: never
Joined: Jan 23, 2016 4:19 am
Full Name: Shane Morris
Location: Australia
Contact:

PSRemoteing in SureBackup

Post by Smor42 »

Hey All,

I am using the SQLChecker.vbs script to test the databases on an MSSQL server.
The account that is being used in the Credential tab in the Application Group configuration does not have access to the databases in production so will not successfully run the script

I am looking at a way of giving the account rights to the database in the SureBackup job

I have a Domain controller in the SureBackup Job and was hoping to invoke commands in a PSSession from the Veeam Backup server to the DC based on the following script
to add the account to a security group that does have access to the database

Code: Select all

param(
$server = "localhost"
)

$failure = 1
try {
    $sess = new-pssession -cn $server -Authentication Negotiate
    $hostname = Invoke-Command -Session $sess -ScriptBlock {[system.environment]::MachineName }
    Write-Host ("Got result computername {0}" -f $hostname)
    #if we got so far that would be nice
    Remove-PSSession $sess
    $failure = 0
} catch {
    write-host ("Failure {0} " -f $error[0])
}
exit $failure
found here https://github.com/tdewin/veeampowershe ... etcred.ps1

The invoke command works using the .net library in the example but I don't seem to be able to get native PowerShell cmdlets to work
i.e have tried a simple new-item command to create a file in temp but this does not work.

Code: Select all

Invoke-Command -Session $sess -ScriptBlock { New-Item -Path C:\Temp\ -Name SB_test.txt -ItemType file}
ideally, I would like to invoke an Add-ADGroupMember command with the ActiveDirectory Module on the DC

Code: Select all

invoke-command -session $sess -ScriptBlock {Param($Radmin,$Rpass) Add-ADGroupMember -Identity SG_DBAs -Members veeamtest -Credential $Radmin $Rpass} -ArgumentList $admin,$pass

My question is has anyone been able to do this or something similar and or is this possible?
am happy to look at other avenues if I'm looking at this the wrong way ?
tdewin
Veeam Software
Posts: 1818
Liked: 655 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: PSRemoteing in SureBackup

Post by tdewin »

Hi,

I got to be honest, I never test it in detail but just retested with new-item and it did work for me. However c:\temp did not exist for me so this was creating errors. For me a directory c:\s exist so I altered the script:

Code: Select all

new-item -Path "C:\s\" -Name ("{0}.txt" -f (get-date -Format "yy-MM-dd-hh-mm-ss")) -type file
However I did notice that I should add some comments to the scripts

First of all, I noticed that you need the add the server as thrustedhost (actually I just executed code below)

Code: Select all

Set-Item WSMan:\localhost\Client\TrustedHosts -Value "*" -Force
Second of all, make sure you set the correct credentials.

Third, make sure that you pass the correct arguments to the script e.g. Otherwise is just takes localhost as the servername, thus it is just created on the backup server itself.

Code: Select all

-server %vm_ip%
You can also check the output of the script in:
%programdata%\Veeam\Backup\<SureBackup_Job_Name>\Job.<SureBackup_Job_Name>.log
You can look for

Code: Select all

[ScriptTests] [Console]
I found the following in my ouput

Code: Select all

[SureBackup] [ad] [ScriptTests] [Console] Got result computername C:\s\16-08-23-03-58-51.txt
And the file was really created in the sandbox

You can "dry run" your script. Don't enable the script in Surebackup. Rather in your surebackup job setting, enable the checkbox to keep the application group running (which probably contains your ad). Than from the commandline you can run

Code: Select all

runas /netonly /user:nuc\administrator "cmd /k powershell -c c:\scr\psremote.ps1 -server 192.168.255.103"
Replace of course the user with your user and the IP with natted ip of your VM in the sandbox (this should NOT be your production ip). The cmd /k is to keep the cmd box open after execution of the script

Hope it helps!
Smor42
Lurker
Posts: 2
Liked: never
Joined: Jan 23, 2016 4:19 am
Full Name: Shane Morris
Location: Australia
Contact:

Re: PSRemoteing in SureBackup

Post by Smor42 »

thanks tdewin,

Sorry for the slow reply, have been on some operational issues.

I will give your advice a go and get back

Thanks,
Shane
Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests