
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check If Computer is Connected to a Domain Using PowerShell
To check if a computer is connected to any domain we can use multiple methods. In this article, we can use two methods. One using the System Information of the computer and the second using the DirectoryServices .Net Class.
First method using System Information and filter out a string called “Domain” which shows us if the computer is in the domain or the workgroup.
systeminfo | findstr "Domain"
Output
If the computer is in the workgroup, It will show the workgroup name. For example,
In the second method, we will use the directory service .Net class method name GetComputerDomain(). If the server is not connected to the domain then this command will throw an error.
For the server connected to a domain,
[System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain()
Output
Forest : labdomain.local DomainControllers : {ADDC.labdomain.local} Children : {} DomainMode : Parent : PdcRoleOwner : ADDC.labdomain.local RidRoleOwner : ADDC.labdomain.local InfrastructureRoleOwner : ADDC.labdomain.local Name : labdomain.local
You can filter out the domain name using Name Property.
[System.DirectoryServices.ActiveDirectory.Domain]::GetComputerDomain() | Select Name
Output
Name ---- labdomain.local
If the server is not connected to the domain then, it will throw an error saying the local computer is not joined to any domain as shown below.