Skip to content

Implement LDAP-authenticated AD object query function#236

Merged
rebelinux merged 2 commits intodevfrom
copilot/implement-ldap-query-function
Feb 28, 2026
Merged

Implement LDAP-authenticated AD object query function#236
rebelinux merged 2 commits intodevfrom
copilot/implement-ldap-query-function

Conversation

Copy link
Contributor

Copilot AI commented Feb 27, 2026

Get-ADObjectList lacked a Credential parameter and only applied credentials when $Server was provided, making authenticated LDAP queries unreliable. Several additional bugs were present in resource management and list initialization.

Changes

  • Authentication: Added explicit [pscredential]$Credential parameter; credentials now passed to DirectoryEntry in all code paths (with and without -Server)
  • Resource cleanup: Added $results.Dispose() and $directoryEntry.Dispose() to prevent leaks from SearchResultCollection and DirectoryEntry
  • List initialization: Fixed [System.Collections.Generic.List[PSObject]]$x = [System.Collections.ArrayList]::new()[System.Collections.Generic.List[PSObject]]::new()
  • DN construction: Replaced fragile string-replace approach with explicit ($Domain.Split('.') | ForEach-Object { "DC=$_" }) -join ','
  • Default filter: No-op when -Object is omitted now uses (objectClass=*) instead of throwing a null-reference on $filters[0]
  • Metadata: Added [CmdletBinding()], [OutputType([System.Collections.Generic.List[PSObject]])], and a proper comment-based help block

Example usage

# With explicit server and credential (authenticated)
Get-ADObjectList -Domain 'contoso.com' -Server 'dc01.contoso.com' -Object 'Users', 'Groups' -Credential $Cred

# Without server — credentials still applied via DirectoryEntry
Get-ADObjectList -Domain 'contoso.com' -Object 'DomainControllers' -Credential $Cred
Original prompt

This section details on the original issue you should resolve

<issue_title>[Help Wanted]: Implement a function to extract information from Active Directory objects via the LDAP:// protocol</issue_title>
<issue_description>### Description

Research methods for implementing a function to query Active Directory objects via LDAP:

  • Must use authentication (not impersonation)
  • Must accept Domain and Server as parameters
  • The function can be modularized to retrieve the following object types:
    • Users
    • Computers
    • Groups
    • Group Policy Objects (GPO)
    • Domain Controllers
    • Organizational Units (OU)

Additional Context

The function to be developed will be used as the backbone to migrate the rest of the report sections to LDAP.

Before submitting

  • I have read the documentation, and referred to the known issues before submitting this change request.
  • I have checked for previously opened & closed issues before submitting this change request.</issue_description>

Comments on the Issue (you are @copilot in this section)

@rebelinux Can you recommend a C# library that I can use to build the solution? I'm starting to program in C# again, something I haven't done in over 20 years, and I'd like to start developing a solution.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@github-actions
Copy link

PSScriptAnalyzer results:

Errors: [0], Warnings: [14], Information: [0]


RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-AbrADGPO.ps1
Line       : 20
Message    : The parameter 'ValidDCFromDomain' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-AbrADDomainObject.ps1
Line       : 19
Message    : The parameter 'ValidDcFromDomain' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-AbrADTrust.ps1
Line       : 20
Message    : The parameter 'ValidDCFromDomain' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-AbrADCACRLSetting.ps1
Line       : 22
Message    : The parameter 'CA' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : ConvertTo-ADObjectName.ps1
Line       : 21
Message    : The parameter 'DC' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-AbrADDomain.ps1
Line       : 20
Message    : The parameter 'ValidDcFromDomain' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-AbrADKerberosAudit.ps1
Line       : 20
Message    : The parameter 'ValidDCFromDomain' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-AbrADOU.ps1
Line       : 20
Message    : The parameter 'ValidDCFromDomain' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-ADObjectSearch.ps1
Line       : 21
Message    : The parameter 'Filter' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-ADObjectSearch.ps1
Line       : 22
Message    : The parameter 'Properties' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-ADObjectSearch.ps1
Line       : 23
Message    : The parameter 'SelectPrty' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : ConvertTo-ADCanonicalName.ps1
Line       : 20
Message    : The parameter 'Domain' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-AbrADDFSHealth.ps1
Line       : 20
Message    : The parameter 'DCs' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Invoke-AsBuiltReport.Microsoft.AD.ps1
Line       : 21
Message    : The parameter 'Credential' has been declared but not used.

…sposal and DN construction

Co-authored-by: rebelinux <1002783+rebelinux@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement function to extract information from Active Directory via LDAP Implement LDAP-authenticated AD object query function Feb 27, 2026
@github-actions
Copy link

PSScriptAnalyzer results:

Errors: [0], Warnings: [14], Information: [0]


RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-AbrADGPO.ps1
Line       : 20
Message    : The parameter 'ValidDCFromDomain' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-AbrADDomainObject.ps1
Line       : 19
Message    : The parameter 'ValidDcFromDomain' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-AbrADTrust.ps1
Line       : 20
Message    : The parameter 'ValidDCFromDomain' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-AbrADCACRLSetting.ps1
Line       : 22
Message    : The parameter 'CA' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : ConvertTo-ADObjectName.ps1
Line       : 21
Message    : The parameter 'DC' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-AbrADDomain.ps1
Line       : 20
Message    : The parameter 'ValidDcFromDomain' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-AbrADKerberosAudit.ps1
Line       : 20
Message    : The parameter 'ValidDCFromDomain' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-AbrADOU.ps1
Line       : 20
Message    : The parameter 'ValidDCFromDomain' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-ADObjectSearch.ps1
Line       : 21
Message    : The parameter 'Filter' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-ADObjectSearch.ps1
Line       : 22
Message    : The parameter 'Properties' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-ADObjectSearch.ps1
Line       : 23
Message    : The parameter 'SelectPrty' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : ConvertTo-ADCanonicalName.ps1
Line       : 20
Message    : The parameter 'Domain' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Get-AbrADDFSHealth.ps1
Line       : 20
Message    : The parameter 'DCs' has been declared but not used.

RuleName   : PSReviewUnusedParameter
Severity   : Warning
ScriptName : Invoke-AsBuiltReport.Microsoft.AD.ps1
Line       : 21
Message    : The parameter 'Credential' has been declared but not used.

@rebelinux rebelinux marked this pull request as ready for review February 28, 2026 01:13
@rebelinux rebelinux merged commit 065928b into dev Feb 28, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Help Wanted]: Implement a function to extract information from Active Directory objects via the LDAP:// protocol

2 participants