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

Badges
MCSE
Community

Cozumpark Bilisim Portali
Posted in Hosting & IIS7, Windows Powershell, Windows Server | 1 Comment | 12,167 views | 02/03/2010 12:35

My script works on all Active Directory Infrastructures without any change on script.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Function Get-ADInfo
{
    $ADDomain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
    $ADDomainName = $ADDomain.Name
    $Netbios = $ADDomain.Name.Split(".")[0].ToUpper()
    $ADServer = ($ADDomain.InfrastructureRoleOwner.Name.Split(".")[0])
    $FQDN = "DC=" + $ADDomain.Name -Replace("\.",",DC=")
 
    $Results = New-Object Psobject
    $Results | Add-Member Noteproperty Domain $ADDomainName
    $Results | Add-Member Noteproperty FQDN $FQDN
    $Results | Add-Member Noteproperty Server $ADServer
    $Results | Add-Member Noteproperty Netbios $Netbios
    Write-Output $Results
}

Usage is pretty simple:

Get-ADInfo

Thats all! :)

Getting Netbios name:

(Get-ADInfo).Netbios

Getting FQDN:

(Get-ADInfo).FQDN

Getting Active Directory Domain Name:

(Get-ADInfo).$ADDomainName

Getting Active Directory Primary Server Name:

(Get-ADInfo).$ADServer

You can use this in your all scripts. You no longer need any active directory information.