Reputation: 63
So what i really need to be able to do is disable Webmail and ActiveSync 'mailbox features' on specific users in Microsoft Exchange. I've looked into powershell script for it but i'm not really familiar with PS so i'd prefer to not use it if at all possible.
I can access the server and mail specifically using ExchangeService and EWS
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
service.AutodiscoverUrl("[email protected]");
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox,new ItemView(10));
foreach (Item item in findResults.Items)
{
Console.WriteLine(item.Subject);
}
However i cant figure out how to find the mailbox features. any help would be appreciated!
Upvotes: 0
Views: 315
Reputation: 63
I Found this somewhere on the interwebs I don't actually recall where. I just modified it to serve my purpose.
RunspaceConfiguration runspaceConfig = RunspaceConfiguration.Create();
Runspace runspace = RunspaceFactory.CreateRunspace(runspaceConfig);
runspace.Open();
Pipeline pipeline = runspace.CreatePipeline();
string serverFqdn = "server";
pipeline.Commands.AddScript(string.Format("$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://{0}/PowerShell/ -Authentication Kerberos", serverFqdn));
pipeline.Commands.AddScript("Import-PSSession $Session");
pipeline.Commands.AddScript("Set-CASMailbox -Identity '" + userID + "' -OWAEnabled $true");
pipeline.Commands.AddScript("Set-CASMailbox -Identity '" + userID + "' -ActiveSyncEnabled $true");
pipeline.Commands.Add("Out-String");
Collection<PSObject> results = pipeline.Invoke();
runspace.Close();
if (pipeline.Error != null && pipeline.Error.Count > 0)
{
// failed
}
else
{
// Success
}
runspace.Dispose();
pipeline.Dispose();
Upvotes: 0
Reputation: 13
What version of Exchange do you have? Features you're talking about not really "mailbox features" but transport settings and all PowerShell cmdlets are running against CAS servers
Set-CASMailbox -Identity "John Smith" -OWAEnabled $false;
Set-CASMailbox -Identity "John Smith" -ActiveSyncEnabled $false;
/Yevgeny
Upvotes: 1