如何查找本地计算机是否在域中? [英] How to find if the local computer is in a domain?

查看:136
本文介绍了如何查找本地计算机是否在域中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单且快速的方法来确定本地计算机是否已通过 PowerShell 加入域?

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

我找到了很多关于获取当前工作组或域的内容,但没有明确说明如何知道它是否真的是工作组或域.只是想在调用一些与 Active Directory 相关的东西之前找出这一点,这些东西只会在工作组计算机上长时间等待后超时.

I find lots of stuff about getting the current workgroup OR domain but no clear indications on how to know if it really is a workgroup or domain. Just want to find this out before calling some Active Directory related stuff that only gives a timeout after a long wait on workgroup computers.

[System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() 方法需要很长时间才能在工作组计算机上失败并且 WMI 类 Win32_ComputerSystem 显示名称但如果它是一个真正的域,则不是.

The [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() method takes a long time before failing on workgroup computers and the WMI class Win32_ComputerSystem shows the name but not if it is a real domain.

推荐答案

Win32_ComputerSystem 有一个 PartOfDomain 属性,用于指示计算机是否已加入域.还有一个工作组属性 - 如果计算机在域中,它应该是空白的.

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.

示例:

if ((gwmi win32_computersystem).partofdomain -eq $true) {
    write-host -fore green "I am domain joined!"
} else {
    write-host -fore red "Ooops, workgroup!"
}

这篇关于如何查找本地计算机是否在域中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆