How to find if the local computer is in a domain?

前端 未结 3 1905
失恋的感觉
失恋的感觉 2021-02-07 00:48

Is there an easy and fast way to find out if the local computer is joined to a domain with PowerShell?

I find lots of stuff about getting the current wo

3条回答
  •  遇见更好的自我
    2021-02-07 01:14

    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!"
    }
    

提交回复
热议问题