Skip to content

Instantly share code, notes, and snippets.

@IISResetMe IISResetMe/healthcheck.ps1
Last active Aug 29, 2015

Embed
What would you like to do?
Domain vs Forest in Jeff's AD health check
param(
...
[Parameter(Mandatory=$false,ParameterSetName='Specific')]
[Parameter(Mandatory=$false,ParameterSetName='All')]
[Switch]$EntireForest
)
function Get-ADDomains {
if($EntireForest)
{
$Domains = ([System.DirectoryServices.ActiveDirectory.forest]::GetCurrentForest().domains)
}
else
{
$Domains = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
}
foreach ($Domain in $Domains) {
$DomName = $Domain.Name
$ADObject = [adsi]"LDAP://$DomName"
$Object = New-Object -TypeName PSObject
$Object | Add-Member -MemberType NoteProperty -Name 'Name' -Value $(ConvertTo-FQDN $Domain.Name)
$Object | Add-Member -MemberType NoteProperty -Name 'FQDN' -Value $Domain.Name
$Object | Add-Member -MemberType NoteProperty -Name 'ObjectSID' -Value $(New-Object System.Security.Principal.SecurityIdentifier($ADObject.objectSid[0], 0)).Value
$Object
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.