C# and Veeam Powershell not working as expected

PowerShell script exchange

C# and Veeam Powershell not working as expected

Veeam Logoby dannordquist » Wed Jan 11, 2017 12:17 pm

Hey Andreas,

I've been using some powershell script in a C# application for several years, and due to an upgrade of VEEAM, it has stopped working in part of the app.

What I mean is, I run several powershell commands, but only one of them does not return any data, and I get no errors. But, the command will return data if I run it manually in a powershell window.

Here's the script that works:
Code: Select all
     Runspace rs = RunspaceFactory.CreateRunspace();
                    PowerShell ps = PowerShell.Create();
                    ps.Runspace = rs;
                    ps.AddScript("Add-PSSnapin VeeamPSSnapin");
                    ps.AddScript("Get-VBRJob | ?{$_.IsContinuous -match \"false\"} | where {($_.GetLastResult() -eq \"Failed\") -OR ($_.GetLastResult() -eq \"Warning\")} | select name");

Code: Select all
 Runspace rs2 = RunspaceFactory.CreateRunspace();
                        PowerShell ps2 = PowerShell.Create();
                        ps2.Runspace = rs2;
                        ps2.AddScript("Add-PSSnapin VeeamPSSnapin");
                        ps2.AddScript("$Job = Get-VBRJob -name \"" + result.Members["Name"].Value + "\"");
                        ps2.AddScript("$LastSession = $Job.FindLastSession()");

                        // getlog here to get job level warnings
                        ps2.AddScript("$lastsession.logger.getlog().updatedrecords | ?{($_.status -eq \"EWarning\") -OR ($_.status -eq \"EFailed\")} | select title");

Both of those run fine and return data as always, but the following will not return data in the C# application:
Code: Select all
 Runspace rs3 = RunspaceFactory.CreateRunspace();
                    PowerShell ps3 = PowerShell.Create();
                    ps3.Runspace = rs3;
                    ps3.AddScript("Add-PSSnapin VeeamPSSnapin");
                    ps3.AddScript("Get-VBRJob | ?{$_.IsContinuous -match \"false\"} | select name, {$_.Findlastsession().creationTime}, {$_.Findlastsession().EndTime}, {$_.Findlastsession().IsFullMode}");

Like I said, this will return data if I run it manually, but nothing in my app.

It used to work fine, but an upgrade to VEEAM broke it.

Any ideas?

Thank you!
Posts: 27
Liked: 2 times
Joined: Thu Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist

Re: C# and Veeam Powershell not working as expected

Veeam Logoby sasilik » Fri Feb 03, 2017 10:34 am

Just a guess but if something returns data when you are logged in on console and using powershell/command prompt but does not if you run it some other way then it may be problem with permissions. Specifically "interactive user" permissions which you have when you are interactively logged in. If your application runs it probably does not have "interactive user" permissions.
Posts: 36
Liked: 1 time
Joined: Thu Jun 12, 2014 11:01 am
Full Name: Markko Meriniit

Re: C# and Veeam Powershell not working as expected

Veeam Logoby tdewin » Fri Feb 03, 2017 10:49 am

Also make sure you compile for 64 bit. The snapin is 64 bit only
Veeam Software
Posts: 1272
Liked: 418 times
Joined: Fri Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin

Return to PowerShell

Who is online

Users browsing this forum: No registered users and 8 guests