Last active
August 29, 2015 14:11
-
-
Save IISResetMe/22a1d94a6d01ae181c87 to your computer and use it in GitHub Desktop.
Domain vs Forest in Jeff's AD health check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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