I need help with a problem I've been trying to solve for a week.
I have a PowerShell script that returns a list os users from Office365 environment.
If I run the script from my PowerShell console (my machine), the script returns the expected data. If I run the script from Server (W2008 R2 SP1) PowerShell console, the script returns the expected data. If I debug my C# WebService code (from where script is executed) in my machine, the srcipt returns the expected data.
PROBLEM: If I call to the WebService hosted into the Server, the script returns NOTHING.
Code:
RunspaceConfiguration runspcConfig = RunspaceConfiguration.Create();
Runspace run = RunspaceFactory.CreateRunspace(runspcConfig);
run.ApartmentState = System.Threading.ApartmentState.STA;
run.ThreadOptions = PSThreadOptions.UseCurrentThread;
run.Open();
Pipeline pipeline = run.CreatePipeline();
Command cmd = new Command("PathScript.ps1");
cmd.Parameters.Add(new CommandParameter("DOMAIN", "domain.onmicrosoft.com"));
cmd.Parameters.Add(new CommandParameter("PRODUCT", "productReference"));
pipeline.Commands.Add(cmd);
Collection<PSObject> users=pipeline.Invoke();
Finally found the error: The type initializer for 'Microsoft.Online.Administration.Automation.ConnectMsolService' threw an exception.
The user and password are right, IUSR and "ApplicationPool user" are included in Administrator group.
Any idea?
By OP,
Problem solved: "Load User Profile" to true in IIS application pool advanced settings
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With