I have this function which create a distribution exchange group (this function works well) :
private void createDistributionGroup()
{
System.Security.SecureString pass = new System.Security.SecureString();
foreach (char c in password)
pass.AppendChar(c);
PSCredential cred = new PSCredential(username, pass);
WSManConnectionInfo connection = new WSManConnectionInfo(new Uri("http://[my_exchange].[my_domain].com/PowerShell/"), "Microsoft.Exchange", cred);
connection.AuthenticationMechanism = AuthenticationMechanism.Default;
Runspace runspace = RunspaceFactory.CreateRunspace(connection);
PowerShell ps = PowerShell.Create();
try
{
runspace.Open();
ps.Runspace = runspace;
ps.AddCommand("New-DistributionGroup").AddParameter("Name", "GRP_DIF_" + textBox1.Text));
ps.Invoke();
}
finally
{
runspace.Dispose();
runspace = null;
ps.Dispose();
ps = null;
}
}
I have to execute my app using impersonation, using the msdn example I impersonate to a service account (the MSDN example works well and impersonates with success).
Before implementing impersonation the connection works, since I do impersonation when I try to execute the createDistributionGroup() function I get an error:
Access Denied : About remote troubleshooting
I have immediately tested to open remote PowerShell session in a local PowerShell using
$credential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://[my_exchange].[my_domain].com/PowerShell/ -Authentication Default -Credential $credential
Import-PSSession $Session
And the session was opened successfully...
- I have tested to change the service account permission (even domain admin he was denied...) : no effect
- I give special access on the exchange server (local admin group, ...): no effect
- I give specials IIS permissions (Frontend, backend,...) : no effect
Why when I impersonate the account is denied and how to grant access ?