NetBIOS domain of computer in PowerShell


SUBMITTED BY: Guest

DATE: Nov. 14, 2013, 7:07 a.m.

FORMAT: Text only

SIZE: 1.8 kB

HITS: 1274

  1. $wmiDomain = Get-WmiObject Win32_NTDomain -Filter "DnsForestName = '$( (Get-WmiObject Win32_ComputerSystem).Domain)'"
  2. $domain = $wmiDomain.DomainName
  3. PS C:> Get-WmiObject Win32_ComputerSystem
  4. Domain : WORKGROUP
  5. Manufacturer : Hewlett-Packard
  6. Model : HP EliteBook 8530w (XXXXXXXXX)
  7. Name : ABCHPP2
  8. PrimaryOwnerName : ABC
  9. TotalPhysicalMemory : 4190388224
  10. PS C:> (gwmi WIN32_ComputerSystem).Domain
  11. nbtstat -n | Select-String -Pattern "^ *(.*) *<1B>.*$" | % {$_ -replace '^ *(.*) *<1B>.*$','$1'}
  12. PS C:> (gwmi Win32_NTDomain).DomainName
  13. # Retrieve Distinguished Name of current domain.
  14. $Domain = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain()
  15. $Root = $Domain.GetDirectoryEntry()
  16. $Base = ($Root.distinguishedName)
  17. # Use the NameTranslate object.
  18. $objTrans = New-Object -comObject "NameTranslate"
  19. $objNT = $objTrans.GetType()
  20. # Invoke the Init method to Initialize NameTranslate by locating
  21. # the Global Catalog. Note the constant 3 is ADS_NAME_INITTYPE_GC.
  22. $objNT.InvokeMember("Init", "InvokeMethod", $Null, $objTrans, (3, $Null))
  23. # Use the Set method to specify the Distinguished Name of the current domain.
  24. # Note the constant 1 is ADS_NAME_TYPE_1779.
  25. $objNT.InvokeMember("Set", "InvokeMethod", $Null, $objTrans, (1, "$Base"))
  26. # Use the Get method to retrieve the NetBIOS name of the current domain.
  27. # Note the constant 3 is ADS_NAME_TYPE_NT4.
  28. # The value retrieved includes a trailing backslash.
  29. $strDomain = $objNT.InvokeMember("Get", "InvokeMethod", $Null, $objTrans, 3)
  30. import-module activedirectory
  31. (Get-ADDomain -Identity (Get-WmiObject Win32_ComputerSystem).Domain).NetBIOSName

comments powered by Disqus