How to find if the local computer is in a domain?
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!"
}