PowerShell script exchange
Post Reply
dannordquist
Enthusiast
Posts: 27
Liked: 2 times
Joined: Oct 23, 2014 3:39 pm
Full Name: Dan Nordquist
Contact:

C# and Veeam Powershell not working as expected

Post by dannordquist »

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();
                    rs.Open();
                    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");
and

Code: Select all

 Runspace rs2 = RunspaceFactory.CreateRunspace();
                        rs2.Open();
                        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();
                    rs3.Open();
                    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!
Dan
sasilik
Expert
Posts: 104
Liked: 13 times
Joined: Jun 12, 2014 11:01 am
Full Name: Markko Meriniit
Contact:

Re: C# and Veeam Powershell not working as expected

Post by sasilik »

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.
tdewin
Veeam Software
Posts: 1775
Liked: 646 times
Joined: Mar 02, 2012 1:40 pm
Full Name: Timothy Dewin
Contact:

Re: C# and Veeam Powershell not working as expected

Post by tdewin »

Also make sure you compile for 64 bit. The snapin is 64 bit only
Post Reply

Who is online

Users browsing this forum: No registered users and 25 guests