简体   繁体   中英

List all users assigned to a calendar using EWS C#/Powershell

I have an exchange server that list 27 calendars. I need to communicate with this server to figure out what users are assigned to what calendar. I'm not good with PowerShell and i know this can be used to retreive the information i may need. I'd preffer to use Microsoft.Exchange.Webservice.Data but i dont beleive there is a way to retreive this information using this. The code below is what im using to connect with EWS and thus far is not a problem Im just looking for the best way to query what users have access to a calendar.

     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;
}

In the Exchange Management Shell, you can do:

$CalendarPermissions = Get-MailboxFolderPermission -Identity jnichols@example.org:\Calendar

Which will return all permissions set on the mailbox calendar - each entry has a User property - the user or group that the permission/access right has been granted to:

$CalendarPermissions | Select User,AccessRights

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM