I am writing a .Net component in C# that needs to open a Remote Powershell connection for Exchange online to execute cmdlets. However there is a web proxy server that sits between local machine and internet. I have not provided proxy server settings in IE. I need to somehow provide the ip address and port number of web proxy server while opening the Remote Runspace.
I am using the following code :
PSCredential credential = new PSCredential(userEmail, securePassword);
connectionInfo = new WSManConnectionInfo(new Uri("https://ps.outlook.com/powershell"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Basic;
connectionInfo.MaximumConnectionRedirectionCount = 2;
runspace = RunspaceFactory.CreateRunspace(connectionInfo);
runspace.Open();
powershell.Runspace = runspace;
//Create the command and add a parameter
powershell.AddCommand("Get-MailboxFolderStatistics");
powershell.AddParameter("identity", sMailbox);
...
...
...
pipeline = remoteRunspace.CreatePipeline()
foreach (Command command in cmdlet.GetCommands())
{
pipeline.Commands.Add(command);
}
commandResults = pipeline.Invoke();
What should I provide in ProxyAccessType,ProxyCredentials,ProxyAuthentication properties for RunspaceconnectionInfo of Runspace object.
Is there a way to open a Remote runspace by providing web proxy server settings without having the proxy settings in IE. I want to pass the proxy server ip and port to my api via a user interface in my application
Please suggest.
Thanks, Gagan