title: NetBIOS domain of computer in PowerShell
body: <p>How can I get the NetBIOS (aka 'short') domain name of the current computer from PowerShell?</p>
  
  <p>$ENV:USERDOMAIN displays the domain of the current user, but I want the domain that the current machine is a member of.</p>
  
  <p>I've discovered you can do it <a href="http://www.wisesoft.co.uk/scripts/vbscript_display_netbios_domain_name.aspx" rel="noreferrer">pretty easily in VBScript</a>, but apparently <a href="http://technet.microsoft.com/en-us/library/ff730963.aspx" rel="noreferrer">ADSystemInfo isn't very nice to use</a> in PowerShell.</p>
  
  <p><em>Update</em></p>
  
  <p>Here's my final solution incorporating the suggestion of using <a href="http://msdn.microsoft.com/en-us/library/aa394224%28v=vs.85%29.aspx" rel="noreferrer">Win32_NTDomain</a>, but filtering to the current machine's domain</p>
  
  <pre><code>$wmiDomain = Get-WmiObject Win32_NTDomain -Filter "DnsForestName = '$( (Get-WmiObject Win32_ComputerSystem).Domain)'"
  $domain = $wmiDomain.DomainName
  </code></pre>