Im trying to access the exchange server using powershell in c# Here is the code i am trying to use
WSManConnectionInfo ConnectionInfo = new WSManConnectionInfo(new Uri(@"http://myexchangeserver.com"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", (PSCredential)null);
ConnectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
using (Runspace runspace = RunspaceFactory.CreateRunspace(ConnectionInfo))
{
using (PowerShell PS_Instance = PowerShell.Create())
{
PS_Instance.AddCommand("Get-MailboxPermission -Identity UAT_TestGeneric");
runspace.Open();
PS_Instance.Runspace = runspace;
Collection<PSObject> results = PS_Instance.Invoke();
if (PS_Instance.Streams.Error.Count > 0)
{
//Couldnt Connect To Server
}
else
{
//Do Stuff
}
}
i keep getting this error message
The WinRM client received an HTTP status code of 403 from the remote WS-Management service. For more information, see the about_Remote_Troubleshooting Help topic.
I have checked the exchange servers powershell IIS folder and it doesnt require SSL as indicated here https://support.microsoft.com/en-au/kb/2276957.
Is there any one out there that can assist? Thanks.