Check if a computer is a member of a domain or workgroup via PowerShell
Basic bit of code to achieve this as below
if ((gwmi win32_computersystem).partofdomain -eq $true) {
write-host “Server is part of a Domain, continuing with script!” -ForegroundColor Green
} else {
write-host “Server is not part of a Domain, continuing with script!” -ForegroundColor Red
}