Jump to content

Script to get local groups on machine not working for win2k


60aside
 Share

Recommended Posts

Hi,

The following script gives a msgbox with the local groups on the computer.

It's working fine on XP/Vista/7 but does not display anything on Windows 2000.

Has anyone got any ideas why?

$objWMIService = Objget("winmgmts:"&"{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
            If Not IsObj($objWMIService) Then
            msgbox(0,"Error","Unable to connect to " & ".")
            Exit
            Endif
$colItems = $objWMIService.ExecQuery(("Select * from Win32_Group  Where LocalAccount = True"))
            For $objItem in $colItems
            $group = StringSplit($objItem.Caption,'\')
            msgbox(0,"", $group[2])
            Next

Thanks.

Link to comment
Share on other sites

Try this:

$strComputer = "ComputerName"

$objWMIService = Objget("winmgmts:"&"{impersonationLevel=impersonate}!\\" & $strComputer & "\root\cimv2")
            If Not IsObj($objWMIService) Then
            msgbox(0,"Error","Unable to connect to " & ".")
            Exit
            Endif
$colItems = $objWMIService.ExecQuery(("Select * from Win32_Group  Where Domain = '" & $strComputer & "'))
            For $objItem in $colItems
            $group = StringSplit($objItem.Caption,'\')
            msgbox(0,"", $group[2])
            Next

The reason the script won’t run on Windows 2000 is because, prior to Windows XP, the Win32_Group class did not support the property LocalAccount. Change the computer name from . to the local computer name and look for groups where the domain is equal to the local computer.

Edited by Lotheron
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...