0

I am getting an error when attempting to run the following in C#.

The error is:

Exception:Thrown Unable to load DLL wldp.dll

PowerShell ps = PowerShell.Create();
ps.AddCommand("Get-BrokerSession");
ps.AddParameter("AdminAddress");
ps.AddParameter("MYSERVERNAMEHERE");
Collection<PSObject> psr = ps.Invoke();

It's also saying that Get-BrokerSession is not a recognized command, yet I can use this at the PS command prompt without issue.

2 Answers 2

1

It could be that you have to load the Citrix-specific PowerShell modules. if your PS version is 3.0. this should resolve error: Get-BrokerSession is not a recognized command
then you can move to the next step.

InitialSessionState initial = InitialSessionState.CreateDefault();
initial.ImportPSModule(new string[] { @"C:\Temp\PSModule.psm1" });  // + Include in your PSModule.psm1: function ImportCitrixModule { Asnp Citrix* }
Runspace runspace = RunspaceFactory.CreateRunspace(initial);
initial.ThrowOnRunspaceOpenError = true;
runspace.Open();
RunspaceInvoke runSpaceInvoker = new  RunspaceInvoke(runspace); 
runSpaceInvoker.Invoke("Set-ExecutionPolicy Unrestricted");

PowerShell ps = PowerShell.Create();
ps.Runspace = runspace;
ps.AddCommand("ImportCitrixModule"); // +
Collection<PSObject> psr = ps.Invoke();
Sign up to request clarification or add additional context in comments.

2 Comments

Not working unfortunately. It runs into too many errors trying to load all those modules. I find it frustrating that I can't just load them on the server I am running the app from and have it work from the code. I can load the modules just find without error in the powershell command line, I can run the command and it works, it just won't do it when I run it from C#.
I have updated the code with some changes just to check importing module part. I don't have the Citirix PS module installed on my computer so try if this helps.
0

According to this blog post it can help to check Prefer 32-bit in the project build settings.

I ran into this error when trying to start an executable file via C# Powershell in a UnitTest project. You cannot select this option for UnitTest projects (so it didn't help me) but running my test without debugging it works as intended. I ended up not having a UnitTest/IntegrationTest...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.