Windows: Script to get the NetBIOS Name of an Active Directory Domain

Hi,

just a short post :-). A powershell script to get the NetBIOS Name of an Active Directory Domain


###############################################################################
# Gets the NetBIOS Domain
# Author Michael Albert michlstechblog.info
# License: GPL v2
###############################################################################
[reflection.assembly]::LoadWithPartialName("System.DirectoryServices.Protocols")|Out-Null

if($args.count -ne 1){
    Write-Warning " Start script with fqdn as parameter"
    Write-Warning (" for example: "+$myInvocation.myCommand.name+" yourdomain.com")
    exit 1
}
$sDomainName=$args[0]
# Get AD Root
$oRootDSE = [ADSI]"LDAP://RootDSE"
$sConfig = $oRootDSE.Get("configurationNamingContext")
# AD Object AD Root
$oADSearchRoot=New-object System.DirectoryServices.DirectoryEntry("LDAP://CN=Partitions," + $sConfig)
# Search for Netbiosname of the specified domain
$sSearchString="(&(objectclass=Crossref)(dnsRoot="+$sDomainName+")(netBIOSName=*))"
$oSearch=New-Object directoryservices.DirectorySearcher($oADSearchRoot,$sSearchString)
$sNetBIOSName=($oSearch.FindOne()).Properties["netbiosname"]
# Print out
Write-Host "Domain NetBIOS Name:" $sNetBIOSName

Have fun :-)!

Michael

Advertisment to support michlstechblog.info

GetDomainNetBIOSNames
GetDomainNetBIOSNames.ps1

Script to get the NetBIOS Domain of an Active Directory Domain

Author:Michael Albert
Category:Powershell Scripts
Date:March 26, 2013
1.1 KiB
1196 Downloads
Details...

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.