sumGirl said:
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<----------------------