Add Domain Group to Local Server Group, need help with script - RobSampson

Posted on 2012-08-29
Last Modified: 2012-08-30
I found a script on EE from RobSampson that is listed below that I am able to use but have a few questions.

The script is working as far as adding the group to the power users local group. In the code below the group is paul.

But when I run the script I get the error below and no results file is created.

Line 31: Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)

Is there a way to get it to show results so I know if the group was added to all the servers in the list? I need to run it remotely on 187 servers. Is there a way to specify a different domain than the one you are logged in with? Like Domain2\paul instead of paul (domain1\paul).

The servers are in several different domains but the account I am using has access to all of them.

strInputFile = "Computers.txt"
strOuputFile = "Results.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objNetwork = CreateObject("WScript.Network")
Set objUser = GetObject("WinNT://" & objNetwork.UserDomain & "/paul")
strResults = "Adding " & objNetwork.UserDomain & "/paul to local Power Users group"
strResults = strResults & VbCrLf & "========================================================================"
Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
While Not objInputFile.AtEndOfStream
	strComputer = objInputFile.ReadLine
	If Ping(strComputer) = True Then
		Set objGroup = GetObject("WinNT://" & strComputer & "/Power Users")
		On Error Resume Next
		objGroup.Add objUser.ADsPath
		If Err.Number = 0 Then
			strResults = strResults & VbCrLf & strComputer & ": Successfully added"
			strResults = strResults & VbCrLf & strComputer & ": Failed to add: " & Err.Number & " - " & Err.Description
		End If
		On Error GoTo 0
		Set objGroup = Nothing
		strResults = strResults & VbCrLf & strComputer & ": Unable to ping"
	End If
Set objInputFile = Nothing
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strResults
Set objOutputFile = Nothing
Set objFSO = Nothing
Set objNetwork = Nothing
MsgBox "Finished. Please see " & strOutputFile
Function Ping(strComputer)
	Dim objShell, boolCode
	Set objShell = CreateObject("WScript.Shell")
	boolCode = objShell.Run("Ping -n 1 -w 300 " & strComputer, 0, True)
	If boolCode = 0 Then
		Ping = True
		Ping = False
	End If
End Function                      

Open in new window

Question by:REIUSA
    LVL 11

    Accepted Solution

    Maybe you get an error because you spelled wrong variable name:
    strOuputFile = "Results.txt"

    Open in new window

    I guess it should be:
    strOutputFile = "Results.txt"

    Open in new window

    After running this script you can see results in Results.txt file where this was successfully.
    For other domain try to change this line:
    Set objUser = GetObject("WinNT://" & objNetwork.UserDomain & "/paul")

    Open in new window

    Set objUser = GetObject("WinNT://domain2/paul")

    Open in new window


    Author Closing Comment

    Sweet, thanks. It works great now.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
    Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now