PowerShell Scripting Problem

PowerShell script exchange

PowerShell Scripting Problem

Veeam Logoby Teakers » Mon Feb 17, 2014 4:51 pm

Hello,

in the past we used a Powershell script to backup one single machine into a Group. That worked very good. After we deployed on the veeam 7.0 we have to make changes on the script.

On that point I recognized that there are two different results:

First Result:
When I type "get-vbrjob" on a normal powershell commandbox he gives me a lot of information about the structure of my vbr-jobs. This information are useless to restart a single machine for that.

Second Result:
When I type "get-vbrjob" and start the powershell-console from the veeam application I get a table about my backup jobs.

My question at this point: Is there some kind of module missing in my powershell enviorment which is loading in the veeam powershell application?

The veeam powershell plugins are installed in both ways.

Thank you for your help in advance! :)
Teakers
Lurker
 
Posts: 2
Liked: never
Joined: Mon Feb 17, 2014 1:20 pm
Full Name: Dennis Bromberg

Re: PowerShell Scripting Problem

Veeam Logoby tsightler » Mon Feb 17, 2014 8:50 pm 1 person likes this post

Actually, both commands are returning the exact same objects, but when you start via the Powershell console option from within Veeam it calls an initialize script which loads some additional formatting information to make the output of the command a little more human readable. For the full details (with a few minor mistakes but the jist is correct) you can read this thread.

Or, if you just want to jump to the "how do I manually load this formatting info so that it looks the same" then the following code should work:
Code: Select all
Add-PSSnapin VeeamPSSnapIn
$snapIn = Get-PSSnapIn "VeeamPSSnapIn"
$xmlFilePath = [System.IO.Path]::Combine($snapIn.ApplicationBase, "Veeam.Backup.PowerShell.format.ps1xml")
update-formatdata -prependPath $xmlFilePath
tsightler
Veeam Software
 
Posts: 4768
Liked: 1737 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: PowerShell Scripting Problem

Veeam Logoby Petrie » Tue Feb 18, 2014 10:33 am

tsightler wrote:Or, if you just want to jump to the "how do I manually load this formatting info so that it looks the same" then the following code should work:


Tom, thank you very much! Now we know why the output within the two PS sessions is different.

But unfortunately this does not solve another problem (we thought it was because of the different formatting):

When we do something like this...

Code: Select all
Get-VBRjob -name Test123 | Start-VBRJob

...it works as expected when started in a "Veeam Powershell session".


In a "normal" Powershell session (where the Veeam-Snapin has been invoked by the "Add-PSSnapIn" command) we keep getting this error:


Code: Select all
Start-VBRJob : Exception has been thrown by the target of an invocation.
At line:1 char:40
+ Get-VBRjob -name Test123 | Start-VBRJob
+                                        ~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Start-VBRJob], TargetInvocationException
    + FullyQualifiedErrorId : System.Reflection.TargetInvocationException,Veeam.Backup.PowerShell.Command.StartVBRJob


What are we doing wrong?
Petrie
Enthusiast
 
Posts: 29
Liked: 1 time
Joined: Wed Oct 24, 2012 11:17 am
Full Name: Helge Hagedorn

Re: PowerShell Scripting Problem

Veeam Logoby v.Eremin » Tue Feb 18, 2014 10:40 am

Hi, Helge, I'm wondering whether you're running the said script under administrator account. Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: PowerShell Scripting Problem

Veeam Logoby Petrie » Tue Feb 18, 2014 10:54 am

Started with elevated rights, everything works fine.
How embarrassing is that rookie mistake, - sorry! :oops:

Of course - and as expected - this does NOT depend on the output formatting of the "Get-VBRJob" command. :wink:

The reason why we did not realize the difference is that the "Veeam PS session" does not ask for elevated rights as VBR already runs with administrative rights (and asks for it when starting the GUI).
Petrie
Enthusiast
 
Posts: 29
Liked: 1 time
Joined: Wed Oct 24, 2012 11:17 am
Full Name: Helge Hagedorn

Re: PowerShell Scripting Problem

Veeam Logoby v.Eremin » Tue Feb 18, 2014 11:11 am

No problem. Sometimes, these things might slip out of your attention. :)

Should any other questions arise, feel free to contact us.

Thanks.
v.Eremin
Veeam Software
 
Posts: 13255
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: PowerShell Scripting Problem

Veeam Logoby Petrie » Tue Feb 18, 2014 11:47 am

Thanks a lot!
Petrie
Enthusiast
 
Posts: 29
Liked: 1 time
Joined: Wed Oct 24, 2012 11:17 am
Full Name: Helge Hagedorn


Return to PowerShell



Who is online

Users browsing this forum: Exabot [Bot] and 7 guests