Loading VisualBasic code in Powershell to find out I didn’t need it

By | 2015-10-20

Working in a multi domain environment, I needed the NETBIOS name of the server domain. I eventually got a very simple VisualBasic code block to work in Powershell, but found out it was not what I was looking for. A differentiation did give me what I needed but it proved to be a method not worth using.

I was working on different ways to determine the NETBIOS DomainName of a Windows server (in the server context, not the user context).
I found some information using [ADSI] (Active Directory Service Interfaces) in Powershell, but I also found a reference to WinNTSystemInfo, but using vbscript.

It seemed to me that this VBScript object should be easy to (re)create in Powershell. It looks like I didn’t got that part right.

When I finally found a way to get the domain name out of the WinNTSystemInfo object using VisualBasic inside Powershell, it provided me with the Domain in the User context


The same page I found also referenced the ADSystemInfo VB Object, so I gave that a try with the same Powershell Add-Type method.

This time it did give me the server domain NETBIOS name, this is the code that I got working:


In the end I have found another reference, which included the WMI object Win32_NTDomain, again a VBScript / VisualBasic scenario, but using WMI is easy in Powershell:

This could give numerous domains, because in the case the user is from another domain than the server, it gives both. I haven’t found a way to determine which domain is the user domain, but you could use a Where clause, like (Get-WmiObject Win32_NTDomain | ?{$_.DnsForestName -like ((Get-WmiObject Win32_ComputerSystem).Domain) }).DomainName, or maybe this [DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain().Forest (or GetComputerDomain().DomainControllers.Forest).

Using ADSI it would be this using Powershell:


This does provide the NETBIOS DomainName in the server context.


So keeping it to Powershell without VisualBasic is much easier.


Leave a Reply

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