Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find if the local computer is in a domain?

Tags:

Is there an easy and fast way to find out if the local computer is joined to a domain with PowerShell?

I find lots of stuff about getting the current workgroup OR domain but no clear indications on how to know if it really is a workgroup or domain. Just want to find this out before calling some Active Directory related stuff that only gives a timeout after a long wait on workgroup computers.

The [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() method takes a long time before failing on workgroup computers and the WMI class Win32_ComputerSystem shows the name but not if it is a real domain.

like image 430
Per Salmi Avatar asked Dec 10 '10 12:12

Per Salmi


People also ask

How do I know if a user is local or domain?

use echo %logonserver% command and check the output. If it is the local machine then you are using a local account and if it is a DC that is mentioned then you are using a domain user. Another option is to use whoami command and: If you are logged using a local account then you will get as a result Computer\username.

How do I find my computer domain name in PowerShell?

Use Get-WmiObject to get domain name of a computer using PowerShell. Using Get-AdDomainController get domain name in active directory. wmic and SystemInfo command-line tool are useful to get domain name in cmd.


1 Answers

Win32_ComputerSystem has a PartOfDomain property that indicates whether the computer is domain joined or not. There is also a workgroup property - that should be blank if the computer is on a domain.

Example:

if ((gwmi win32_computersystem).partofdomain -eq $true) {     write-host -fore green "I am domain joined!" } else {     write-host -fore red "Ooops, workgroup!" } 
like image 137
craika Avatar answered Oct 07 '22 18:10

craika