Sign in to follow this  
Followers 0
60aside

Script to get local groups on machine not working for win2k

3 posts in this topic

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.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

That works great.

Thanks a lot.

Share this post


Link to post
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
Sign in to follow this  
Followers 0