Fixed: Hide from Addressbook for distributionlists didnt work.

When hiding distributionlist the ShowInAddressBook attribute gets cleared
This commit is contained in:
robvde 2012-09-12 20:39:39 +04:00
parent 731b7f0c24
commit 1ee91cabb5

View file

@ -3353,7 +3353,7 @@ namespace WebsitePanel.Providers.HostedSolution
//fix showInAddressBook Attribute //fix showInAddressBook Attribute
if (addressLists.Length > 0) if (addressLists.Length > 0)
FixShowInAddressBook(runSpace, email, addressLists); FixShowInAddressBook(runSpace, email, addressLists, false);
} }
catch (Exception ex) catch (Exception ex)
@ -3370,7 +3370,7 @@ namespace WebsitePanel.Providers.HostedSolution
ExchangeLog.LogEnd("CreateDistributionListInternal"); ExchangeLog.LogEnd("CreateDistributionListInternal");
} }
private void FixShowInAddressBook(Runspace runSpace, string accountName, string[] addressLists) private void FixShowInAddressBook(Runspace runSpace, string accountName, string[] addressLists, bool HideFromAddressList)
{ {
Command cmd = new Command("Get-DistributionGroup"); Command cmd = new Command("Get-DistributionGroup");
cmd.Parameters.Add("Identity", accountName); cmd.Parameters.Add("Identity", accountName);
@ -3380,9 +3380,12 @@ namespace WebsitePanel.Providers.HostedSolution
DirectoryEntry dlDEEntry = GetADObject(AddADPrefix(id)); DirectoryEntry dlDEEntry = GetADObject(AddADPrefix(id));
dlDEEntry.Properties["showInAddressBook"].Clear(); dlDEEntry.Properties["showInAddressBook"].Clear();
foreach (string addressList in addressLists) if (!HideFromAddressList)
{ {
dlDEEntry.Properties["showInAddressBook"].Add(addressList); foreach (string addressList in addressLists)
{
dlDEEntry.Properties["showInAddressBook"].Add(addressList);
}
} }
dlDEEntry.CommitChanges(); dlDEEntry.CommitChanges();
} }
@ -3542,7 +3545,7 @@ namespace WebsitePanel.Providers.HostedSolution
} }
if (addressLists.Length > 0) if (addressLists.Length > 0)
FixShowInAddressBook(runSpace, accountName, addressLists); FixShowInAddressBook(runSpace, accountName, addressLists, hideFromAddressBook);
} }
finally finally
@ -3612,7 +3615,14 @@ namespace WebsitePanel.Providers.HostedSolution
} }
if (addressLists.Length > 0) if (addressLists.Length > 0)
FixShowInAddressBook(runSpace, accountName, addressLists); {
cmd = new Command("Get-DistributionGroup");
cmd.Parameters.Add("Identity", accountName);
Collection<PSObject> result = ExecuteShellCommand(runSpace, cmd);
PSObject distributionGroup = result[0];
FixShowInAddressBook(runSpace, accountName, addressLists, (bool)GetPSObjectProperty(distributionGroup, "HiddenFromAddressListsEnabled"));
}
} }
finally finally
@ -3648,7 +3658,14 @@ namespace WebsitePanel.Providers.HostedSolution
} }
if (addressLists.Length > 0) if (addressLists.Length > 0)
FixShowInAddressBook(runSpace, accountName, addressLists); {
cmd = new Command("Get-DistributionGroup");
cmd.Parameters.Add("Identity", accountName);
Collection<PSObject> result = ExecuteShellCommand(runSpace, cmd);
PSObject distributionGroup = result[0];
FixShowInAddressBook(runSpace, accountName, addressLists, (bool)GetPSObjectProperty(distributionGroup, "HiddenFromAddressListsEnabled"));
}
} }
finally finally
@ -3720,7 +3737,14 @@ namespace WebsitePanel.Providers.HostedSolution
ExecuteShellCommand(runSpace, cmd); ExecuteShellCommand(runSpace, cmd);
if (addressLists.Length > 0) if (addressLists.Length > 0)
FixShowInAddressBook(runSpace, accountName, addressLists); {
cmd = new Command("Get-DistributionGroup");
cmd.Parameters.Add("Identity", accountName);
Collection<PSObject> result = ExecuteShellCommand(runSpace, cmd);
PSObject distributionGroup = result[0];
FixShowInAddressBook(runSpace, accountName, addressLists, (bool)GetPSObjectProperty(distributionGroup, "HiddenFromAddressListsEnabled"));
}
} }
finally finally
@ -3856,7 +3880,14 @@ namespace WebsitePanel.Providers.HostedSolution
ExecuteShellCommand(runSpace, cmd); ExecuteShellCommand(runSpace, cmd);
if (addressLists.Length > 0) if (addressLists.Length > 0)
FixShowInAddressBook(runSpace, accountName, addressLists); {
cmd = new Command("Get-DistributionGroup");
cmd.Parameters.Add("Identity", accountName);
Collection<PSObject> r = ExecuteShellCommand(runSpace, cmd);
PSObject distributionGroup = r[0];
FixShowInAddressBook(runSpace, accountName, addressLists, (bool)GetPSObjectProperty(distributionGroup, "HiddenFromAddressListsEnabled"));
}
} }
finally finally
{ {
@ -3955,17 +3986,24 @@ namespace WebsitePanel.Providers.HostedSolution
if (sendOnBehalfAccounts == null) if (sendOnBehalfAccounts == null)
throw new ArgumentNullException("sendOnBehalfAccounts"); throw new ArgumentNullException("sendOnBehalfAccounts");
Runspace runspace = null; Runspace runSpace = null;
try try
{ {
runspace = OpenRunspace(); runSpace = OpenRunspace();
string cn = GetDistributionListCommonName(runspace, accountName); string cn = GetDistributionListCommonName(runSpace, accountName);
ExchangeDistributionList distributionList = GetDistributionListPermissionsInternal(organizationId, accountName, runspace); ExchangeDistributionList distributionList = GetDistributionListPermissionsInternal(organizationId, accountName, runSpace);
SetSendAsPermissions(runspace, distributionList.SendAsAccounts, cn, sendAsAccounts); SetSendAsPermissions(runSpace, distributionList.SendAsAccounts, cn, sendAsAccounts);
SetDistributionListSendOnBehalfAccounts(runspace, accountName, sendOnBehalfAccounts); SetDistributionListSendOnBehalfAccounts(runSpace, accountName, sendOnBehalfAccounts);
if (addressLists.Length > 0) if (addressLists.Length > 0)
FixShowInAddressBook(runspace, accountName, addressLists); {
Command cmd = new Command("Get-DistributionGroup");
cmd.Parameters.Add("Identity", accountName);
Collection<PSObject> result = ExecuteShellCommand(runSpace, cmd);
PSObject distributionGroup = result[0];
FixShowInAddressBook(runSpace, accountName, addressLists, (bool)GetPSObjectProperty(distributionGroup, "HiddenFromAddressListsEnabled"));
}
} }
catch (Exception ex) catch (Exception ex)
@ -3975,7 +4013,7 @@ namespace WebsitePanel.Providers.HostedSolution
} }
finally finally
{ {
CloseRunspace(runspace); CloseRunspace(runSpace);
} }
ExchangeLog.LogEnd("SetDistributionListPermissionsInternal"); ExchangeLog.LogEnd("SetDistributionListPermissionsInternal");