Reputation: 1739
I'm trying to figure out how to do this kind of thing, but using PowerShell calls (from C#). We are moving to Exchange 2010 and my old code doesn't want to work, hence the PowerShell.
IExchangeMailbox exMb = (IExchangeMailbox)userDe.NativeObject;
IADsSecurityDescriptor securityDescriptor = (IADsSecurityDescriptor)exMb.MailboxRights;
IADsAccessControlList acl = (IADsAccessControlList)securityDescriptor.DiscretionaryAcl;
AccessControlEntry ace = new AccessControlEntry();
...
...
I've got the mailbox OK using:
using (PowerShell powershell = PowerShell.Create())
{
powershell.AddCommand("Get-Mailbox");
powershell.AddParameter("Identity", username);
runspace.Open();
powershell.Runspace = runspace;
return powershell.Invoke()[0];
}
But if I then pass the result to a similar method to get the ACL so I can start modifying that, like this
using (PowerShell powershell = PowerShell.Create())
{
powershell.AddCommand("Get-Acl");
powershell.AddArgument(mailbox);
runspace.Open();
powershell.Runspace = runspace;
return powershell.Invoke()[0];
}
...I get
The term 'Get-Acl' is not recognized as the name of a cmdlet
...coming out in the logs. I also tried 'Get-ACL' in case it was case sensitive but I think the first version is correct.
I also tried Get-MailboxPermission but the docs for that say it doesn't even have a return type, so it wouldn't give me an object to manipulate afterwards.
Please help
Upvotes: 0
Views: 1082
Reputation: 1739
Figured it out eventually:
powershell.AddCommand("Add-MailboxPermission");
powershell.AddParameter("Identity", mailboxIdentity);
powershell.AddParameter("User", groupName);
powershell.AddParameter("AccessRights", "FullAccess");
powershell.AddParameter("InheritanceType", "All");
Upvotes: 1