locked
Get list of users in C# code, who has Mailbox Access permissions to Particular User RRS feed

  • Question

  • Hi,

    I am using Exchange Server 2013. In my server, Full Mailbox access permissions of some users has granted to one particular user [ ex: Exadmin@admin.com].

    Now i need the list who has access permissions to Exadmin@admin.com in C# code.

    In the below code i am getting all users list of my server using Administrator account.

     SecureString password = new SecureString();
                  string str_password = "xxxxx";
                  string username = "Administrator@admin.com";
                  foreach (char x in str_password) { password.AppendChar(x); }
                  PSCredential credential = new PSCredential(username, password);
    
                  WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri("http://ExchangeServer.admin.com/powershell/Microsoft.Exchange"), "http://schemas.microsoft.com/powershell/Microsoft.Exchange", credential);
    
                  Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo);
    
                  PowerShell powershell = PowerShell.Create();
    
                  PSCommand command = new PSCommand();
                  command.AddCommand("Get-Mailbox");
                  command.AddParameter("ResultSize", int.MaxValue);
                  powershell.Commands = command;
                  runspace.Open();
                  powershell.Runspace = runspace;
                  Collection<PSObject> usersList = powershell.Invoke();
                  runspace.Close();

     Now i need to access list of users who has mailbox permissions access toExadmin@admin.com , instead of all users.

    Please share your ideas

    Tuesday, July 8, 2014 6:50 AM

Answers

All replies

  • below commands lists all users that have full access permissions to mailboxes.

    Get-Mailbox -Server "<servername>"  -resultsize "Unlimited" | Get-MailboxPermission | where { ($_.AccessRights -eq "FullAccess") -and ($_.IsInherited -eq $false) -and -not ($_.User -like "NT AUTHORITY\SELF") } | ft @{Name="Identity";expression={($_.Identity -split "/")[-1]}}, User -AutoSize

    http://social.technet.microsoft.com/Forums/office/en-US/a9cd79ff-eda6-4527-af25-e50149e2242c/list-all-users-accounts-that-have-full-access-permissions-to-mailboxes?forum=exchange2010

    This command works fine in shell.

    but how can i call this command from C# code ?

     I am getting error by replacing above command in C# code.

     PSCommand command = new PSCommand();
    command.AddCommand(Get-Mailbox -Server ExchangeServer  -resultsize "Unlimited" | Get-MailboxPermission | where { ($_.AccessRights -eq "FullAccess") -and ($_.IsInherited -eq $false) -and -not ($_.User -like "NT AUTHORITY\SELF") } | ft @{Name="Identity";expression={($_.Identity -split "/")[-1]}}, User -AutoSize);


    • Edited by Dora407 Tuesday, July 8, 2014 9:25 AM
    Tuesday, July 8, 2014 9:21 AM
  • Wednesday, July 9, 2014 1:11 PM
  • My code looks like this

    powershell.AddCommand("Get-MailboxPermission");
    powershell.AddParameter("-Identity", name);

    //I want to put Where-Object {($_.AccessRights –like ‘FullAccess’)  condition here.

    //What i have tried till now

    //powershell.AddCommand("Where");

    powershell.AddParameter("-AccessRights", "FullAccess");

    powershell.Runspace = myRunSpace;
    objMailboxPermissionResults = powershell.Invoke();

    In powershell it working fine please help me here                         
    Thursday, April 19, 2018 7:29 AM
  • If you get an error then you need to include the error you received but firstly 

    powershell.AddParameter("-AccessRights", "FullAccess");

    ins't correct you don't need the - eg it should be

    powershell.AddParameter("AccessRights", "FullAccess");

    Cheers
    Glen

    Friday, April 20, 2018 12:43 AM