- 1 year ago
PowerShell Script to check if a computer is a domain controller or not
To check if a computer is a domain controller or not using PowerShell, you can use the Get-WmiObject
cmdlet to retrieve the Win32_ComputerSystem
class and check the value of the DomainRole
property. Here's an example script:
powershell$computerName = "COMPUTER_NAME" # Replace with the actual computer name
# Get the computer system information
$computerSystem = Get-WmiObject -Class Win32_ComputerSystem -ComputerName $computerName
# Check the domain role
if ($computerSystem.DomainRole -eq 4) {
Write-Host "The computer $computerName is a domain controller."
} else {
Write-Host "The computer $computerName is not a domain controller."
}
In this script, replace "COMPUTER_NAME"
with the name of the computer you want to check. The Get-WmiObject
cmdlet retrieves the Win32_ComputerSystem
class for the specified computer, and the DomainRole
property indicates the role of the computer in the domain.
The DomainRole
property can have different values, where 4 represents a domain controller. The script checks if the DomainRole
is equal to 4 and outputs the appropriate message indicating whether the computer is a domain controller or not.
Execute the script, and it will display the result based on the computer's domain role.
Note: The script requires administrative privileges or appropriate access rights to query WMI information on the remote computer.