If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.
' Email variables:
strServer = "mailhost.abc.com"
strTo = "john.doe@abc.com"
strFrom = "john.doe@abc.com"
' Run USMT
Set objNetwork = CreateObject("WScript.Network")
Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
strUSMTLog = "\\server\share\USMT\USMTcapture_" & objNetwork.ComputerName & ".log"
strUSMTCmd = "cmd /c ""\\server\share\USMT\x86\scanstate.exe"" \\server\backupshare\" & objNetwork.ComputerName & " /v:5 /o /c /i:""\\server\share\USMT\x86\MigApp.xml"" /i:""\\server\share\USMT\x86\MigDocs.xml"" /l:""" & strUSMTLog & """"
objShell.Run strUSMTCmd, 1, True
' Read log file to get result
Set objLog = objFSO.OpenTextFile(strUSMTLog, 1, False)
arrContents = Split(objLog.ReadAll, vbCrLf)
objLog.Close
For intLine = UBound(arrContents) To 1 Step -1
If InStr(1, arrContents(intLine), "Activity: 'MIGACTIVITY", vbTextCompare) > 0 Then
strResult = arrContents(intLine) & vbCrLf & _
arrContents(intLine + 1) & vbCrLf & _
arrContents(intLine + 2) & vbCrLf
Exit For
End If
Next
strResult = arrContents(0) & vbCrLf & strResult
strBody = "The result of the USMT scan is:" & vbCrLf & strResult & vbCrLf & "The log file is located at " & strUSMTLog & vbCrLf
SendEmail strServer, strTo, strFrom, "USMT Log File from " & objNetwork.ComputerName & ": " & Now, strBody & strResult, ""
Sub SendEmail(strServer, strTo, strFrom, strSubject, strBody, strAttachment)
Dim objMessage
Set objMessage = CreateObject("CDO.Message")
objMessage.To = strTo
objMessage.From = strFrom
objMessage.Subject = strSubject
objMessage.TextBody = strBody
If strAttachment <> "" Then objMessage.AddAttachment strAttachment
'==This section provides the configuration information for the remote SMTP server.
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = strServer
'Server port (typically 25)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send
Set objMessage = Nothing
End Sub
strResult = arrContents(0) & vbCrLf & strResult
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Regards,
Rob.
Open in new window