remote powershell and sql error

PowerShell script exchange

remote powershell and sql error

Veeam Logoby Tulror » Mon 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
Tulror
Novice
 
Posts: 9
Liked: never
Joined: Wed Aug 03, 2011 1:25 pm

Re: remote powershell and sql error

Veeam Logoby ThomasMc » Mon 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
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: remote powershell and sql error

Veeam Logoby Tulror » Mon 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.
Tulror
Novice
 
Posts: 9
Liked: never
Joined: Wed Aug 03, 2011 1:25 pm

Re: remote powershell and sql error

Veeam Logoby ThomasMc » Mon 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.
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: remote powershell and sql error

Veeam Logoby Tulror » Mon Jan 23, 2012 3:46 pm

Ah, im not reusing old sessions, i close the connections when i need to rerun the ps1 script.
Tulror
Novice
 
Posts: 9
Liked: never
Joined: Wed Aug 03, 2011 1:25 pm

Re: remote powershell and sql error

Veeam Logoby ThomasMc » Mon 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
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: remote powershell and sql error

Veeam Logoby Tulror » Mon 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.
Tulror
Novice
 
Posts: 9
Liked: never
Joined: Wed Aug 03, 2011 1:25 pm

Re: remote powershell and sql error

Veeam Logoby ThomasMc » Mon Jan 23, 2012 4:21 pm

I would maybe log it with support or wait until Seth gets here :)
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: remote powershell and sql error

Veeam Logoby Tulror » Mon Jan 23, 2012 4:25 pm

Thanks, ill wait for Seth.
Tulror
Novice
 
Posts: 9
Liked: never
Joined: Wed Aug 03, 2011 1:25 pm

Re: remote powershell and sql error

Veeam Logoby ThomasMc » Mon 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
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: remote powershell and sql error

Veeam Logoby Tulror » Mon 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.
Tulror
Novice
 
Posts: 9
Liked: never
Joined: Wed Aug 03, 2011 1:25 pm

Re: remote powershell and sql error

Veeam Logoby Sethbartlett » Tue 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.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: remote powershell and sql error

Veeam Logoby Tulror » Tue 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
Tulror
Novice
 
Posts: 9
Liked: never
Joined: Wed Aug 03, 2011 1:25 pm

Re: remote powershell and sql error

Veeam Logoby ThomasMc » Tue 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)
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: remote powershell and sql error

Veeam Logoby Tulror » Tue 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.
Tulror
Novice
 
Posts: 9
Liked: never
Joined: Wed Aug 03, 2011 1:25 pm

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 4 guests