function Get-Active-Directory-Forest-Object ([string]$ForestName, [System.Management.Automation.PsCredential]$Credential) { #if forest is not specified, get current context forest If (!$ForestName) { $ForestName = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest().Name.ToString() } If ($Credential) { $credentialUser = $Credential.UserName.ToString() $credentialPassword = $Credential.GetNetworkCredential().Password.ToString() $adCtx = New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext("forest", $ForestName, $credentialUser, $credentialPassword ) } Else { $adCtx = New-Object System.DirectoryServices.ActiveDirectory.DirectoryContext("forest", $ForestName) } $output = ([System.DirectoryServices.ActiveDirectory.Forest]::GetForest($adCtx)) Return $output }
By Edge Pereira
No comments:
Post a Comment