0

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

Gags
  • 827
  • 2
  • 13
  • 29

2 Answers2

0

The proxy settings can be configured using New-WSManSessionOption

http://technet.microsoft.com/en-us/library/hh849874.aspx

mjolinor
  • 66,130
  • 7
  • 114
  • 135
  • I read this article, but still I have a question. Say, the IP address of web proxy server is 192.168.0.2 and port is 8080. Where do I specify the ip address and port number of the proxy server in New-WSManSessionOption ? – Gags Nov 12 '13 at 00:09
0

if for example you want to configure proxy to work with fiddler, you can do it like this:

PSSessionOption sessionOptions = new PSSessionOption();
sessionOptions.ProxyAccessType = ProxyAccessType.IEConfig;
sessionOptions.ProxyAuthentication = AuthenticationMechanism.Negotiate;
wsManConnectionInfoInstance.SetSessionOptions(sessionOptions);