Get Users list who has Access permissions to Particular User in C# code

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.

using below command i am getting users list who has Access permissions , but not for particular user.

Get-Mailbox -resultsize unlimited | Get-MailboxPermission | Where {(!$_.isinherited) -and ($_.user.SecurityIdentifier -ne "S-1-5-10") -and ($_.accessrights -contains "fullaccess") } | Select Identity

Please see the C# code I am using to get user list.  

var runspace = RunspaceFactory.CreateRunspace();
runspace.Open();

object psSessionConnection;

// Create a powershell session for remote exchange server
using (var powershell = PowerShell.Create())
{
var command = new PSCommand();
command.AddCommand("New-PSSession");
command.AddParameter("ConfigurationName", "Microsoft.Exchange");
command.AddParameter("ConnectionUri", new Uri("http://ExchangeServer.admin.com/powershell/Microsoft.Exchange"));
command.AddParameter("Authentication", "Kerberos");
powershell.Commands = command;
powershell.Runspace = runspace;

// TODO: Handle errors
var result = powershell.Invoke();
psSessionConnection = result[0];
}

// Set ExecutionPolicy on the process to unrestricted
using (var powershell = PowerShell.Create())
{
var command = new PSCommand();
command.AddCommand("Set-ExecutionPolicy");
command.AddParameter("Scope", "Process");
command.AddParameter("ExecutionPolicy", "Unrestricted");
powershell.Commands = command;
powershell.Runspace = runspace;

powershell.Invoke();
}

// Import remote exchange session into runspace
using (var powershell = PowerShell.Create())
{
var command = new PSCommand();
command.AddCommand("Import-PSSession");
command.AddParameter("Session", psSessionConnection);
powershell.Commands = command;
powershell.Runspace = runspace;

powershell.Invoke();
}

String file = "D:/Scripts/listcmd.ps1";
Pipeline pipeline = runspace.CreatePipeline();
pipeline.Commands.AddScript(file);
Collection<PSObject> results = pipeline.Invoke();


runspace.Close();

Now I have 2 Questions.

1) Using above code i am getting users list who has permissions , but I am doing this now in my Test Server . 

I need to do  in client server . In client server also some users has Access permissions . 

How can i check using above code , weather client server getting users list or not ?. because client doesn't have visual studio installed for checking the code ? I need to test this from my server . How can i do it ?

2) what is the command for getting users who has Access permissions to particular User ,

  Above command  getting all users list in Server.

July 15th, 2014 9:32am

Hello,

Suggest you to post this in Development forum...

http://social.msdn.microsoft.com/Forums/en-US/exchangesvrdevelopment/threads/
Free Windows Admin Tool Kit Click here and download it now
July 15th, 2014 4:46pm

Hi,

About your problems, Development forum can be a better place which is staffed by more experts, you might get a better answer there.

Best regards,

July 16th, 2014 1:32am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics