列出使用 EWS C#/Powershell 分配给日历的所有用户
本文关键字:日历 用户 分配 Powershell EWS | 更新日期: 2023-09-27 18:31:43
我有一个列出27个日历的交换服务器。我需要与此服务器通信,以确定哪些用户被分配到哪个日历。我不擅长PowerShell,我知道这可以用来检索我可能需要的信息。我倾向于使用Microsoft.Exchange.Webservice.Data,但我不相信有办法使用它来检索这些信息。下面的代码是我用来连接 EWS 的代码,到目前为止不是问题,我只是在寻找查询用户有权访问日历的最佳方式。
static void Main(string[] args)
{
ExchangeService service = new ExchangeService (ExchangeVersion.Exchange2010_SP2);
//***********New**********************
ExchangeService mailbox = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
string mailboxEmail = "JNichols@example.org";
WebCredentials wbcred = new WebCredentials("exampleUsername", "examplePassword");
mailbox.Credentials = wbcred;
// mailbox.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, mailboxEmail);
mailbox.AutodiscoverUrl(mailboxEmail, RedirectionUrlValidationCallback);
mailbox.HttpHeaders.Add("X-AnchorMailBox", mailboxEmail);
FolderId mb1Inbox = new FolderId(WellKnownFolderName.Inbox, mailboxEmail);
//SetStreamingNotification(mailbox, mb1Inbox);
mailbox.Url = new Uri("https://webmail.example.org/EWS/Exchange.asmx");
Dictionary<string, Folder> x = GetSharedCalendarFolders(mailbox, mailboxEmail);
}
internal static bool RedirectionUrlValidationCallback(string redirectionUrl)
{
//The default for the validation callback is to reject the URL
bool result=false;
Uri redirectionUri=new Uri(redirectionUrl);
if(redirectionUri.Scheme=="https")
{
result=true;
}
return result;
}
在 Exchange 命令行管理程序中,您可以执行以下操作:
$CalendarPermissions = Get-MailboxFolderPermission -Identity jnichols@example.org:'Calendar
这将返回在邮箱日历上设置的所有权限 - 每个条目都有一个User
属性 - 已向其授予权限/访问权限的用户或组:
$CalendarPermissions | Select User,AccessRights