Reputation: 3063
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.
Upvotes: 0
Views: 642
Reputation: 8588
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...
Upvotes: 0
Reputation: 4038
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();
Upvotes: 1