About Me

My photo
HANUMANGARH, RAJASTHAN, India

Thursday, 15 September 2022

Get Domain Name with DC

 $ADForestInfo = Get-ADForest

$ADForestInfoName = $ADForestInfo.Name

$ADForestInfoDomains = $ADForestInfo.Domains

$ADForestInfoForestMode = $ADForestInfo.ForestMode

$AllDCs = $Null

ForEach ($DomainDNS in $ADForestInfoDomains)

{

[string]$DomainDC = (Get-ADDomainController -Domain $DomainDNS -discover -service “ADWS”).HostName

$DomainInfo = Get-ADDomain -server $DomainDC

$DomainInfoDomainMode = $DomainInfo.DomainMode

[array]$AllDomainDCs = Get-ADDomainController -server $DomainDC -filter *

$AllDomainDCsCount = $AllDomainDCs.Count

Write-Output “Discovered $AllDomainDCsCount Domain Controllers in the $DomainDNS Domain (DFL: $DomainInfoDomainMode) ”

[array]$AllDCs += $AllDomainDCs

}

$AllDCsCount = $AllDCs.Count

Write-Output “Discovered $AllDCsCount Domain Controllers in the AD Forest $ADForestInfoName (FFL: $ADForestInfoForestMode) ”

$AllDCs | select domain,name,operatingsystem,OperatingSystemServicePack | sort domain | ft -auto

No comments:

Post a Comment

Export contact from Justdial

  Extract Data From JustDial using Selenium Let us see how to extract data from Justdial using Selenium and Python. Justdial is a company th...