How to find if the windows server is in an Active Directory domain via PowerShell?

/ets/shadow
How to remove password from /etc/shadow
May 10, 2020
Control Tower
How to create AWSControlTowerExecution IAM role in AWS account
May 11, 2020

How to find if the windows server is in an Active Directory domain via PowerShell?

active-directory

The Win32_ComputerSystem class represents a computer system operating in a Win32 environment. You can find more information here.

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

The Get-wmiObject cmdlet has its own alias as gwmi.

if ((gwmi win32_computersystem).partofdomain -eq $true) {
    write-host -fore green "The server/computer in Domain!"
} else {
    write-host -fore red "The server/computer is not in domain."
}
Bitnami