Win OS – Get Domain Information – Using WMI

Background

Using WMI, Let us get the short domain name

Windows Management Instrumentation (WMI)

Script

Outline

  1. Issue “Get-WmiObject -Class Win32_NTDomain”
    • Capture result of Get-WmiObject in a object
    • Result is actually a list
  2. Iterate through the list
    • Each time place list node in an object
    • Here are the important attributes
      • DnsForestName
      • DomainName
      • DomainControllerName
      • DomainControllerAddress
      • Roles

Powershell

Code

Set-StrictMode -Version 2.0
[object] $objWin32_NTDomain =$null;
[int]    $iEntry=0;
[string] $strLineBreak= "=" * 50;

Function getActiveDirectoryInfoUsingWMI()
{

    [string] $log="";

    $objWin32NTDomainList = Get-WmiObject -Class Win32_NTDomain

    if ($objWin32NTDomainList -eq $null)
    {

        $log = "Unable to access WMI Object Win32_NTDomain List"

        Write-Host $log;

        Return

    }

    else
    {

        $log = "WMI Object Win32_NTDomain accessed"

        Write-Host $log;

        Write-Host ( $strLineBreak );

        $objWin32NTDomainList 

    }   

    $iEntry=1;

    Write-Host ( $strLineBreak );

    foreach ($objResult in $objWin32NTDomainList)
    {

        $log = "`Entry {0}" -f $iEntry;

        Write-Host($log);

        $log = "`t Description:- {0}" -f $objResult.Description;

        Write-Host($log);

        $log = "`t Dns Forest Name:- {0}" -f $objResult.DnsForestName;

        Write-Host($log);

        $log = "`t Domain Name:- {0}" -f $objResult.DomainName;

        Write-Host($log);

        $log = "`t Domain Controller Name:- {0}" -f $objResult.DomainControllerName;

        Write-Host($log);

        $log = "`t Domain Controller Address:- {0}" -f $objResult.DomainControllerAddress;

        Write-Host($log);

        $log = "`t Roles:- {0}" -f $objResult.Roles;

        Write-Host($log);

        $iEntry = $iEntry + 1;

        Write-Host "";

        Write-Host "";

    }

    Write-Host ( $strLineBreak );

}

getActiveDirectoryInfoUsingWMI

Output

Output – Text

Entry 1
         Description:- HRDB
         Dns Forest Name:-
         Domain Name:-
         Domain Controller Name:-
         Domain Controller Address:-
         Roles:-

Entry 2
         Description:- LAB
         Dns Forest Name:- lab.org
         Domain Name:- LAB
         Domain Controller Name:- \\DC01
         Domain Controller Address:- \\192.168.10.30
         Roles:-

Output – Image

 

Explanation

  1. On Workstation
    • Standalone
      • Single Node returned
        • Work Station Info
    • Joined To Domain ( Member Node)
      • Returned
        • Work Station Node Info
        • Domain Info
  2. On Domain Controller
    • Domain Information

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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

Google photo

You are commenting using your Google 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