I'm using the InitialSessionState class to prepare the Powershell Runspace and preload some modules.
iss = InitialSessionState.CreateDefault();
iss.ImportPSModule(new[] { "SomeModules" });
//iss.ImportPSSnapIn("Microsoft.Exchange.Management.PowerShell.SnapIn", out psEx);
iss.ThrowOnRunspaceOpenError = true;
rs = RunspaceFactory.CreateRunspace(iss);
rs.Open();
Unfortunately, it's not possible to preload a Powershell Snapin (like Exchange Management Shell) because the method has been marked as deprecated: https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.runspaces.initialsessionstate.importpssnapin?view=powershellsdk-7.0.0
Is there any alternative for this method? Loading the Snapin as a module does not work.