C# 使用Powershell设置Exchange邮箱ACL
我试图弄明白如何做这类事情,但使用PowerShell调用(来自C#)。我们正在迁移到Exchange 2010,而我的旧代码不想工作,因此出现了PowerShellC# 使用Powershell设置Exchange邮箱ACL,c#,powershell,exchange-server-2010,C#,Powershell,Exchange Server 2010,我试图弄明白如何做这类事情,但使用PowerShell调用(来自C#)。我们正在迁移到Exchange 2010,而我的旧代码不想工作,因此出现了PowerShell IExchangeMailbox exMb = (IExchangeMailbox)userDe.NativeObject; IADsSecurityDescriptor securityDescriptor = (IADsSecurityDescriptor)exMb.MailboxRights; IADsAccessContr
IExchangeMailbox exMb = (IExchangeMailbox)userDe.NativeObject;
IADsSecurityDescriptor securityDescriptor = (IADsSecurityDescriptor)exMb.MailboxRights;
IADsAccessControlList acl = (IADsAccessControlList)securityDescriptor.DiscretionaryAcl;
AccessControlEntry ace = new AccessControlEntry();
...
...
我已通过以下方式使邮箱正常:
using (PowerShell powershell = PowerShell.Create())
{
powershell.AddCommand("Get-Mailbox");
powershell.AddParameter("Identity", username);
runspace.Open();
powershell.Runspace = runspace;
return powershell.Invoke()[0];
}
但是如果我将结果传递给一个类似的方法来获取ACL,那么我就可以开始修改它,就像这样
using (PowerShell powershell = PowerShell.Create())
{
powershell.AddCommand("Get-Acl");
powershell.AddArgument(mailbox);
runspace.Open();
powershell.Runspace = runspace;
return powershell.Invoke()[0];
}
…我明白了
术语“Get-Acl”未被识别为cmdlet的名称
…在日志中出现。我还尝试了“获取ACL”,以防它区分大小写,但我认为第一个版本是正确的
我也尝试过获取MailboxPermission,但是文档上说它甚至没有返回类型,所以它不会给我一个对象来操作
请帮助最终解决它:
powershell.AddCommand("Add-MailboxPermission");
powershell.AddParameter("Identity", mailboxIdentity);
powershell.AddParameter("User", groupName);
powershell.AddParameter("AccessRights", "FullAccess");
powershell.AddParameter("InheritanceType", "All");