Active Directory: Retrieve all group members using DirectoryServices

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite












I have written a function that will retrieve all active directory group members via DirectoryServices. I am using DirectoryServices because it is approximately 1 to 2 orders of magnitude faster than using AccountManagement. I have validated that the function's results are correct.



I am now doing code cleanup and want to make sure the code is clean and that the use of the try/catch/finally blocks are correct. The idea is to isolate the retrieval of data from AD from the process of adding data into the list that will be returned by the function. If this is not an appropriate way to do things or if you have any recommendations are appreciated.



private List<string> GetGroupMemberList(string strPropertyValue, string strActiveDirectoryHost, int intActiveDirectoryPageSize, string strObjectRid)

// Variable declaration(s).
DirectoryEntry directoryEntryGroup = null;
SearchResultCollection searchResultCollection = null;
DirectorySearcher directorySearcher = null;
List<string> listGroupMemberDn = null;
string strPath = null;
const int intIncrement = 1500; // https://msdn.microsoft.com/en-us/library/windows/desktop/ms676302(v=vs.85).aspx
bool bolCancel = false;

// https://gallery.technet.microsoft.com/scriptcenter/fa4ccf4f-712e-459c-88b4-aacdb03a08d0
// The member attribute of the groups is a collection of the Distinguished Names of all direct memberships, but does not reveal the "Primary Group" membership.
// So, get all of the members within the group first and then search for all users that have a primaryGroupID that is set to the current group that we are
// retrieving members from. For the latter step, we will need to use the DirectoryEntry to search for all users that have an RID that includes the PrimaryGroupId.

// Step 1.) Get all direct group members.
// Note: Per the weblink above in the variable declaration(s), group members are extracted in batches of 1500 members.
// So, we will need to loop through all members in increments of 1500 until there are no more left.

try

// Create a new list.
listGroupMemberDn = new List<string>();

// Set the string path of the current group so that it can be bound to DirectoryEntry.
strPath = strActiveDirectoryHost + "/<GUID=" + strPropertyValue + ">";

// Get the current group infromation, which will include the first batch of group members.
directoryEntryGroup = new DirectoryEntry(strPath, null, null, AuthenticationTypes.Secure);

catch (Exception ex)

// Something went wrong. Throw an error.
bolCancel = false;
ComponentMetaData.FireError(0, ComponentMetaData.Name, ex.Message, string.Empty, 0, out bolCancel);
throw;


try

while (true)

// Isolate all members that are listed in the current batch of group members.
var varGroupMemberDns = directoryEntryGroup.Properties["member"];

// Loop through the members that have been isolated and add each one into the list.
foreach (string strMemberDn in varGroupMemberDns)

listGroupMemberDn.Add(strMemberDn.ToString().Replace(""", ""));


// Check to see if the current batch is the last batch of group members by checking the count of members that are contained in the current batch.
// If the number of members is less than the 1500 member batch limit, then this is the last batch of users. So, break the loop.
if (varGroupMemberDns.Count < intIncrement)

break;


// The current batch is not the last batch of group members. So, get the next batch of group members.
// Note: We must use string.Format() to avoid string interpolation: $"member;range=listGroupMemberDn.Count-*"
// Using string interpolation prevents the debugger from starting.
// directoryEntryGroup.RefreshCache(new $"member;range=listGroupMemberDn.Count-*" );
directoryEntryGroup.RefreshCache(new string.Format("member;range=0-*", listGroupMemberDn.Count) );



catch (Exception ex)

// Something went wrong. Throw an error.
bolCancel = false;
ComponentMetaData.FireError(0, ComponentMetaData.Name, ex.Message, string.Empty, 0, out bolCancel);
throw;


// Step 2.) Get all group members by searching DirectoryEntry for users that have their primaryGroupId set to the current group.
try

// Set directorySearcher and initialize certain properties.
directorySearcher = new DirectorySearcher(strActiveDirectoryHost)

// Set the Filter criteria that is used to constrain the search within AD.
Filter = string.Format("(primaryGroupID=0)", strObjectRid),

// Set the SearchScope for how the AD tree is searched (Default = Subtree).
SearchScope = SearchScope.Subtree,

// The PageSize value should be set equal to the PageSize that is set by the AD administrator (Server default = 1000, PageSize default = 0).
PageSize = intActiveDirectoryPageSize,

// Set the value indicating which node in the Active Directory Domain Services hierarchy to start the search.
SearchRoot = new DirectoryEntry(strActiveDirectoryHost),

PropertiesToLoad = "distinguishedName"
;

catch (Exception ex)

// Something went wrong. Throw an error.
bolCancel = false;
ComponentMetaData.FireError(0, ComponentMetaData.Name, ex.Message, string.Empty, 0, out bolCancel);
throw;


try

// Populate the searchResultCollection with all AD records that match the Filter criteria.
searchResultCollection = directorySearcher.FindAll();

// For each record object in the searchResultCollection, retrieve the distinguishedName and add it to the list.
foreach (SearchResult searchResult in searchResultCollection)

listGroupMemberDn.Add(searchResult.Properties["distinguishedName"][0].ToString().Replace(""", ""));


// Return the list.
return listGroupMemberDn;

catch (Exception ex)

// Something went wrong. Throw an error.
bolCancel = false;
ComponentMetaData.FireError(0, ComponentMetaData.Name, ex.Message, string.Empty, 0, out bolCancel);
throw;

finally

// Cleanup objects.
listGroupMemberDn = null;
strPath = null;
strObjectRid = null;
directoryEntryGroup.Close();
if (directoryEntryGroup != null) directoryEntryGroup.Dispose();
if (directorySearcher != null) directorySearcher.Dispose();
if (searchResultCollection != null) searchResultCollection.Dispose();








share|improve this question





















  • Hiding exeptions like that catch (Exception) isn't usually a wise decision. Is there any reason you're doing that? If the first try didn't work and the directoryEntryGroup remains null the next one is going to blow too... this is a very questionable design.
    – t3chb0t
    Apr 10 at 18:10











  • I'm also not sure whether this is your real code... the while loop is missing the closing }. Could you fix it please?
    – t3chb0t
    Apr 10 at 18:13










  • @t3chb0t Thanks for catching that. I had to change the string interpolation to a string.format() due to a bug within the debugger - it would not launch on breakpoints in an SSIS script component. I have corrected the typo.
    – J Weezy
    Apr 10 at 19:07










  • @t3chb0t Regarding the multiple try/catch blocks, typically I used one try/catch block for each function. But, since I am creating an SSIS script, I noticed in an online posting (I don't have it handy anymore) that they were using multiple try/catch blocks. That is why I am posting here to get feedback on that.
    – J Weezy
    Apr 10 at 19:09

















up vote
2
down vote

favorite












I have written a function that will retrieve all active directory group members via DirectoryServices. I am using DirectoryServices because it is approximately 1 to 2 orders of magnitude faster than using AccountManagement. I have validated that the function's results are correct.



I am now doing code cleanup and want to make sure the code is clean and that the use of the try/catch/finally blocks are correct. The idea is to isolate the retrieval of data from AD from the process of adding data into the list that will be returned by the function. If this is not an appropriate way to do things or if you have any recommendations are appreciated.



private List<string> GetGroupMemberList(string strPropertyValue, string strActiveDirectoryHost, int intActiveDirectoryPageSize, string strObjectRid)

// Variable declaration(s).
DirectoryEntry directoryEntryGroup = null;
SearchResultCollection searchResultCollection = null;
DirectorySearcher directorySearcher = null;
List<string> listGroupMemberDn = null;
string strPath = null;
const int intIncrement = 1500; // https://msdn.microsoft.com/en-us/library/windows/desktop/ms676302(v=vs.85).aspx
bool bolCancel = false;

// https://gallery.technet.microsoft.com/scriptcenter/fa4ccf4f-712e-459c-88b4-aacdb03a08d0
// The member attribute of the groups is a collection of the Distinguished Names of all direct memberships, but does not reveal the "Primary Group" membership.
// So, get all of the members within the group first and then search for all users that have a primaryGroupID that is set to the current group that we are
// retrieving members from. For the latter step, we will need to use the DirectoryEntry to search for all users that have an RID that includes the PrimaryGroupId.

// Step 1.) Get all direct group members.
// Note: Per the weblink above in the variable declaration(s), group members are extracted in batches of 1500 members.
// So, we will need to loop through all members in increments of 1500 until there are no more left.

try

// Create a new list.
listGroupMemberDn = new List<string>();

// Set the string path of the current group so that it can be bound to DirectoryEntry.
strPath = strActiveDirectoryHost + "/<GUID=" + strPropertyValue + ">";

// Get the current group infromation, which will include the first batch of group members.
directoryEntryGroup = new DirectoryEntry(strPath, null, null, AuthenticationTypes.Secure);

catch (Exception ex)

// Something went wrong. Throw an error.
bolCancel = false;
ComponentMetaData.FireError(0, ComponentMetaData.Name, ex.Message, string.Empty, 0, out bolCancel);
throw;


try

while (true)

// Isolate all members that are listed in the current batch of group members.
var varGroupMemberDns = directoryEntryGroup.Properties["member"];

// Loop through the members that have been isolated and add each one into the list.
foreach (string strMemberDn in varGroupMemberDns)

listGroupMemberDn.Add(strMemberDn.ToString().Replace(""", ""));


// Check to see if the current batch is the last batch of group members by checking the count of members that are contained in the current batch.
// If the number of members is less than the 1500 member batch limit, then this is the last batch of users. So, break the loop.
if (varGroupMemberDns.Count < intIncrement)

break;


// The current batch is not the last batch of group members. So, get the next batch of group members.
// Note: We must use string.Format() to avoid string interpolation: $"member;range=listGroupMemberDn.Count-*"
// Using string interpolation prevents the debugger from starting.
// directoryEntryGroup.RefreshCache(new $"member;range=listGroupMemberDn.Count-*" );
directoryEntryGroup.RefreshCache(new string.Format("member;range=0-*", listGroupMemberDn.Count) );



catch (Exception ex)

// Something went wrong. Throw an error.
bolCancel = false;
ComponentMetaData.FireError(0, ComponentMetaData.Name, ex.Message, string.Empty, 0, out bolCancel);
throw;


// Step 2.) Get all group members by searching DirectoryEntry for users that have their primaryGroupId set to the current group.
try

// Set directorySearcher and initialize certain properties.
directorySearcher = new DirectorySearcher(strActiveDirectoryHost)

// Set the Filter criteria that is used to constrain the search within AD.
Filter = string.Format("(primaryGroupID=0)", strObjectRid),

// Set the SearchScope for how the AD tree is searched (Default = Subtree).
SearchScope = SearchScope.Subtree,

// The PageSize value should be set equal to the PageSize that is set by the AD administrator (Server default = 1000, PageSize default = 0).
PageSize = intActiveDirectoryPageSize,

// Set the value indicating which node in the Active Directory Domain Services hierarchy to start the search.
SearchRoot = new DirectoryEntry(strActiveDirectoryHost),

PropertiesToLoad = "distinguishedName"
;

catch (Exception ex)

// Something went wrong. Throw an error.
bolCancel = false;
ComponentMetaData.FireError(0, ComponentMetaData.Name, ex.Message, string.Empty, 0, out bolCancel);
throw;


try

// Populate the searchResultCollection with all AD records that match the Filter criteria.
searchResultCollection = directorySearcher.FindAll();

// For each record object in the searchResultCollection, retrieve the distinguishedName and add it to the list.
foreach (SearchResult searchResult in searchResultCollection)

listGroupMemberDn.Add(searchResult.Properties["distinguishedName"][0].ToString().Replace(""", ""));


// Return the list.
return listGroupMemberDn;

catch (Exception ex)

// Something went wrong. Throw an error.
bolCancel = false;
ComponentMetaData.FireError(0, ComponentMetaData.Name, ex.Message, string.Empty, 0, out bolCancel);
throw;

finally

// Cleanup objects.
listGroupMemberDn = null;
strPath = null;
strObjectRid = null;
directoryEntryGroup.Close();
if (directoryEntryGroup != null) directoryEntryGroup.Dispose();
if (directorySearcher != null) directorySearcher.Dispose();
if (searchResultCollection != null) searchResultCollection.Dispose();








share|improve this question





















  • Hiding exeptions like that catch (Exception) isn't usually a wise decision. Is there any reason you're doing that? If the first try didn't work and the directoryEntryGroup remains null the next one is going to blow too... this is a very questionable design.
    – t3chb0t
    Apr 10 at 18:10











  • I'm also not sure whether this is your real code... the while loop is missing the closing }. Could you fix it please?
    – t3chb0t
    Apr 10 at 18:13










  • @t3chb0t Thanks for catching that. I had to change the string interpolation to a string.format() due to a bug within the debugger - it would not launch on breakpoints in an SSIS script component. I have corrected the typo.
    – J Weezy
    Apr 10 at 19:07










  • @t3chb0t Regarding the multiple try/catch blocks, typically I used one try/catch block for each function. But, since I am creating an SSIS script, I noticed in an online posting (I don't have it handy anymore) that they were using multiple try/catch blocks. That is why I am posting here to get feedback on that.
    – J Weezy
    Apr 10 at 19:09













up vote
2
down vote

favorite









up vote
2
down vote

favorite











I have written a function that will retrieve all active directory group members via DirectoryServices. I am using DirectoryServices because it is approximately 1 to 2 orders of magnitude faster than using AccountManagement. I have validated that the function's results are correct.



I am now doing code cleanup and want to make sure the code is clean and that the use of the try/catch/finally blocks are correct. The idea is to isolate the retrieval of data from AD from the process of adding data into the list that will be returned by the function. If this is not an appropriate way to do things or if you have any recommendations are appreciated.



private List<string> GetGroupMemberList(string strPropertyValue, string strActiveDirectoryHost, int intActiveDirectoryPageSize, string strObjectRid)

// Variable declaration(s).
DirectoryEntry directoryEntryGroup = null;
SearchResultCollection searchResultCollection = null;
DirectorySearcher directorySearcher = null;
List<string> listGroupMemberDn = null;
string strPath = null;
const int intIncrement = 1500; // https://msdn.microsoft.com/en-us/library/windows/desktop/ms676302(v=vs.85).aspx
bool bolCancel = false;

// https://gallery.technet.microsoft.com/scriptcenter/fa4ccf4f-712e-459c-88b4-aacdb03a08d0
// The member attribute of the groups is a collection of the Distinguished Names of all direct memberships, but does not reveal the "Primary Group" membership.
// So, get all of the members within the group first and then search for all users that have a primaryGroupID that is set to the current group that we are
// retrieving members from. For the latter step, we will need to use the DirectoryEntry to search for all users that have an RID that includes the PrimaryGroupId.

// Step 1.) Get all direct group members.
// Note: Per the weblink above in the variable declaration(s), group members are extracted in batches of 1500 members.
// So, we will need to loop through all members in increments of 1500 until there are no more left.

try

// Create a new list.
listGroupMemberDn = new List<string>();

// Set the string path of the current group so that it can be bound to DirectoryEntry.
strPath = strActiveDirectoryHost + "/<GUID=" + strPropertyValue + ">";

// Get the current group infromation, which will include the first batch of group members.
directoryEntryGroup = new DirectoryEntry(strPath, null, null, AuthenticationTypes.Secure);

catch (Exception ex)

// Something went wrong. Throw an error.
bolCancel = false;
ComponentMetaData.FireError(0, ComponentMetaData.Name, ex.Message, string.Empty, 0, out bolCancel);
throw;


try

while (true)

// Isolate all members that are listed in the current batch of group members.
var varGroupMemberDns = directoryEntryGroup.Properties["member"];

// Loop through the members that have been isolated and add each one into the list.
foreach (string strMemberDn in varGroupMemberDns)

listGroupMemberDn.Add(strMemberDn.ToString().Replace(""", ""));


// Check to see if the current batch is the last batch of group members by checking the count of members that are contained in the current batch.
// If the number of members is less than the 1500 member batch limit, then this is the last batch of users. So, break the loop.
if (varGroupMemberDns.Count < intIncrement)

break;


// The current batch is not the last batch of group members. So, get the next batch of group members.
// Note: We must use string.Format() to avoid string interpolation: $"member;range=listGroupMemberDn.Count-*"
// Using string interpolation prevents the debugger from starting.
// directoryEntryGroup.RefreshCache(new $"member;range=listGroupMemberDn.Count-*" );
directoryEntryGroup.RefreshCache(new string.Format("member;range=0-*", listGroupMemberDn.Count) );



catch (Exception ex)

// Something went wrong. Throw an error.
bolCancel = false;
ComponentMetaData.FireError(0, ComponentMetaData.Name, ex.Message, string.Empty, 0, out bolCancel);
throw;


// Step 2.) Get all group members by searching DirectoryEntry for users that have their primaryGroupId set to the current group.
try

// Set directorySearcher and initialize certain properties.
directorySearcher = new DirectorySearcher(strActiveDirectoryHost)

// Set the Filter criteria that is used to constrain the search within AD.
Filter = string.Format("(primaryGroupID=0)", strObjectRid),

// Set the SearchScope for how the AD tree is searched (Default = Subtree).
SearchScope = SearchScope.Subtree,

// The PageSize value should be set equal to the PageSize that is set by the AD administrator (Server default = 1000, PageSize default = 0).
PageSize = intActiveDirectoryPageSize,

// Set the value indicating which node in the Active Directory Domain Services hierarchy to start the search.
SearchRoot = new DirectoryEntry(strActiveDirectoryHost),

PropertiesToLoad = "distinguishedName"
;

catch (Exception ex)

// Something went wrong. Throw an error.
bolCancel = false;
ComponentMetaData.FireError(0, ComponentMetaData.Name, ex.Message, string.Empty, 0, out bolCancel);
throw;


try

// Populate the searchResultCollection with all AD records that match the Filter criteria.
searchResultCollection = directorySearcher.FindAll();

// For each record object in the searchResultCollection, retrieve the distinguishedName and add it to the list.
foreach (SearchResult searchResult in searchResultCollection)

listGroupMemberDn.Add(searchResult.Properties["distinguishedName"][0].ToString().Replace(""", ""));


// Return the list.
return listGroupMemberDn;

catch (Exception ex)

// Something went wrong. Throw an error.
bolCancel = false;
ComponentMetaData.FireError(0, ComponentMetaData.Name, ex.Message, string.Empty, 0, out bolCancel);
throw;

finally

// Cleanup objects.
listGroupMemberDn = null;
strPath = null;
strObjectRid = null;
directoryEntryGroup.Close();
if (directoryEntryGroup != null) directoryEntryGroup.Dispose();
if (directorySearcher != null) directorySearcher.Dispose();
if (searchResultCollection != null) searchResultCollection.Dispose();








share|improve this question













I have written a function that will retrieve all active directory group members via DirectoryServices. I am using DirectoryServices because it is approximately 1 to 2 orders of magnitude faster than using AccountManagement. I have validated that the function's results are correct.



I am now doing code cleanup and want to make sure the code is clean and that the use of the try/catch/finally blocks are correct. The idea is to isolate the retrieval of data from AD from the process of adding data into the list that will be returned by the function. If this is not an appropriate way to do things or if you have any recommendations are appreciated.



private List<string> GetGroupMemberList(string strPropertyValue, string strActiveDirectoryHost, int intActiveDirectoryPageSize, string strObjectRid)

// Variable declaration(s).
DirectoryEntry directoryEntryGroup = null;
SearchResultCollection searchResultCollection = null;
DirectorySearcher directorySearcher = null;
List<string> listGroupMemberDn = null;
string strPath = null;
const int intIncrement = 1500; // https://msdn.microsoft.com/en-us/library/windows/desktop/ms676302(v=vs.85).aspx
bool bolCancel = false;

// https://gallery.technet.microsoft.com/scriptcenter/fa4ccf4f-712e-459c-88b4-aacdb03a08d0
// The member attribute of the groups is a collection of the Distinguished Names of all direct memberships, but does not reveal the "Primary Group" membership.
// So, get all of the members within the group first and then search for all users that have a primaryGroupID that is set to the current group that we are
// retrieving members from. For the latter step, we will need to use the DirectoryEntry to search for all users that have an RID that includes the PrimaryGroupId.

// Step 1.) Get all direct group members.
// Note: Per the weblink above in the variable declaration(s), group members are extracted in batches of 1500 members.
// So, we will need to loop through all members in increments of 1500 until there are no more left.

try

// Create a new list.
listGroupMemberDn = new List<string>();

// Set the string path of the current group so that it can be bound to DirectoryEntry.
strPath = strActiveDirectoryHost + "/<GUID=" + strPropertyValue + ">";

// Get the current group infromation, which will include the first batch of group members.
directoryEntryGroup = new DirectoryEntry(strPath, null, null, AuthenticationTypes.Secure);

catch (Exception ex)

// Something went wrong. Throw an error.
bolCancel = false;
ComponentMetaData.FireError(0, ComponentMetaData.Name, ex.Message, string.Empty, 0, out bolCancel);
throw;


try

while (true)

// Isolate all members that are listed in the current batch of group members.
var varGroupMemberDns = directoryEntryGroup.Properties["member"];

// Loop through the members that have been isolated and add each one into the list.
foreach (string strMemberDn in varGroupMemberDns)

listGroupMemberDn.Add(strMemberDn.ToString().Replace(""", ""));


// Check to see if the current batch is the last batch of group members by checking the count of members that are contained in the current batch.
// If the number of members is less than the 1500 member batch limit, then this is the last batch of users. So, break the loop.
if (varGroupMemberDns.Count < intIncrement)

break;


// The current batch is not the last batch of group members. So, get the next batch of group members.
// Note: We must use string.Format() to avoid string interpolation: $"member;range=listGroupMemberDn.Count-*"
// Using string interpolation prevents the debugger from starting.
// directoryEntryGroup.RefreshCache(new $"member;range=listGroupMemberDn.Count-*" );
directoryEntryGroup.RefreshCache(new string.Format("member;range=0-*", listGroupMemberDn.Count) );



catch (Exception ex)

// Something went wrong. Throw an error.
bolCancel = false;
ComponentMetaData.FireError(0, ComponentMetaData.Name, ex.Message, string.Empty, 0, out bolCancel);
throw;


// Step 2.) Get all group members by searching DirectoryEntry for users that have their primaryGroupId set to the current group.
try

// Set directorySearcher and initialize certain properties.
directorySearcher = new DirectorySearcher(strActiveDirectoryHost)

// Set the Filter criteria that is used to constrain the search within AD.
Filter = string.Format("(primaryGroupID=0)", strObjectRid),

// Set the SearchScope for how the AD tree is searched (Default = Subtree).
SearchScope = SearchScope.Subtree,

// The PageSize value should be set equal to the PageSize that is set by the AD administrator (Server default = 1000, PageSize default = 0).
PageSize = intActiveDirectoryPageSize,

// Set the value indicating which node in the Active Directory Domain Services hierarchy to start the search.
SearchRoot = new DirectoryEntry(strActiveDirectoryHost),

PropertiesToLoad = "distinguishedName"
;

catch (Exception ex)

// Something went wrong. Throw an error.
bolCancel = false;
ComponentMetaData.FireError(0, ComponentMetaData.Name, ex.Message, string.Empty, 0, out bolCancel);
throw;


try

// Populate the searchResultCollection with all AD records that match the Filter criteria.
searchResultCollection = directorySearcher.FindAll();

// For each record object in the searchResultCollection, retrieve the distinguishedName and add it to the list.
foreach (SearchResult searchResult in searchResultCollection)

listGroupMemberDn.Add(searchResult.Properties["distinguishedName"][0].ToString().Replace(""", ""));


// Return the list.
return listGroupMemberDn;

catch (Exception ex)

// Something went wrong. Throw an error.
bolCancel = false;
ComponentMetaData.FireError(0, ComponentMetaData.Name, ex.Message, string.Empty, 0, out bolCancel);
throw;

finally

// Cleanup objects.
listGroupMemberDn = null;
strPath = null;
strObjectRid = null;
directoryEntryGroup.Close();
if (directoryEntryGroup != null) directoryEntryGroup.Dispose();
if (directorySearcher != null) directorySearcher.Dispose();
if (searchResultCollection != null) searchResultCollection.Dispose();










share|improve this question












share|improve this question




share|improve this question








edited May 29 at 20:42









Jamal♦

30.1k11114225




30.1k11114225









asked Apr 6 at 17:38









J Weezy

1112




1112











  • Hiding exeptions like that catch (Exception) isn't usually a wise decision. Is there any reason you're doing that? If the first try didn't work and the directoryEntryGroup remains null the next one is going to blow too... this is a very questionable design.
    – t3chb0t
    Apr 10 at 18:10











  • I'm also not sure whether this is your real code... the while loop is missing the closing }. Could you fix it please?
    – t3chb0t
    Apr 10 at 18:13










  • @t3chb0t Thanks for catching that. I had to change the string interpolation to a string.format() due to a bug within the debugger - it would not launch on breakpoints in an SSIS script component. I have corrected the typo.
    – J Weezy
    Apr 10 at 19:07










  • @t3chb0t Regarding the multiple try/catch blocks, typically I used one try/catch block for each function. But, since I am creating an SSIS script, I noticed in an online posting (I don't have it handy anymore) that they were using multiple try/catch blocks. That is why I am posting here to get feedback on that.
    – J Weezy
    Apr 10 at 19:09

















  • Hiding exeptions like that catch (Exception) isn't usually a wise decision. Is there any reason you're doing that? If the first try didn't work and the directoryEntryGroup remains null the next one is going to blow too... this is a very questionable design.
    – t3chb0t
    Apr 10 at 18:10











  • I'm also not sure whether this is your real code... the while loop is missing the closing }. Could you fix it please?
    – t3chb0t
    Apr 10 at 18:13










  • @t3chb0t Thanks for catching that. I had to change the string interpolation to a string.format() due to a bug within the debugger - it would not launch on breakpoints in an SSIS script component. I have corrected the typo.
    – J Weezy
    Apr 10 at 19:07










  • @t3chb0t Regarding the multiple try/catch blocks, typically I used one try/catch block for each function. But, since I am creating an SSIS script, I noticed in an online posting (I don't have it handy anymore) that they were using multiple try/catch blocks. That is why I am posting here to get feedback on that.
    – J Weezy
    Apr 10 at 19:09
















Hiding exeptions like that catch (Exception) isn't usually a wise decision. Is there any reason you're doing that? If the first try didn't work and the directoryEntryGroup remains null the next one is going to blow too... this is a very questionable design.
– t3chb0t
Apr 10 at 18:10





Hiding exeptions like that catch (Exception) isn't usually a wise decision. Is there any reason you're doing that? If the first try didn't work and the directoryEntryGroup remains null the next one is going to blow too... this is a very questionable design.
– t3chb0t
Apr 10 at 18:10













I'm also not sure whether this is your real code... the while loop is missing the closing }. Could you fix it please?
– t3chb0t
Apr 10 at 18:13




I'm also not sure whether this is your real code... the while loop is missing the closing }. Could you fix it please?
– t3chb0t
Apr 10 at 18:13












@t3chb0t Thanks for catching that. I had to change the string interpolation to a string.format() due to a bug within the debugger - it would not launch on breakpoints in an SSIS script component. I have corrected the typo.
– J Weezy
Apr 10 at 19:07




@t3chb0t Thanks for catching that. I had to change the string interpolation to a string.format() due to a bug within the debugger - it would not launch on breakpoints in an SSIS script component. I have corrected the typo.
– J Weezy
Apr 10 at 19:07












@t3chb0t Regarding the multiple try/catch blocks, typically I used one try/catch block for each function. But, since I am creating an SSIS script, I noticed in an online posting (I don't have it handy anymore) that they were using multiple try/catch blocks. That is why I am posting here to get feedback on that.
– J Weezy
Apr 10 at 19:09





@t3chb0t Regarding the multiple try/catch blocks, typically I used one try/catch block for each function. But, since I am creating an SSIS script, I noticed in an online posting (I don't have it handy anymore) that they were using multiple try/catch blocks. That is why I am posting here to get feedback on that.
– J Weezy
Apr 10 at 19:09
















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f191427%2factive-directory-retrieve-all-group-members-using-directoryservices%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f191427%2factive-directory-retrieve-all-group-members-using-directoryservices%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Chat program with C++ and SFML

Function to Return a JSON Like Objects Using VBA Collections and Arrays

Will my employers contract hold up in court?