Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBS - Create NewFile With Adm Users

Status
Not open for further replies.

TakaBR

Technical User
Oct 9, 2018
1
BR
Hi all,

I have a script that collects users members of the local administrators group and this script creates a file for each user, I would like to know if it is possible to generate these files and then unify in a single file example:

administrator.txt
user_X.txt
admin.txt

New file:

administrator_user_X_admin.txt

The problem is that the amount of users varies from computer to computer. I'll copy the script that does this collection. I appreciate who can help me.

'===================================
On Error Resume Next

Set Shell = CreateObject("WScript.Shell")
strOS = shell.ExpandEnvironmentStrings("%OS%")

If strOS = "Windows_NT" Then
strVerKey = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\"
strVersion = Shell.regread(strVerKey & "ProductName")
Else
End if

If strVersion = "Windows Server 2008 R2 Enterprise" Or strVersion = "Windows Server 2008 R2 Standard" Or strVersion = "Windows Server 2012 R2 Standard" Or strVersion = "Windows Server 2012 R2 Enterprise" Or strVersion = "Microsoft Windows Server 2003 R2" Then
WScript.Quit
Else

Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName

Dim UsersGroup
Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators")
For Each objUser in objGroup.Members
UsersGroup = objUser.Name
If UsersGroup = "Administrador" Or UsersGroup = "Domain Admins" Or UsersGroup = "RemoteDesktop_DM" Or UsersGroup = "RemoteDesktop_SD" Then
Else

Set objFolder = objFSO.CreateFolder("C:\Folder")
Set objFolder = objFSO.CreateFolder("C:\Folder\ADMGROUP")
Set objTextFile = objFSO.OpenTextFile("C:\Folder\ADMGROUP\" & strComputer & "_" & UsersGroup & ".txt", ForAppending, TRUE)
objTextFile.Close
objFSO.CopyFolder "C:\Folder\ADMGROUP" , "\\Newtwork\Logs\ADMGROUP", True
End If
Next

End If

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top