各位好,我想透過 windows script host 寫一個程式,去確認某網域帳戶是否有加入該電腦的 Group Administrators 中
我研究了好久 透過 windows script host 去抓取 WMI 資訊應該有相關資料
但我用 wmiexplorer 去看沒看到相關的資訊
想請問有人用過這個方法寫過類似的東西嗎
目前我用以下 Code 撈出電腦基本資料
WScript.Stdout.writeline "COMPUTERNAME=" & system_name
WScript.Stdout.Writeline "DOMAINNAME=" & Domain
WScript.Stdout.Writeline "USERNAME=" & objNetwork.UserDomain & "\" & objNetwork.UserName --> 此處只能顯示目前使用哪個網域帳號登入, 我的目的想要把整個我們在控制台中看到的本機使用者和群組的相關資訊都撈出
謝謝,苦惱中
$userToFind = $args[0] $administratorsAccount = Get-WmiObject Win32_Group -filter "LocalAccount=True AND SID='S-1-5-32-544'" $administratorQuery = "GroupComponent = `"Win32_Group.Domain='" + $administratorsAccount.Domain + "',NAME='" + $administratorsAccount.Name + "'`"" $user = Get-WmiObject Win32_GroupUser -filter $administratorQuery | select PartComponent |where {$_ -match $userToFind} $user
SELECT * from Win32_GroupUser where GroupComponent= "Win32_Group.Domain='"."',Name='Administrators'"
<pre class="c" name="code">
strComputer = "."
Set wshShell = CreateObject( "WScript.Shell" )
strComputerName = wshShell.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery("SELECT * from Win32_GroupUser where GroupComponent= ""Win32_Group.Domain='" & strComputerName & "',Name='Administrators'""")
For Each objItem in colItems
Wscript.Echo "PartComponent: " & objItem.PartComponent
Next