Skip to content

Instantly share code, notes, and snippets.

@IISResetMe
Last active August 29, 2015 14:11
Show Gist options
  • Save IISResetMe/22a1d94a6d01ae181c87 to your computer and use it in GitHub Desktop.
Save IISResetMe/22a1d94a6d01ae181c87 to your computer and use it in GitHub Desktop.
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