QuickTip: Get Domain Name of Computer

In PowerShell it is relatively trivial to retrieve the domain for the logged in user, as this is stored in the environment variable. In multi-domain environments it is often the case that the user account is a member of the same domain as the computer account. To retrieve the domain name of the current computer the following command can be executed:

1
[System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties()

ComputerDomainName

To only retrieve the Domain Name the following command can be used:

1
[System.Net.NetworkInformation.IPGlobalProperties]::GetIPGlobalProperties().DomainName

For more information about the GetIPGlobalProperties method and the IPGlobalProperties class please refer to the following article:
MSDN – IPGlobalProperties

Share

Leave a Reply