search
Categories
Sponsors
VirtualMetric Hyper-V Monitoring, Hyper-V Reporting
Archive
Blogroll

Badges
MCSE
Community

Cozumpark Bilisim Portali
Getting Distinguished Names of your AD joined Servers
Posted in Windows Powershell, Windows Server | No Comment | 1,765 views | 18/07/2013 10:10

You can get DNs of your servers with following PowerShell script:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$DomainServers = Get-ADComputer -Filter *
$ChildDomainServers = Get-ADComputer -Filter * -SearchBase "DC=child,DC=domain,DC=com" -Server "child.domain.com"
$Servers = Get-Content C:\Servers.txt
foreach ($Server in $Servers)
{
	$DN = $null;
	$DN = ($DomainServers | where DNSHostName -eq "$Server").DistinguishedName
	if (!$DN)
	{
		$DN = ($ChildDomainServers | where DNSHostName -eq "$Server").DistinguishedName
		if (!$DN)
		{
			Add-Content -Value $Server -Path C:\DNs.txt
		}
		else
		{
			Add-Content -Value $DN -Path C:\DNs.txt
		}
	}
	else
	{
		Add-Content -Value $DN -Path C:\DNs.txt		
	}
}

You should add your server list into C:\Servers.txt.



Leave a Reply