sile007
9/5/2017 - 2:10 PM

Active Directory get current Domain function

Active Directory get current Domain function

function getDomain
{
	#Reading current Active Directory
	$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
	$objSearcher.PageSize = 1
	$objSearcher.Filter = "(objectclass=Domain)"
	$objSearcher.SearchScope = "Subtree"
	$currentActiveDirectory = $objSearcher.FindAll()
	
	$LocalDomain = ($currentActiveDirectory.path).replace(",DC=", ".").replace("LDAP://DC=", "")
	$path = $currentActiveDirectory.path
	
	WriteLogFile "function: getDomain - Scriptrunning Domain is $LocalDomain"
	return $LocalDomain, $path
}