Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue] - Health Checker - Remove AD Module dependencies #2252

Open
dpaulson45 opened this issue Dec 11, 2024 · 6 comments
Open

[Issue] - Health Checker - Remove AD Module dependencies #2252

dpaulson45 opened this issue Dec 11, 2024 · 6 comments

Comments

@dpaulson45
Copy link
Member

Describe the issue
Been seeing a lot of odd issues with the AD cmdlets, we just need to remove them and come up with ways to get the information without using them.

Commands that need to be removed:

Get-ADComputer
Get-ADPrincipalGroupMembership
Get-ADObject

Need to use LDAP Query to find the information that we need.

@Shinbaum
Copy link
Contributor

$ComputerName="NY-EX19-01"
$adsisearcher = New-Object system.directoryservices.directorysearcher
$DomainDN = "DC="+(Get-ExchangeServer $ComputerName).OrganizationalUnit.Split("/")[0].Replace(".",",DC=")
$adsisearcher = New-Object system.directoryservices.directorysearcher
$adsisearcher.SearchRoot = 'LDAP://' + $DomainDN
$adsisearcher.Filter = "(&(objectCategory=computer)(objectClass=computer)(cn=$ComputerName))"
$adsisearcher.FindOne().Properties.distinguishedname

#Need to check that (Get-ExchangeServer $ComputerName).OrganizationalUnit always has the right domain, and in FQDN format
#Need to check that $adsisearcher will go to another domain correctly to do the query

@dpaulson45
Copy link
Member Author

@Shinbaum if you change $adsisearcher.SearchRoot = 'LDAP://' + $DomainDN to $adsisearcher.SearchRoot = 'GC://' + $DomainDN then it will work, as long as the DC that we pick is also a GC.

@Shinbaum
Copy link
Contributor

$ComputerName="NY-EX19-01"
$adsisearcher = New-Object system.directoryservices.directorysearcher
$DomainDN = "DC="+(Get-ExchangeServer $ComputerName).OrganizationalUnit.Split("/")[0].Replace(".",",DC=")
$adsisearcher = New-Object system.directoryservices.directorysearcher
$adsisearcher.SearchRoot = 'GC://' + $DomainDN
$adsisearcher.Filter = "(&(objectCategory=computer)(objectClass=computer)(cn=$ComputerName))"
$adsisearcher.FindOne().Properties.distinguishedname

Works in my lab, but all the DCs are GCs. Can directorysearcher pick a DC that is not a GC?

@dpaulson45
Copy link
Member Author

Could use this function to find the GC.

Shared/ActiveDirectoryFunctions/Get-GlobalCatalogServer.ps1

@Shinbaum
Copy link
Contributor

$ComputerName="NY-EX19-01"
$ADSite = (Get-ExchangeServer -Identity $ComputerName).Site.Name
$GC = ([System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain().Forest.FindGlobalCatalog($ADSite)).Name
$adsisearcher = New-Object system.directoryservices.directorysearcher
$DomainDN = "DC="+(Get-ExchangeServer $ComputerName).OrganizationalUnit.Split("/")[0].Replace(".",",DC=")
$adsisearcher = New-Object system.directoryservices.directorysearcher
$adsisearcher.SearchRoot = 'GC://' + $GC + "/" + $DomainDN
$adsisearcher.Filter = "(&(objectCategory=computer)(objectClass=computer)(cn=$ComputerName))"
$adsisearcher.FindOne().Properties.distinguishedname

#This will error if there is no GC in the same site as the Exchange server

@dpaulson45
Copy link
Member Author

That would likely be fine, since it isn't supported to be that way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants