- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to check if the 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.
- Related Articles
- How to Join Computer to the AD domain using PowerShell?
- How to check if the USB device is connected to the system using PowerShell?
- How to Remove the computer from the AD domain using PowerShell?
- How to check if the file is empty using PowerShell?
- How to check if a bluetooth device is connected with an Android device using Kotlin?
- How to check if a file is connected with terminal in Python?
- How to check if a bluetooth device is connected with Android device?
- How to check if the date is adjusted by Daylight saving time using PowerShell?
- How to check if the Azure resource group is empty or not using PowerShell?
- How to check if remote ports are open using PowerShell?
- How to retrieve the Azure subnets connected to the virtual network using PowerShell?
- How to get the load balancers connected to the Azure VM using PowerShell?
- How to test remote computer connectivity using PowerShell?
- How to check if PSCustomObject is empty in PowerShell?
- How to find a Computer product serial number using PowerShell?
