Web Images Videos Maps News Shopping Gmail more »
Recently Visited Groups | Help | Sign in
Google Groups Home
remotely query group membership of machine via script/wmi
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Expand all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
sumGirl  
View profile  
 More options Nov 29 2004, 10:38 am
Newsgroups: microsoft.public.windowsxp.wmi
From: emeb...@netscape.net (sumGirl)
Date: 29 Nov 2004 07:38:32 -0800
Local: Mon, Nov 29 2004 10:38 am
Subject: remotely query group membership of machine via script/wmi
Hi all and happy holidays. I am unsure whether or not this is
possible, so excuse me in advance if this is a dumb question. I need
to make sure a particular user account is a member of the
administrators group on certain remote machines and I am hoping I can
use a script (via WMI?) to do that. I dont need to add or change user
properties, just query the remote machine to find out this info so I
can act on it later, call the user, etc...

Can someone help me with an example script of how to do this?


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Torgeir Bakken (MVP)  
View profile  
 More options Nov 29 2004, 4:32 pm
Newsgroups: microsoft.public.windowsxp.wmi
From: "Torgeir Bakken \(MVP\)" <Torgeir.Bakken-s...@hydro.com>
Date: Mon, 29 Nov 2004 22:32:17 +0100
Local: Mon, Nov 29 2004 4:32 pm
Subject: Re: remotely query group membership of machine via script/wmi

sumGirl wrote:
> Hi all and happy holidays. I am unsure whether or not this is
> possible, so excuse me in advance if this is a dumb question. I need
> to make sure a particular user account is a member of the
> administrators group on certain remote machines and I am hoping I can
> use a script (via WMI?) to do that. I dont need to add or change user
> properties, just query the remote machine to find out this info so I
> can act on it later, call the user, etc...

> Can someone help me with an example script of how to do this?

Hi

Using ADSI is easier.

Script below assumes domain computers that you have implicit
admin access to.

'--------------------8<----------------------

' computer to connect to
sComputer = "some name or ip address"

' user name to check for
sUser = "something"

' ping the computer to see if it is available
If IsConnectible(sComputer, "", "") Then

   On Error Resume Next
   ' try to connect to the administrator account on computer
   Set oGroup = GetObject("WinNT://" & sComputer & "/Administrators")

   If Err.Number = 0 Then
     bUserExist = False  ' init value
     ' was able to connect to the computer, now enumerate users
     For Each oUser in oGroup.Members
       If LCase(sUser) = LCase(oUser.Name) Then
         bUserExist = True
       End If
     Next

     If Err.Number <> 0 Then
       WScript.Echo "Could not enumerate users in group"
     Elseif bUserExist Then
       WScript.Echo "User exists in group"
     Else
       WScript.Echo "User does not exists in group"
     End If
   Else
     WScript.Echo "Could not connect to the computer"
   End If
Else
   WScript.Echo "Could not ping the computer"
End If

Function IsConnectible(sHost, iPings, iTO)
    ' Returns True or False based on the output from ping.exe
    '
    ' Author: Alex Angelopoulos/Torgeir Bakken
    ' Works an "all" WSH versions
    ' sHost is a hostname or IP
    ' iPings is number of ping attempts
    ' iTO is timeout in milliseconds
    ' if values are set to "", then defaults below used

     Const OpenAsASCII      =  0
     Const FailIfNotExist   =  0
     Const ForReading       =  1
     Dim oShell, oFSO, sTempFile, fFile

     If iPings = "" Then iPings = 2
     If iTO = "" Then iTO = 750

     Set oShell = CreateObject("WScript.Shell")
     Set oFSO = CreateObject("Scripting.FileSystemObject")

     sTempFile = oFSO.GetSpecialFolder(2).ShortPath & "\" & oFSO.GetTempName

     oShell.Run "%comspec% /c ping.exe -n " & iPings & " -w " & iTO _
        & " " & sHost & ">" & sTempFile, 0 , True

     Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, _
                                       FailIfNotExist, OpenAsASCII)

     Select Case InStr(fFile.ReadAll, "TTL=")
       Case 0 IsConnectible = False
       Case Else IsConnectible = True
     End Select

     fFile.Close
     oFSO.DeleteFile(sTempFile)

End Function

'--------------------8<----------------------

--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Falz  
View profile  
 More options Nov 29 2004, 4:43 pm
Newsgroups: microsoft.public.windowsxp.wmi
From: "Peter Falz" <pf.ms.n...@asp-solutions.de>
Date: Mon, 29 Nov 2004 22:43:39 +0100
Local: Mon, Nov 29 2004 4:43 pm
Subject: Re: remotely query group membership of machine via script/wmi
Hi sumGirl,

"sumGirl" <emeb...@netscape.net> schrieb im Newsbeitrag news:a5e13cff.0411290738.17435a09@posting.google.com...

> Hi all and happy holidays. I am unsure whether or not this is
> possible, so excuse me in advance if this is a dumb question. I need
> to make sure a particular user account is a member of the
> administrators group on certain remote machines and I am hoping I can
> use a script (via WMI?) to do that. I dont need to add or change user
> properties, just query the remote machine to find out this info so I
> can act on it later, call the user, etc...
> Can someone help me with an example script of how to do this?

with the following WQL-Query, you get a enumaration of all
Groups the user is associated to:

ASSOCIATORS OF
    {Win32_UserAccount.Domain="[DOMAIN\WORKGROUP]",Name="[USERNAME]"}
    WHERE resultClass = Win32_Group

But i agree with Torgeir, that ADSI will be the right place
to get those informations.

HTH

Ciao
Peter


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
sumGirl  
View profile  
 More options Nov 30 2004, 9:40 am
Newsgroups: microsoft.public.windowsxp.wmi
From: emeb...@netscape.net (sumGirl)
Date: 30 Nov 2004 06:40:54 -0800
Local: Tues, Nov 30 2004 9:40 am
Subject: Re: remotely query group membership of machine via script/wmi
Thanks everyone. Its wonderful to have several mousetraps for this! Happy Holidays.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google