识别计算机是在域还是工作组?

时间:2016-07-21 12:47:34

标签: windows batch-file

是否可以使用批处理脚本快速识别计算机是domain还是workgroup的成员?如果它是domain的成员,那么domain的名称是什么?

1 个答案:

答案 0 :(得分:0)

最后,我能够使用PowerShell找到它并在批处理变量中捕获它。

以下是代码

@echo off
REM Bellow logic is to identify "Computer membership"? True=Member of domain | False=Member of Workgroup
for /f %%a in ('powershell "(Get-WmiObject -Class Win32_ComputerSystem).PartOfDomain"') do set ComMem=%%a
echo %ComMem%

If %ComMem% Equ True    (
                        GoTo Domainmember
                        ) Else  (
                                GoTo WorkgroupMember
                                )


REM Bellow logic is will find Domain / Workgroup Name

:Domainmember

for /f %%f in ('powershell "(Get-WmiObject Win32_ComputerSystem).Domain"') do set MemNme=%%f
Pause
GoTo End
:WorkgroupMember
for /f %%f in ('powershell "(Get-WmiObject Win32_ComputerSystem).Workgroup"') do set MemNme=%%f

:End
Echo %MemNme%
pause