PowerShell script exchange
Post Reply
Tulror
Novice
Posts: 9
Liked: never
Joined: Aug 03, 2011 1:25 pm
Contact:

remote powershell and sql error

Post by Tulror » Jan 23, 2012 2:24 pm

Hi all,

I'm having some issues with remoting powershell and veeam and hopefully someone has encountered the same issue.

Code: Select all

$s = New-PSSession -Computername <servername> 

Invoke-Command -Session $s -ScriptBlock {Add-PSSnapin VeeamPSSnapIn}  
Invoke-Command -Session $s -ScriptBlock {Get-VBRJob}
When I run this command the VeeamPSSnapIn is correctly loaded and I can run the Veeam commands.
The error output of the script:
SQL server is not available
+ CategoryInfo : InvalidOperation: (Veeam.Backup.Po...mmand.GetVBRJob:GetVBRJob) [Get-VBRJob], CAppException
+ FullyQualifiedErrorId : Backup,Veeam.Backup.PowerShell.Command.GetVBRJob
The script is working. I entered the session and manually run the Get-VBRJob command the same error occurs.
When I run the Get-VBRJob command locally on the server (same account) everything works fine.

Anyone got a clue on resolving this issue?

Thanks

ThomasMc
Expert
Posts: 293
Liked: 17 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: remote powershell and sql error

Post by ThomasMc » Jan 23, 2012 2:58 pm

A quick stab in the dark but can you do this first and then try your code again

Code: Select all

Get-PSSession | Remove-PSSession

Tulror
Novice
Posts: 9
Liked: never
Joined: Aug 03, 2011 1:25 pm
Contact:

Re: remote powershell and sql error

Post by Tulror » Jan 23, 2012 3:13 pm

Hi Thomas,

U totally right but for script debugging purpose there is no need for me to close the session now from the ps1 script, I also need to manually run some other commands first.

But the command will be put in the script later.

ThomasMc
Expert
Posts: 293
Liked: 17 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: remote powershell and sql error

Post by ThomasMc » Jan 23, 2012 3:17 pm

No thats not what this was for, it was to make sure that there was no open sessions that are generating your error, we had someone on here that was using old sessions and they where cause odd issues.

Tulror
Novice
Posts: 9
Liked: never
Joined: Aug 03, 2011 1:25 pm
Contact:

Re: remote powershell and sql error

Post by Tulror » Jan 23, 2012 3:46 pm

Ah, im not reusing old sessions, i close the connections when i need to rerun the ps1 script.

ThomasMc
Expert
Posts: 293
Liked: 17 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: remote powershell and sql error

Post by ThomasMc » Jan 23, 2012 4:05 pm

Thanks, another stab would be something going on with Auth. try

Code: Select all

$secpasswd = ConvertTo-SecureString "ADPassword" -AsPlainText -Force
$mycreds = New-Object System.Management.Automation.PSCredential ("domain\administrator", $secpasswd)

$s = New-PSSession -Computername "veeam01" -Credential $mycreds

Invoke-Command -Session $s -ScriptBlock {Add-PSSnapin VeeamPSSnapIn}  
Invoke-Command -Session $s -ScriptBlock {Get-VBRJob}
I would suggest using the Domain Admin just so we can rule out permissions

Tulror
Novice
Posts: 9
Liked: never
Joined: Aug 03, 2011 1:25 pm
Contact:

Re: remote powershell and sql error

Post by Tulror » Jan 23, 2012 4:16 pm

I have tried your script with different accounts including the domain admin but the same error occurs.

It almost look like the server on which the scripts runs can't access the SQL server through a PSSession.

I have enabled the remote powershell on the SQL server and I can succesfully connect from server A (script server) to server C (SQL).
But when I run Veeam commands on Server B (Session from Server A) it fails.

ThomasMc
Expert
Posts: 293
Liked: 17 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: remote powershell and sql error

Post by ThomasMc » Jan 23, 2012 4:21 pm

I would maybe log it with support or wait until Seth gets here :)

Tulror
Novice
Posts: 9
Liked: never
Joined: Aug 03, 2011 1:25 pm
Contact:

Re: remote powershell and sql error

Post by Tulror » Jan 23, 2012 4:25 pm

Thanks, ill wait for Seth.

ThomasMc
Expert
Posts: 293
Liked: 17 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: remote powershell and sql error

Post by ThomasMc » Jan 23, 2012 4:29 pm

While we are waiting can you try this

Code: Select all

$s = New-PSSession -Computername "veeam01"
Enter-PSSession -Session $s
cd '.\Program Files\Veeam\Backup and Replication'
PS C:\Program Files\Veeam\Backup and Replication> .\Initialize-VeeamToolkit.ps1
Get-VBRJob

Tulror
Novice
Posts: 9
Liked: never
Joined: Aug 03, 2011 1:25 pm
Contact:

Re: remote powershell and sql error

Post by Tulror » Jan 23, 2012 4:37 pm

I manually entered ".\Initialize-VeeamToolkit.ps1"

Code: Select all

Welcome to the Veeam Backup PowerShell Toolkit!

To find out what commands are available, type:       Get-VBRCommand
To show documentation for all available commands:    Get-VBRToolkitDocumentation

Copyright (C) 2011 Veeam, Inc. All rights reserved.
But too bad same error:

Code: Select all

Get-VBRJob : SQL server is not available
I also tried to set the execution policy on unrestricted on the sql and veeam server but with no succes.

Sethbartlett
Expert
Posts: 282
Liked: 25 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: remote powershell and sql error

Post by Sethbartlett » Jan 24, 2012 5:44 am

Make sure you are running your powershell under 'privileged' rights. So right click powershell -> run as administrator. Try again. Also, try sticking the script you are doing into a .ps1 and running it from command prompt(powershell.exe -File "path to file") or make a bat file and try it.
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.

Tulror
Novice
Posts: 9
Liked: never
Joined: Aug 03, 2011 1:25 pm
Contact:

Re: remote powershell and sql error

Post by Tulror » Jan 24, 2012 6:46 am

Hi Seth,

The script already was in a ps1.

I tried to run in with privileged right (UAC is off though):

Code: Select all

PS E:\Powershell> .\Remote-Veeam.ps1
WARNING: You should update your PowerShell to PowerShell 2.0 version.
SQL server is not available
    + CategoryInfo          : InvalidOperation: (Veeam.Backup.Po...mmand.GetVBRJob:GetVBRJob) [Get-VBRJob], CAppExcept
   ion
    + FullyQualifiedErrorId : Backup,Veeam.Backup.PowerShell.Command.GetVBRJob
I also tried running it from the command prompt but the same issue occurs:

Code: Select all

E:\>C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe E:\Powershell\Remote-Veeam.ps1
WARNING: You should update your PowerShell to PowerShell 2.0 version.
SQL server is not available
    + CategoryInfo          : InvalidOperation: (Veeam.Backup.Po...mmand.GetVB
   RJob:GetVBRJob) [Get-VBRJob], CAppException
    + FullyQualifiedErrorId : Backup,Veeam.Backup.PowerShell.Command.GetVBRJob

ThomasMc
Expert
Posts: 293
Liked: 17 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: remote powershell and sql error

Post by ThomasMc » Jan 24, 2012 11:57 am

Heres something interesting, I was doing some test to see what happens when you access a remote SQL box;

Comp A -> Remote SQL (Domain\Thomas)
Comp A -> Veeam Server(Local DB) (Domain\Thomas)
Comp A -> Veeam Server -> Remote SQL (NT AUTHORITY\ANONYMOUS LOGON)

Tulror
Novice
Posts: 9
Liked: never
Joined: Aug 03, 2011 1:25 pm
Contact:

Re: remote powershell and sql error

Post by Tulror » Jan 24, 2012 1:30 pm

That is really interesting situation. I have tried to reproduce to connect to the sql server from session to session.
This is the outcome.

Server A > Server B (Veeam) > Server C <SQL>

Code: Select all

$s = New-PSSession -Computername <veeam fqdn>
Enter-PSSession $s

Invoke-Command -Session $s -ScriptBlock {Add-PSSnapin VeeamPSSnapIn}  
Manualy tried to enter the session to the sql server

Code: Select all

[<veeam server>]: PS C:\Users\<user>\Documents> Enter-PSSession -computername <sql server> -credential <domain>\<user>
Remote host method PushRunspace is not implemented.
    + CategoryInfo          :
    + FullyQualifiedErrorId : System.Management.Automation.Remoting.PSRemotingDataStructureException,Microsoft.PowerShell.Commands.EnterPSSessionCommand
When I try to script from within the veeam session. The session is created localy on Server A.

Code: Select all

$db = New-PSSession -Computername <sql fqdn>
Enter-PSSession $db
I can't find the PSSnapin VeeamPSSnapIn to look how the connection to the DB is being setup.

ThomasMc
Expert
Posts: 293
Liked: 17 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: remote powershell and sql error

Post by ThomasMc » Jan 30, 2012 4:07 pm

I can't test most of this as it seems to not be supported in 2003 but might be worth a go

Code: Select all

# Run elevated on the computer that will be remoting into Veeam Server
Enable-WSManCredSSP Client –DelegateComputer veeam01

# Run on the Veeam Server and SQL box
Enable-WSManCredSSP Server

# Back to the client your be connecting to veeam on again
$s = New-PSSession veeam01 -Authentication CredSSP -Credential domain\UserYourRunningAs

Invoke-Command -Session $s -ScriptBlock {
	Add-PSSnapin VeeamPSSnapIn
	Get-VBRJob
} 
Windows Remote Management (WinRM) supports the delegation of user credentials across multiple remote computers. The multi-hop support functionality can now use Credential Security Service Provider (CredSSP) for authentication. CredSSP enables an application to delegate the user’s credentials from the client computer to the target server.
CredSSP authentication is intended for environments where Kerberos delegation cannot be used. Support for CredSSP was added to allow a user to connect to a remote server and have the ability to access a second-hop machine, such as a file share.
For more information about CredSSP, see KB 951608.
Note WinRM clients and servers will support CredSSP authentication only with explicit credentials.
Windows XP, Windows Server 2003, and earlier: CredSSP is not supported.

Tulror
Novice
Posts: 9
Liked: never
Joined: Aug 03, 2011 1:25 pm
Contact:

Re: remote powershell and sql error

Post by Tulror » Feb 01, 2012 9:57 am

Hi Thomas,

Good news!

I have tested your commands and its working.

I overlooked the command "Enable-WSManCredSSP Server" which I had run only on the veeam server.
After I ran this command I get the supposed output from the Get-VBRJob.

Now I can extend my script with other command.

Thanks alot for your help!

ThomasMc
Expert
Posts: 293
Liked: 17 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: remote powershell and sql error

Post by ThomasMc » Feb 01, 2012 10:22 am

Excellent news :)

pizzim13
Enthusiast
Posts: 94
Liked: 6 times
Joined: Apr 21, 2011 7:37 pm
Contact:

PS Remoting with Veeam database on a separate DB server

Post by pizzim13 » May 01, 2012 8:39 pm

[merged]

I am seeing an issue when using powershell remoting on a veeam 6 server that has its database on a separate sql 2008r2 database server.

Code: Select all

PS H:\> New-PSSession -ComputerName "veeam" -Credential (Get-Credential) | Enter-PSSession

[veeam]: PS C:\Windows\system32> Get-VBRJob

WARNING: You should update your PowerShell to PowerShell 2.0 version.
Get-VBRJob : SQL server is not available
    + CategoryInfo          : InvalidOperation: (Veeam.Backup.Po...mmand.GetVBRJob:GetVBRJob) [Get-VBRJob], CAppExcept
   ion
    + FullyQualifiedErrorId : Backup,Veeam.Backup.PowerShell.Command.GetVBRJob
I can run Get-VBRJob locally on the Veeam server and it returns the correct results. I can run Get-VBRJob locally on a different Veeam server with a local sql db and it returns the correct results. Has anyone else seen this type of behavior?

Case [ID#5188473]

Sethbartlett
Expert
Posts: 282
Liked: 25 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: PS Remoting with Veeam database on a separate DB server

Post by Sethbartlett » May 01, 2012 9:44 pm

Check out this thread
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.

Gostev
SVP, Product Management
Posts: 24641
Liked: 3468 times
Joined: Jan 01, 2006 1:01 am
Location: Baar, Switzerland
Contact:

Re: remote powershell and sql error

Post by Gostev » May 01, 2012 9:47 pm

Also, did you mention what the warning says? Wasn't PowerShell remoting only added in v2?

ThomasMc
Expert
Posts: 293
Liked: 17 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: remote powershell and sql error

Post by ThomasMc » May 01, 2012 11:14 pm

I think the Veeamshell checks the PsVersion from the Get-Host(or its .net counterpart) which oddly enough will say its version one on a remote session.

Code: Select all

[coor01]: PS C:\> (Get-Host).Version

Major  Minor  Build  Revision
-----  -----  -----  --------
1      0      0      0

[coor01]: PS C:\> $PSVersionTable.PsVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1
so wouldn't worry about that warning

pizzim13
Enthusiast
Posts: 94
Liked: 6 times
Joined: Apr 21, 2011 7:37 pm
Contact:

Re: remote powershell and sql error

Post by pizzim13 » May 02, 2012 9:49 am

Thanks Seth/Thomas. That worked as advertised.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest