Currenlty i'm wrestling with a issue i'm facing when i try to use custom scripts to do some tests on a server during a SureBackup job.
The situation:
I followed the best practice guide from Veeam. One of the practices is to not domain join the Veeam B&R Server. So that is the case, my VEEAM B&R server is not domain joined.
What i want to do is to some more checks on a VM that is in a SureBackup application group. I found the knowledge base article to do some checks on particular services (https://www.veeam.com/blog/automate-rec ... ackup.html).
Now during some testing, i noticed that this wouldn't work, because my server is not domain joined, and trying to powershell to a domain joined machine and trying to use domain credentials simply just would'nt compute on my veeam server. So i tried it via another direction; WinRM over HTTPS.
So i made sure that WinRM over HTTPS was correctly setup on my destination machine (that i would script against during the surebackup job). Did some tests with my script from a test machine, to make sure everything would work and so fort.
Looking at my script, my eye couldn't let go the fact that my password whas in plain text just sitting there. To resolve this, I encrypted it.
Code: Select all
<# Set and encrypt credentials to file using default method #>
$credential = Get-Credential
$credentialfile = Read-Host -Prompt 'Voer hier de gewenste bestandsnaam in'
$credential.Password | ConvertFrom-SecureString | Set-Content "E:\Scripts\Credentials\$($credentialfile)_encrypted_password.txt"
So after doing that, i ran PowerShell ISE as another user (svc_veeam_scripts) and tested the script and it worked. Test it again with my admin account, and as expected it failed (due to the fact that the encrypted credential could'nt be decrypted with my admin account). So far so good.
But now here's my problem. During the Surebackup job, it failed again. And it looks like that the user running the script couldn't decrypt the credential But why?
- - I created the user on the Veeam server locally
- I created the user in Veeam itself with the same credentials
- I made sure that the credentials were encrypted with the same user
- I tested the script with the same user; no errors at all.
And here is my script:
Code: Select all
param(
[string] $ip #IP address van server
)
$username = "DOMAIN\user"
$secpasswdfile = "E:\Scripts\Credentials\svc_domainuser_encrypted_password.txt"
$secpasswd = Get-Content $secpasswdfile | ConvertTo-SecureString
$credentials = New-Object System.Management.Automation.PSCredential ($username, $secpasswd)
$soptions = New-PSSessionOption -SkipCACheck -SkipRevocationCheck -SkipCNCheck
# Start services
Invoke-Command -ComputerName $ip -UseSSL -SessionOption $soptions -Credential $credentials -ScriptBlock `
{
Start-Service -InputObject (Get-Service -Name IAS)
#Write-Output (Get-Service -Name IAS)
#Start-Sleep -s 60
# Check services status
$checkservice = (get-service -ComputerName $ip -Name IAS -ErrorAction SilentlyContinue)
if($checkservice.status -ne "Running"){$host.SetShouldExit(1)}
exit
}
#En de batch file waar SureBackup draait:
#powershell.exe -noninteractive -noprofile -command "& {E:\Scripts\Check-Services_XXX.ps1 %1 }"
#EXIT /B %errorlevel%
I searched the forum and came across a thread (powershell-f26/surebackup-custom-powers ... 63179.html) that Better Credentials module would somehow work beter? But the thread was inconclusive about this.
Hope that anyone can help me out with this one.
Kind regards,
David