Script to create 10,000 test users

I thought I would share the script I made to create 10,000 test users in an NT 4.0 domain for my test lab.  I should note a couple of things:

  • When I first ran this script, my domain only had the default ‘guest’ and ‘administrator’ accounts.
  • I used Visual Basic Script (VBS) which does not require pre-defining of variables or variable types (adding ‘option explicit’ requirements would case the script to fail)
  • The script was ran from a command line as ‘cscript.exe CreateUsersWinNtObj.vbs’
  • No checking was performed to verify that the user ID was unique (in a ‘real’ domain this could cause a problem.
  • This script was not tested with Active Directory domains.  However, the code would most likely work — creating all 10,000 users in the default “cn=users” container.

If you have any questions please let me know.

Create10kTestUsers

Posted in Scripting | Leave a comment

Verify network translation

Again, some earlier code.  I’m not sure how good this works…I had ran it for a few weeks awhile back.  However, my IP address changed and I received a lot of notifications before I had a chance to resolve it.  The script would be better if it contained some sort of logic so that it only sent one notification.

Monday, 08 October 2007

  • The purpose of this script is to:
  • lookup a domain name with nslookup, returning an IP address
  • find the external network address translation (NAT) using whatismyip.org
  • compare the two IP addresses
  • send a notification if they are not the same

This script was designed to run as a scheduled task and in my scenario it runs every 30 minutes.  The purpose is to work similiar to the www.no-ip.com service that will dynamically update DNS based on your external IP address.  Since I do not typically have a scripting interface into my hosted external DNS, I use a simple CDO email to let me know when DNS needs to be manually updated.


NatName = "publicnat.domainname.com"
NotifyContact = " scripting.user@domainname.com"
smtpserver = "smtp.domainname.com"

IP_in_DNS = DNSLookup(NatName)
IP_on_OutSide = ExternalIP()

If Not IP_in_DNS = IP_on_OutSide Then
SendEmail NotifyContact,NatName & " issue","The network address translation for " & NatName & " (IP_" & IP_in_DNS & ") does not match the current external address of IP_" & IP_on_OutSide & "."
End If

msgbox "Done."

Function DNSLookup(sDNSName)
On error resume next

Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1

Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
sTemp = oShell.ExpandEnvironmentStrings("%TEMP%")
sTempFile = sTemp & "\" & oFSO.GetTempName

oShell.Run "%comspec% /c nslookup " & sDNSName & ">" & sTempFile, 0, True

Set fFile = oFSO.OpenTextFile(sTempFile, ForReading, FailIfNotExist, OpenAsDefault)
sResults = fFile.ReadAll
fFile.Close
oFSO.DeleteFile (sTempFile)

If InStr(sResults, "Address:") Then
aNameTemp = Split(sResults, "Address:")
aName = Split(Trim(aNameTemp(2)), Chr(13))
'aNameTemp(2) will be the second address listed; the first address is that of the DNS Server

DNSLookup = aName(0)
Else
DNSLookup = "Failed."
End If

Set oShell = Nothing
Set oFSO = Nothing
End Function

Function ExternalIP()
url = "http://whatismyip.org"
set xmlhttp = CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.open "GET", url, false
xmlhttp.send ""
ExternalIP = xmlhttp.responseText
set xmlhttp = Nothing
End Function

Sub SendEmail(strTo, strSubject, strBody)
Set objEmail = CreateObject("CDO.Message")
objEmail.From = NotifyContact
objEmail.To = strTo
objEmail.Subject = strSubject
objEmail.HTMLBody = strBody
'objEmail.AddAttachment (txtOutFile)
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpserver
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objEmail.Configuration.Fields.Update
objEmail.Send
End Sub

Posted in Scripting | Leave a comment

DFS Replication Report Task

This is an earlier piece of code (says 1/21/2007).  I don’t do a lot with batch files anymore…however, it looks like this could still work and I thought I’d copy it here.

Purpose: Create Distributed File System (DFS) Replication Health Reports, post them to a web site and send an email notification when complete. This script was designed to run as a scheduled task.

Tested Windows Version(s): Windows 2003 R2
Script language: standard batch file


REM ================================================================================ REM ====================== DFS Replication Report Generation ======================
REM ================================================================================
REM Created by Brian Wuchner on 1/19/2007

SET ReplicationGroup=server1\web_replication\webdev
SET DestinationOutputPath=D:\Inetpub\wwwroot\webdev.domain.alias\ReplicationReport
SET DestinationWebOutput=http://webdev.domain.alias/ReplicationReport
SET SendSMTPnotification=yes

REM Optional settings for email notifcation
SET BlatSMTPmailPath="D:\SCRIPT\BLAT\blat.exe"
SET SMTP_Server_Address=smtp_server.com
SET SMTP_From_Address=scripter@domain.alias
SET SMTP_To_Address=scripter@domain.alias
@ECHO OFF
CLS

REM Use the for command to format date and time as YYYY-MM-DD HHMM
for /F "eol=; tokens=1,2,3,4* delims=/, " %%i in ('date /t') do SET YYYYMMDD=%%l-%%j-%%k
for /F "eol=; tokens=1,2,3* delims=:, " %%i in ('time /t') do SET HHMM=%%i%%j%%k

DFSRadmin health new /rgname:%ReplicationGroup% /repname:"%DestinationOutputPath%\%YYYYMMDD%_%HHMM%.html"

if %SendSMTPnotification%==yes %BlatSMTPmailPath% -server %SMTP_Server_Address% -f %SMTP_From_Address% -to %SMTP_To_Address% -subject "DFS Replication Report %YYYYMMDD%_%HHMM%" -body "The DFS Replication Report for replication group %ReplicationGroup% dated %YYYYMMDD%_%HHMM% has completed and is ready for review. You may access the report here: %DestinationWebOutput%/%YYYYMMDD%_%HHMM%.html. This report was sent from %computername% by %userdomain%\%username%."
exit

Posted in Scripting | Leave a comment

Add domain group to local group

This script was designed to be run by a domain administrator to grant other groups access to Administrators or Power Users on a local machine.  It reads in a list of computers from a text file and attempts to add the specified domain group to a specified local group.  An error log (success, fail, error message) will be written so that you know which workstations were correctly updated.

This is a useful script to grant a desktop support group access to a list of workstations without giving them domain administrator permissions.


On Error Resume Next

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oInFile = oFSO.OpenTextFile("computers.txt")
Set oLogFile = oFSO.OpenTextFile("Output.log",8,True)
StartTime = Now
ComputerCount = 0

While Not oInFile.AtEndOfStream
sComputerName = Trim(oInFile.ReadLine)
If Not sComputerName = "" Then
ComputerCount = ComputerCount + 1
sLGroup = "Administrators"
sGGroup = "Workstation Admins"
sDC = "testing.root.local"

Message = "Error adding Global to Local on " & sComputerName

Set oLGroup = GetObject("WinNT://" & sComputerName & "/" & sLGroup & ",group")
Set oGGroup = GetObject("WinNT://" & sDC & "/" & sGGroup & ",group")
ReturnCode = oLGroup.Add(oGGroup.ADsPath)

If Err.Number = "-2147023518" then
Message = sGGroup & " is already a member of " & sLGroup & " on " & sComputerName
ElseIf Err.Number = "0" Then
Message = oGGroup.Name & " is now in " & oLGroup.Name & " on computer " & sComputerName
End If

oLogFile.WriteLine (Message)
End If
Wend

MsgBox ComputerCount & " machines were processed in " & DateDiff("S", StartTime, Now) & " seconds."

WScript.Quit

Posted in Scripting | Leave a comment

New web site!

Good morning,

If you are reading this, you’ve obviously found my new blog.  I’ve created this site to discuss random topics in virtualization and systems administration.  Over the next couple of days I plan on consolidating a few failed attempts at creating such a site into this new structure.

If you have any comments or suggestions please feel free to post them.

Thanks,
Brian Wuchner

Posted in Uncategorized | Leave a comment