PowerShell Script: Distinguished Name / Fully Qualified Domain Name to string

Posted on February 22, 2010. Filed under: Powershell Tangents |

By: Brenton Blawat

This article is designed to be short and sweet. This article displays the method by which one would retrieve the FQDN or Distinguished Name of the Domain. This is code is very useful for any operations in Active Directory. A must know for any scripter that needs to call the domain on a system without hard coding the value in the script.

Lets take a theoretical network that consists of ‘division’ subdomain, ‘domain’ as the domain, and ‘root’ as the domain root.

Root Distinguished name – Easy Method in PowerShell

   1: # Instantiate The ADSI Provider

   2: $root = [ADSI]''

   3: $CurrentDN = $root.DistinguishedName

Result:

The variable $CurrentDN will contain:

DN=division,DN=domain,DN=root

E.G. DN=bittangents,DN=com

Root Fully Qualified Domain Name (FQDN) – Easy Method In PowerShell

   1: # Retrieve the Fully Qualified Domain Name and store it in $FQDN Variable

   2: [String]$FQDN =  [System.DirectoryServices.ActiveDirectory.Domain]::getCurrentDomain()

   3:  

Result:

The variable $FQDN will contain:

division.domain.root

E.G. bittangents.com

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

Gravatar
WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

    About

    Business and Information Technology Tangents is dedicated to providing quality content while informing the world about technology.

    RSS

    Subscribe Via RSS

    • Subscribe with Bloglines
    • Add your feed to Newsburst from CNET News.com
    • Subscribe in Google Reader
    • Add to My Yahoo!
    • Subscribe in NewsGator Online
    • The latest comments to all posts in RSS

    Meta

Liked it here?
Why not try sites on the blogroll...

Follow

Get every new post delivered to your Inbox.