0

我试图弄清楚如何做这种事情,但使用 PowerShell 调用(来自 C#)。我们正在迁移到 Exchange 2010,而我的旧代码不想工作,因此使用了 PowerShell。

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 的名称

...从日志中出来。我还尝试了“Get-ACL”以防它区分大小写,但我认为第一个版本是正确的。

我也尝试过 Get-MailboxPermission 但是文档说它甚至没有返回类型,所以它不会给我一个对象来操作。

请帮忙

4

1 回答 1

1

最终想通了:

powershell.AddCommand("Add-MailboxPermission");
powershell.AddParameter("Identity", mailboxIdentity); 
powershell.AddParameter("User", groupName); 
powershell.AddParameter("AccessRights", "FullAccess"); 
powershell.AddParameter("InheritanceType", "All"); 
于 2011-12-05T12:47:53.087 回答