+ Reply to Thread
Results 1 to 1 of 1

Thread: WMI script help

  1. #1
    Ultimate Member BobOmega's Avatar
    Join Date
    May 2002
    Location
    Youngstown (well nea
    Posts
    1,102

    WMI script help

     
    So a seemingly impossible task has been handed to me.
    we are in the process of migrating domains and i need to make sure the CIO who did/does a lot of development work doesn't have his old domain account tied to anything important like services.

    that said. I was thinking i could write a WMI script to poll the servers for any specific accounts in the local admin groups on the servers.

    So i've been using scriptomatic to try this out and i can almost get what i want. But i cannot get it to specify the group in the code.

    i'm trying to figure out if it would be worth it to do this in visual studio instead just so i can see any code errors.

    anyone ever done anything like this? soon as i add WHERE to the SELECT it breaks.
    This is the basic Group users code scriptomatic generates. it works but it essentially pulls every domain account when it hits the Domain Users group.
    Code:
    On Error Resume Next
    
    Const wbemFlagReturnImmediately = &h10
    Const wbemFlagForwardOnly = &h20
    
    arrComputers = Array("PC")
    For Each strComputer In arrComputers
       WScript.Echo
       WScript.Echo "=========================================="
       WScript.Echo "Computer: " & strComputer
       WScript.Echo "=========================================="
    
       Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
       Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_GroupUser", "WQL", _
                                              wbemFlagReturnImmediately + wbemFlagForwardOnly)
    
       For Each objItem In colItems
          WScript.Echo "GroupComponent: " & objItem.GroupComponent
          WScript.Echo "PartComponent: " & objItem.PartComponent
          WScript.Echo
       Next
    Next

    If i add a WHERE to that such as this it will no longer run. i've also tried sticking the strComputer string in for the "PC" because it will be run with several targets eventually.
    Code:
    On Error Resume Next
    
    Const wbemFlagReturnImmediately = &h10
    Const wbemFlagForwardOnly = &h20
    
    arrComputers = Array("PC")
    For Each strComputer In arrComputers
       WScript.Echo
       WScript.Echo "=========================================="
       WScript.Echo "Computer: " & strComputer
       WScript.Echo "=========================================="
    
       Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
       Set colItems = objWMIService.ExecQuery("SELECT * FROM Win32_GroupUser WHERE GroupComponent = ""Win32_Group.Domain='PC',Name='Administrators'""", "WQL", _
                                              wbemFlagReturnImmediately + wbemFlagForwardOnly)
    
       For Each objItem In colItems
          WScript.Echo "GroupComponent: " & objItem.GroupComponent
          WScript.Echo "PartComponent: " & objItem.PartComponent
          WScript.Echo
       Next
    Next
    Last edited by BobOmega; August 27th, 2009 at 11:52 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VB/WMI help : copy files between 2 PCs
    By bwcc in forum Webmastering and Programming
    Replies: 0
    Last Post: October 13th, 2008, 02:03 PM
  2. WMI problem
    By kermani34 in forum Applications and Operating Systems
    Replies: 2
    Last Post: July 19th, 2004, 11:32 AM
  3. WMI error...Help
    By Army2001 in forum Technical Support
    Replies: 4
    Last Post: November 9th, 2003, 09:14 PM
  4. WMI for Win95
    By blubomber in forum Applications and Operating Systems
    Replies: 4
    Last Post: August 16th, 2002, 04:47 PM
  5. Anyone do any WMI scripting?
    By newbie~wan in forum Applications and Operating Systems
    Replies: 5
    Last Post: June 28th, 2002, 09:31 AM

Tags for this Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Recommended Sites: ResellerRatings Store Reviews