Option Explicit '************************************************************************* 'Constants '************************************************************************* Const ForReading = 1 Const ForWriting = 2 Const ForAppending = 8 Const E_ADS_PROPERTY_NOT_FOUND = &h8000500D Const ADS_PROPERTY_CLEAR = 1 Const ADS_PROPERTY_DELETE = 4 '************************************************************************* 'Objects '************************************************************************* Dim FSO, wshShell Set FSO=CreateObject("Scripting.FileSystemObject") Set wshShell = WScript.CreateObject ("WSCript.shell") '************************************************************************* 'Variables '************************************************************************* Public Store(55) Public UseDebug Dim ThisComputer,LogDir,WorkdataFolder 'UseDebug is simply for displaying useful information on the console. Set to anything other than "Yes" to disable. UseDebug="Yes" ThisComputer=wshShell.ExpandEnvironmentStrings("%COMPUTERNAME%") LogDir="C:\autouser\log" WorkdataFolder = "\\usolpbws201\NewAcctFiles\" '************************************************************************* 'First, let's see if the script is already running... '************************************************************************* Dim objSWbemServices,colProcess,ProcessCount,objProcess Set objSWbemServices = GetObject ("WinMgmts:Root\Cimv2") Set colProcess = objSWbemServices.ExecQuery("Select * From Win32_Process") ProcessCount=0 For Each objProcess In colProcess If InStr (objProcess.CommandLine, "autouser.vbs") <> 0 Then ProcessCount=ProcessCount+1 End If Next If ProcessCount>1 Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Script already running, exiting gracefully." WScript.quit End If '************************************************************************* 'Set up logging '************************************************************************* Dim CurMonth,CurDay,LogFile,FullLogfilePath,Logging 'vbscript Date() function returns single digits <10, so pad a 0..... If Month(Date) < 10 Then CurMonth="0" & Month(Date) Else CurMonth=Month(Date) End If If Day(Date) < 10 Then CurDay="0" & Day(Date) Else CurDay=Day(Date) End If LogFile=Year(Date) & CurMonth & CurDay & ".txt" FullLogfilePath=LogDir & "\" & LogFile If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " FullLogFilePath: " & FullLogfilePath If Not FSO.FileExists(FullLogfilePath) Then Set Logging=FSO.CreateTextFile(FullLogfilePath, ForAppending) Logging.Close Set Logging=FSO.OpenTextFile(FullLogFilePath, ForAppending) Else Set Logging=FSO.OpenTextFile(FullLogFilePath, ForAppending) End If If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Set FSO objects (Exit here if no work to do)." '************************************************************************* 'Check for Workdata '************************************************************************* Dim Folder, Files, FolderIdx, WorkFile, FullWorkFilePath Set folder = fso.GetFolder(WorkDataFolder) Set files = folder.Files For Each folderIdx In files WorkFile=folderIdx.Name If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Calling main loop for " & WorkDataFolder & "\" & WorkFile Logging.WriteLine(Date & " " & Time & " Calling main loop for " & WorkDataFolder & "\" & WorkFile) FullWorkFilePath=WorkDataFolder & "\" & WorkFile Call WorkfileLoop(FullWorkFilePath) Next WScript.Quit Sub WorkFileLoop(FileToParse) '************************************************************************* 'This is the loop that will do the bulk of the actual work. It's big. It's bad. It's complicated. '************************************************************************* Dim OriginalFileName OriginalFileName=FileToParse If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Entering work loop: " & OriginalFileName Logging.WriteLine(Date & " " & Time & " Entering work loop: " & OriginalFileName) Set Workfile=FSO.OpenTextFile(FileToParse, ForReading) Do Until WorkFile.AtEndofstream Dim CurrentLine,Userdata,Phone,Expiry,TicketNumber,LastName,FirstName,MidInit CurrentLine=workfile.readline If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Parsing Text: " & CurrentLine userdata=split(CurrentLine,"~") '************************************************************************* 'Note: Some fields are allowed to be blank - Here are the 4 that could potentially be NULL '************************************************************************* If ubound(userdata)<>-1 And lcase(userdata(0))="middleinitial" Then MidInit=userdata(1) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Found Middle Initial: " & MidInit End if If ubound(userdata)<>-1 and lcase(userdata(0))="phone" then phone=userdata(1) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Found phone #: " & phone End If If ubound(userdata)<>-1 and lcase(userdata(0))="expiry" Then expiry=userdata(1) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Found expiration date: " & expiry End If '************************************************************************* 'Everything else is validated on the front end. If lcase(userdata(0))="ticket" Then TicketNumber=userdata(1) If lcase(userdata(0))="lastname" Then Lastname=userdata(1) If lcase(userdata(0))="firstname" Then '************************************************************************* 'Check to see if first name has additional identifying information, like "(Research)" for common names. 'This happens when there's >1 users (such as John Smith) already in the GAL, and the MAC requestor 'puts in identifying information in the first name so it looks like 'Smith, John (Research)' or 'similar in the GAL. This little routine looks at the 2nd array element and breaks it down into 'a subarray with the benefit of the Last/First fields being correct in AD but the Displayname and 'AD Container name still get the data in Parenths listed to differentiate one John Smith from the other. '************************************************************************* if instr(userdata(1),"(")>0 or InStr(userdata(1),")")>0 Then Dim FirstNameTemp,FirstNameArray,AdditionalInfo FirstNameTemp=Replace(userdata(1),"(","~") FirstNameTemp=Replace(FirstNameTemp,")","") FirstNameArray=Split(FirstNameTemp,"~") Firstname=FirstNameArray(0) AdditionalInfo=FirstNameArray(1) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Found additional FirstName info: " & AdditionalInfo Else FirstName=userdata(1) End If '************************************************************************* End If '************************************************************************* 'The remainder of the query is handled here: '************************************************************************* Dim Mail,StartDate,City,State,Zip,Address,Location,MgrLanID,Dept,HRApprover,Requestor,Blocktype If lcase(userdata(0))="mail" Then Mail=userdata(1) If lcase(userdata(0))="start" Then StartDate=userdata(1) If lcase(userdata(0))="city" Then City=userdata(1) If lcase(userdata(0))="state" Then State=ucase(userdata(1)) If lcase(userdata(0))="zip" Then Zip=userdata(1) If lcase(userdata(0))="address" Then Address=userdata(1) If lcase(userdata(0))="location" Then location=userdata(1) If lcase(userdata(0))="managerlanid" Then MgrLanID=userdata(1) If lcase(userdata(0))="department" Then Dept=userdata(1) If lcase(userdata(0))="hrapprover" Then HRapprover=userdata(1) If lcase(userdata(0))="requestor" Then Requestor=userdata(1) If LCase(userdata(0))="blocktype" Then Blocktype=userdata(1) if UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Ticket#: " & TicketNumber WScript.Echo Date & " " & Time & " Expiry: " & expiry WScript.Echo Date & " " & Time & " Lastname: " & Lastname WScript.Echo Date & " " & Time & " Firstname: " & firstname WScript.Echo Date & " " & Time & " Mail: " & mail WScript.Echo Date & " " & Time & " Start: " & StartDate WScript.Echo Date & " " & Time & " City: " & City WScript.Echo Date & " " & Time & " State: " & State WScript.Echo Date & " " & Time & " Zip: " & zip WScript.Echo Date & " " & Time & " Address: " & address WScript.Echo Date & " " & Time & " Location: " & location WScript.Echo Date & " " & Time & " ManagerLanID: " & MgrLanID WScript.Echo Date & " " & Time & " Department: " & Dept WScript.Echo Date & " " & Time & " HRApprover: " & HRapprover WScript.Echo Date & " " & Time & " Requestor: " & Requestor WScript.Echo Date & " " & Time & " Blocktype: " & BlockType End If 'Anything else returned by the stored procedure is superfluous Exit Do End If Loop '************************************************************************* 'Done with the workfile. Close it out. '************************************************************************* if UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Closing Workfle. We're done here." WorkFile.Close Logging.WriteLine(Date & " " & Time & " MAC " & TicketNumber & ": " & Lastname & ", " & Firstname & " " & MidInit) Logging.WriteLine(Date & " " & Time & " MAC " & "Approved By: " & hrapprover) if UseDebug="Yes" Then WScript.Echo Date & " " & Time & " MAC " & TicketNumber & ": " & Lastname & ", " & Firstname & " " & MidInit if UseDebug="Yes" Then WScript.Echo Date & " " & Time & " MAC " & "Approved By: " & hrapprover '************************************************************************* 'At this point, all variables should be set. We can now start creating additional variables. 'Start with the "Display Name" '************************************************************************* Dim DisplayName 'AdditionalInfo is what we used above for the "Smith, John (Research)" case. If MidInit="" and AdditionalInfo="" Then DisplayName=Lastname & ", " & FirstName If MidInit="" And AdditionalInfo<>"" Then DisplayName=Lastname & ", " & FirstName & " " & Chr(40) & AdditionalInfo & Chr(41) If MidInit<>"" And AdditionalInfo="" Then DisplayName=Lastname & ", " & FirstName & " " & Left(MidInit,1) If MidInit<>"" And AdditionalInfo<>"" Then DisplayName=Lastname & ", " & FirstName & " " & Left(MidInit,1) & " " & Chr(40) & AdditionalInfo & Chr(41) if UseDebug="Yes" Then WScript.Echo Date & " " & Time & " DisplayName: " & DisplayName Logging.WriteLine(Date & " " & Time & " DisplayName: " & DisplayName) '************************************************************************* 'Now we'll create a Lan ID '************************************************************************* Dim LanIdLast,LanIDFirst 'First, strip out common special characters, like Dashes, Spaces and Apostrophes after lowercasing it. LanIdLast=replace(Lastname," ","") LanIdLast=Replace(LanIdLast,"'","") LanIDLast=Replace(LanIdLast,"-","") LanIDFirst=replace(FirstName," ","") LanIDFirst=Replace(LanIDFirst,"'","") LanIDFirst=Replace(LanIDFirst,"-","") LanIdLast=LCase(LanIDLast) LanIDFirst=LCase(LanIDFirst) Dim LanID(10) LanID(0)=Left(LanIDFirst,1) & Left(LanIDLast,7) LanID(1)=Left(LanIDFirst,2) & Left(LanIDLast,6) LanID(2)=Left(LanIDLast,7) & Left(LanIDFirst,1) LanID(3)=Left(LanIDLast,6) & Left(LanIDFirst,2) LanID(4)=Left(LanIDFirst,1) & Left(LanIDLast,6) & 1 LanID(5)=Left(LanIDFirst,1) & Left(LanIDLast,6) & 2 LanID(6)=Left(LanIDFirst,1) & Left(LanIDLast,6) & 3 LanID(7)=Left(LanIDFirst,1) & Left(LanIDLast,6) & 4 LanID(8)=Left(LanIDFirst,1) & Left(LanIDLast,6) & 5 LanID(9)=Left(LanIDFirst,1) & Left(LanIDLast,6) & 6 Dim i,id2test,Container,FinalLanID For i=0 To 9 'Let's see if we find that ID in the directory... If FinalLanID="" then ID2Test=LanID(i) Container=RetrieveValue("sAMAccountName",ID2Test,"DistinguishedName") 'Look for "CN=", which will be part of the DN: If InStr(Container,"CN=")=0 Then if UseDebug="Yes" Then WScript.Echo Date & " " & Time & " LanID Set: " & id2test 'If No DN is returned, then guess what, we have a winner! FinalLanID=LanID(i) End If End If Next 'So did we get a winner? (Trust me, the problem isn't here, this routine has NEVER failed) If FinalLanID="" Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " **** FATAL: UNABLE TO SET LAN ID ****" Call Failmail("FATAL: Cannot assign a LanID",TicketNumber) Logging.WriteLine(Date & " " & Time & " ***CANNOT SET LanID: FATAL") if UseDebug="Yes" Then WScript.Echo Date & " " & Time & " **** FATAL: MOVING FILE TO ERROR REPOSITORY ****" Call MoveFile(OriginalFileName, "C:\autouser\workdata\error\") Exit Sub End If Logging.WriteLine(Date & " " & Time & " Generated LanID: " & FinalLanID) '************************************************************************* 'Let's get his Manager's DN '************************************************************************* Dim ManagerDN ManagerDN=RetrieveValue("sAMAccountName",MgrLanID,"distinguishedName") If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " MgrDN: " & ManagerDN Logging.WriteLine(Date & " " & Time & " MgrDN: " & ManagerDN) '************************************************************************* 'Find out what OU they're going into '************************************************************************* Dim tmpOU,TargetOU tmpOU=Split(ManagerDN,",") For i=2 To UBound(tmpOU) If TargetOU="" Then TargetOU=tmpOU(i) Else TargetOU=TargetOU & "," & tmpOU(i) End If Next '************************************************************************* 'If Manager is not already in the USA, then give him a generic OU '************************************************************************* If InStr(TargetOU,"United States")<0 Or TargetOU="" Then TargetOU="OU=Uncategorized Users,OU=United States,DC=oak,DC=fg,DC=RBC,DC=com" If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " !Manager appears to not be in the USA. Setting Generic OU." End If '************************************************************************* 'And create a DN out of it... '************************************************************************* Dim ContainerName,FullDN ContainerName=Replace(DisplayName,", ", "\, ") FullDN="CN=" & ContainerName & "," & TargetOU If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Full CN: " & FullDN Logging.WriteLine(Date & " " & Time & " UserDN: " & FullDN) Logging.WriteLine(Date & " " & Time & " TargetOU: " & TargetOU) 'Validate OLP/WFC since it's not being validated on the front end like it should be If InStr(location,"OLP")>0 Or InStr(location,"WFC")>0 Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " OLP or WFC found in Location String. Normalizing to State: NY" state="NY" Else location="" End If '************************************************************************* 'Check to see if DN exists... '************************************************************************* If UseDebug="Yes" Then WScript.echo Date & " " & Time & " Checking for duplicate DN..." Dim objUser,ContainerNameToCheck On Error Resume next Set objUser=GetObject("LDAP://" & FullDN) If Err.Number=0 Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " ****FATAL: Container Exists****" WScript.Echo Date & " " & Time & " ****FATAL: " & ContainerNameToCheck WScript.Echo Date & " " & Time & " ****FATAL: Sending failure email" WScript.Echo Date & " " & Time & " ****FATAL: Moving file to error repository" End If Call FailMail("FATAL: AD container already exists",TicketNumber) Call MoveFile(OriginalFileName, "C:\autouser\workdata\error\") Logging.WriteLine(Date & " " & Time & " ***FATAL ERROR: Container " & objUser.distinguishedname & " already exists.") Logging.Close Exit Sub End If If UseDebug="Yes" Then WScript.echo Date & " " & Time & " No duplicate DN found. Passed." On Error GoTo 0 '************************************************************************* 'Now, generate an email address. '************************************************************************* Dim EmailAddress,AddrExists,HomeMDB If Mail<>"Y" Then if UseDebug="Yes" Then WScript.Echo Date & " " & Time & " !NOT Mail Enabled." EmailAddress="" Else If MidInit="" Then EmailAddress=firstname & "." & lastname & "@rbccm.com" EmailAddress=Replace(EmailAddress," ","") EmailAddress=LCase(EmailAddress) Else EmailAddress=firstname & "." & lastname & "@rbccm.com" EmailAddress=Replace(EmailAddress," ","") EmailAddress=LCase(EmailAddress) 'Check to see if the first email address exists. AddrExists=FindEmailAddress(emailAddress) if UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Checking for Dupe: " & EmailAddress 'If it does, try the variant with the middle initial (last chance) If AddrExists="Y" Then if UseDebug="Yes" Then WScript.Echo Date & " " & Time & " !DUPLICATE Email Address: " & EmailAddress EmailAddress=FirstName & "." & MidInit & "." & LastName & "@rbccm.com" EmailAddress=LCase(EmailAddress) if UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting alternate: " & EmailAddress End If End If End If 'Last chance, let's see if the email address exists after all that. If Mail="Y" Then AddrExists=FindEmailAddress(emailAddress) If AddrExists="Y" Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " !DUPLICATE Email Address. Raising nonfatal error for " & EmailAddress 'Raise a NON-FATAL error if both combinations of email addresses exist. Creation can still continue. Call FailMail("NON-FATAL: Duplicate email address",TicketNumber) 'Set mail-enabled flag to no, since we can't find a valid email address for him. Intervention required. Mail="N" Logging.WriteLine(Date & " " & Time & " ***UNABLE TO SET EMAIL ADDRESS: " & EmailAddress) Logging.WriteLine(Date & " " & Time & " ***NON-FATAL, Sending error email and continuing.") End If End If Logging.WriteLine(Date & " " & Time & " MailEnabled: " & Mail) Logging.WriteLine(Date & " " & Time & " EmailAddress: " & EmailAddress) If Mail="N" Then HomeMDB="Not Mail Enabled" If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " HomeMDB: Not mail enabled." Else 'HomeMDB=GetBestMDB() 'Hardcoding until Mike Toomath says it's ok not to. When given the OK, delete the hardcoded mdb below, and unrem 'the function call above. HomeMDB="CN=Mailbox Store 4B (SXGM-501),CN=Fourth Storage Group,CN=InformationStore,CN=SXGM-501,CN=Servers,CN=CAN-TORONTO,CN=Administrative Groups,CN=GEMS,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=forest,DC=rbc,DC=com" If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " HomeMDB: " & HomeMDB Logging.WriteLine(Date & " " & Time & " HomeMDB: " & HomeMDB) End If '************************************************************************* 'Let's see what state they're in, to see if they get a Netapp Filer homedir. '************************************************************************* If instr(state,"JERSEY")>0 Then state="NJ" if InStr(State,"YORK")>0 Then state="NY" If state="NJ" Or state="NY" Or state="PA" Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " State is NJ, PA or NY. Netapp Eligible." 'Randomly pick a volume on the Netapp, since we can't effectively get free space with WMI... Dim RandomNumber,drvtouse,nasdir,homedir,profiledir Randomize RandomNumber=Int( ( 4 - 1 + 1 ) * Rnd + 1 ) If RandomNumber=1 Then drvtouse="u" nasdir="C:\VOL\nt5" End If If RandomNumber=2 Then drvtouse="w" nasdir="C:\VOL\nt3" End If If RandomNumber=3 Then drvtouse="x" nasdir="C:\VOL\nt2" End if If RandomNumber=4 Then drvtouse="y" nasdir="C:\VOL\nt1" End If If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Drv: " & drvtouse WScript.Echo Date & " " & Time & " Nas: " & nasdir End If HomeDir="\\NTDISK01\" & FinalLanID ProfileDir="\\NTDISK01\" & FinalLanID & "\profile" Else HomeDir="" ProfileDir="" End If If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Homedir: " & homedir WScript.Echo Date & " " & Time & " Profiledir: " & ProfileDir End If '************************************************************************* 'Split up the location field so we can normalize the address... '************************************************************************* 'Validate first. 'If leftmost is OLP or WFC, that's good... If Left(location,3)="OLP" Or Left(location,3)="WFC" Then 'But if the spaces aren't in the right places, null it out, They didn't put it in the right format. If Mid(location,4,1)<>" " Or Mid(location,7,1)<>" " Then call FailMail("NON-FATAL: Invalid or partial location field: " & location,TicketNumber) location="" End If End If If Len(Location)<>11 Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Location blank or in incorrect format. Ignoring." Logging.WriteLine(Date & " " & Time & " Location empty or in incorrect format. Ignoring.") location="" End If if location<>"" Then Dim tmpLoc,Building,Floor,Cubeloc tmpLoc=Split(location," ") If IsArray(tmpLoc)=True Then If InStr(tmpLoc(0),"WFC")>0 Or InStr(tmpLoc(0),"OLP")>0 Then if not uBound(tmpLoc)=0 Then building=tmpLoc(0) floor=tmpLoc(1) cubeloc=tmpLoc(2) state="NY" End If Else Floor="X" End If End If End If If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Normalized Building: " & Building WScript.Echo Date & " " & Time & " Normalized Floor: " & Floor WScript.Echo Date & " " & Time & " Normalized Cubeloc: " & Cubeloc WScript.Echo Date & " " & Time & " Normalized State: " & State End If If Floor="0M" Then Floor="Mezzanine" fSuffix="" Else If IsNumeric(Floor)=True And floor>0 And IsArray(tmpLoc)=True Then Dim fSuffix If Left(floor,1)=0 Then floor=Right(floor,1) If Right(floor,1)=4 Then fSuffix="th" If Right(floor,1)=5 Then fSuffix="th" If Right(floor,1)=6 Then fSuffix="th" If Right(floor,1)=7 Then fSuffix="th" If Right(floor,1)=8 Then fSuffix="th" If Right(floor,1)=9 Then fSuffix="th" If Right(floor,1)=0 Then fSuffix="th" If Right(floor,1)=1 Then fSuffix="st" If Right(floor,1)=2 Then fSuffix="nd" If Right(floor,1)=3 Then fSuffix="rd" If floor > 3 And floor < 21 Then fSuffix="th" End If End If If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Normalized Floor: " & Floor & fSuffix 'Normalize address for 3WFC and OLP If Building="OLP" Then Address="One Liberty Plaza - 165 Broadway - " & floor & fsuffix & " Flr" City="New York" State="NY" Zip="10006-1446" Logging.WriteLine(Date & " " & Time & " Address (Normalized): " & Address) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Normalized Address: " & Address WScript.Echo Date & " " & Time & " Normalized City: " & City WScript.Echo Date & " " & Time & " Normalized Zip: " & Zip End If End If If Building="WFC" Then Address="3 World Financial Center - 200 Vesey St. - " & floor & fSuffix & " Flr" City="New York" State="NY" Zip="10281-8098" If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Normalized Address: " & Address WScript.Echo Date & " " & Time & " Normalized City: " & City WScript.Echo Date & " " & Time & " Normalized Zip: " & Zip End If Logging.WriteLine(Date & " " & Time & " Address (Normalized): " & Address) End If If Building<>"WFC" or Building<>"OLP" Then Logging.WriteLine(Date & " " & Time & " Address (Non-Normalized): " & Address) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Non-Normalized Address: " & Address End If '************************************************************************* 'A little more logging... '************************************************************************* Logging.WriteLine(Date & " " & Time & " BlockType: " & BlockType) Logging.WriteLine(Date & " " & Time & " City: " & City) Logging.WriteLine(Date & " " & Time & " State: " & State) Logging.WriteLine(Date & " " & Time & " Zip: " & Zip) Logging.WriteLine(Date & " " & Time & " Expiry: " & expiry) Logging.WriteLine(Date & " " & Time & " Loc: " & Location) Logging.WriteLine(Date & " " & Time & " Homedir: " & homedir) Logging.WriteLine(Date & " " & Time & " ProfDir: " & ProfileDir) Logging.WriteLine(Date & " " & Time & " LitPath: " & nasdir & " (drive " & ucase(drvtouse) & "$)") '************************************************************************* 'Create the user in AD '************************************************************************* Logging.WriteLine(Date & " " & Time & " Invoking User Creation routine...") If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Invoking Creation Routine..." Call CreateUser(TargetOU,ContainerName,FinalLanID) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Finished Creating User." 'Now set his AD properties. '************************************************************************* 'Set Home directory, ProfilePath, HomeDrive (which is always F:) in AD '************************************************************************* If HomeDir<>"" Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property homeDirectory: " & HomeDir Logging.WriteLine(Date & " " & Time & " Setting AD Property: homeDirectory (" & HomeDir & ")") Call ApplyLDAPProperty(FullDN,"homeDirectory",HomeDir) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property profilepath: " & profiledir Logging.WriteLine(Date & " " & Time & " Setting AD Property: profilePath (" & profiledir & ")") Call ApplyLDAPProperty(FullDN,"profilePath",Profiledir) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property homeDrive: F:" Logging.WriteLine(Date & " " & Time & " Setting AD Property: homeDrive (F:)") Call ApplyLDAPProperty(FullDN,"homeDrive","F:") End If '************************************************************************* 'Set phone number, which is almost always null... Apply to AD '************************************************************************* If Phone<>"" Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property telephoneNumber: " & Phone Logging.WriteLine(Date & " " & Time & " Setting AD Property: telephoneNumber (" & Phone & ")") Call ApplyLDAPProperty(FullDN,"telephoneNumber",Phone) End If '************************************************************************* 'Set primary email address in AD '************************************************************************* If Mail="Y" Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property mail: " & emailAddress Logging.WriteLine(Date & " " & Time & " Setting AD Property: mail (" & emailaddress & ")") Call ApplyLDAPProperty(FullDN,"mail",EmailAddress) End If '************************************************************************* 'Set expiration date if given, in AD '************************************************************************* If Expiry<>"" Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property accountExpirationDate: " & expiry Logging.WriteLine(Date & " " & Time & " Setting AD Property: AccountExpirationDate (" & Expiry & ")") Call SetExpirationDate(FullDN,Expiry) End If '************************************************************************* 'Set cubicle location, if given, in AD '************************************************************************* If Location<>"" Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property PhysicalDeliveryOfficename: " & location Logging.WriteLine(Date & " " & Time & " Setting AD Property: physicalDeliveryOfficeName (" & location & ")") Call ApplyLDAPProperty(FullDN,"physicalDeliveryOfficeName",Location) End If '************************************************************************* 'Set department info in AD '************************************************************************* If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property department: " & dept Logging.WriteLine(Date & " " & Time & " Setting AD Property: department (" & dept & ")") Call ApplyLDAPProperty(FullDN,"department",Dept) '************************************************************************* 'Set their ManagerDN in AD '************************************************************************* If ManagerDN<>"" Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property Manager: " & ManagerDN Logging.WriteLine(Date & " " & Time & " Setting AD Property: manager (" & ManagerDN & ")") Call ApplyLDAPProperty(FullDN,"manager",ManagerDN) End If '************************************************************************* 'Set DisplayName in AD '************************************************************************* If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property displayName: " & DisplayName Logging.WriteLine(Date & " " & Time & " Setting AD Property: displayName (" & DisplayName & ")") Call ApplyLDAPProperty(FullDN,"displayName",DisplayName) '************************************************************************* 'Set Firstname in AD '************************************************************************* If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property givenName: " & FirstName Logging.WriteLine(Date & " " & Time & " Setting AD Property: givenName (" & Firstname & ")") Call ApplyLDAPProperty(FullDN,"givenName",Firstname) '************************************************************************* 'Set LastName in AD '************************************************************************* If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property sn: " & Lastname Logging.WriteLine(Date & " " & Time & " Setting AD Property: sn (" & Lastname & ")") Call ApplyLDAPProperty(FullDN,"sn",Lastname) '************************************************************************* 'Set City in AD '************************************************************************* If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property l: " & City Logging.WriteLine(Date & " " & Time & " Setting AD Property: l (" & City & ")") Call ApplyLDAPProperty(FullDN,"l",City) '************************************************************************* 'Set Address in AD '************************************************************************* If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property postalAddress: " & Address Logging.WriteLine(Date & " " & Time & " Setting AD Property: postalAddress (" & Address & ")") Call ApplyLDAPProperty(FullDN,"postalAddress",Address) '************************************************************************* 'Set State in AD '************************************************************************* If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property st: " & State Logging.WriteLine(Date & " " & Time & " Setting AD Property: st (" & state & ")") Call ApplyLDAPProperty(FullDN,"st",state) '************************************************************************* 'Set PostalCode in AD '************************************************************************* If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property postalCode: " & ZIP Logging.WriteLine(Date & " " & Time & " Setting AD Property: postalCode (" & ZIP & ")") Call ApplyLDAPProperty(FullDN,"postalCode",ZIP) '************************************************************************* 'Set Country field in AD '************************************************************************* If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property co: United States" Logging.WriteLine(Date & " " & Time & " Setting AD Property: co (United States)") Call ApplyLDAPProperty(FullDN,"co","United States") '************************************************************************* 'Set Redundant Street Address in AD '************************************************************************* If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property streetAddress: " & Address Logging.WriteLine(Date & " " & Time & " Setting AD Property: streetAddress (" & Address & ")") Call ApplyLDAPProperty(FullDN,"streetAddress",Address) '************************************************************************* 'Set LoginScript in AD (Static) '************************************************************************* If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property scriptpath: newlogin.vbs" Logging.WriteLine(Date & " " & Time & " Setting AD Property: scriptPath (newlogin.vbs)") Call ApplyLDAPProperty(FullDN,"scriptpath","newlogin.vbs") '************************************************************************* 'Set UPN in AD '************************************************************************* If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Setting AD Property userPrincipalName: " & finalLanId & "@oak.fg.rbc.com)" Logging.WriteLine(Date & " " & Time & " Setting AD Property: userPrincipalName (" & finalLanId & "@oak.fg.rbc.com)") Call ApplyLDAPProperty(FullDN,"userPrincipalName",FinalLanID & "@oak.fg.rbc.com") '************************************************************************* 'We are now done setting all the properties for this user. Let's create their mailbox. '************************************************************************* If Mail="Y" Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Entering Mailbox Creation." Logging.WriteLine(Date & " " & Time & " Calling Mailbox Creation Routine.") Call CreateMailbox(FullDN,HomeMDB) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Successfully Created Mailbox." 'Then create the @rbccm address, since the default is @rbc...This happens when the default mail policy comes down. If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Waiting for application of default mail policy." 'This is a subroutine that simply waits for the default mail policy to come down - that allows us to set 'the default email address to the @rbccm.com email address. 'If you don't do this, the @rbc.com email address will be primary, which is not optimal. Call WaitForDefaultMailPolicy(FullDN) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Applied. Setting default email address: " & emailAddress Logging.WriteLine(Date & " " & Time & " Setting default SMTP address to: " & emailAddress) Call ChangeDefaultEmail(FullDN,EmailAddress) End If '************************************************************************* 'Should their home directory be on the NY Netapp? '************************************************************************* If HomeDir<>"" Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Creating Path \\NTDISK01\" & drvtouse & "$\users\" & FinalLanID Call CreateDirectory("\\NTDISK01\" & drvtouse & "$\users\" & FinalLanID,FinalLanID,TicketNumber) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Creating Share \\NTDISK01\" & FinalLanID Call CreateShare("\\NTDISK01\" & FinalLanID,NasDir & "\users\" & FinalLanID,FinalLanID,TicketNumber) Else 'if they aren't, send an email. 'recipientList=chr(34) & "karl.weckstrom@rbccm.com" & chr(34) recipientList=chr(34) & "dsusapcserver@rbccm.com" & chr(34) & ";" & chr(34) & "+CM-USARemoteIS@rbccm.com" & chr(34) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " !User not eligible for NETAPP4. Sending email to Remote Support." Call HomeDirReq(FullDN,recipientlist,TicketNumber) End If 'Are they flagged to be in the IB blocklist? If BlockType="Investment Banking" Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " !IB Block List member." Call Blocklist(FullDN,"IB") End If 'Are they flagged to be in the ER blocklist? If Blocktype="Equity Research" Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " !ER Block List member." Call BlockList(FullDN,"ER") End If '************************************************************************* 'Before sending final approval, might as well let the hiring manager know - fetch his email address '************************************************************************* Dim mgrEmail If ManagerDN<>"" then Set objUser=GetObject("LDAP://" & ManagerDN) mgrEmail=objUser.mail If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Fetched Hiring Mgr's Email: " & mgrEmail End If '************************************************************************* 'Get the requestor's email address too... '************************************************************************* Dim ReqEmail ReqEmail=RetrieveValue("sAMAccountName",Requestor,"mail") If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Fetched MacRequestors Email: " & ReqEmail Logging.WriteLine(Date & " " & Time & " Sending final email for request " & TicketNumber) If mgrEmail="" Then mgrEmail=ReqEmail If HomeDir="" Then If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Sending Notification Email (NON-NETAPP4)." Call SendFinalEmail(FinalLanID,"none",TicketNumber,EmailAddress,Phone,mgrEmail,ReqEmail) Else If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Sending Notification Email (NETAPP4)." Call SendFinalEmail(FinalLanID,"\\NTDISK01\" & FinalLanID,TicketNumber,EmailAddress,Phone,mgrEmail,ReqEmail) End If 'Put the file away. If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Moving file to Completed directory." Call MoveFile(OriginalFileName, "C:\autouser\workdata\completed\") WScript.quit End Sub '******************************************************************************************************************************* '******************************************************************************************************************************* '******************************************************************************************************************************* '******************************************************************************************************************************* '******************************************************************************************************************************* '*********************************All Subroutines and Functions beyond this point*********************************************** '******************************************************************************************************************************* '******************************************************************************************************************************* '******************************************************************************************************************************* '******************************************************************************************************************************* '******************************************************************************************************************************* Sub SendFinalEmail(samid,homedir,ticket,useremail,userphone,manageremail,requestoremail) 'Generate final email. Dim DN,MailString,RecipientList,strBody,objUser,DisplayName,HomeDirString,RetryLoop Dim objMessage Set objMessage = CreateObject("CDO.Message") DN=RetrieveValue("sAMAccountName",samid,"distinguishedName") Set objUser=GetObject("LDAP://" & DN) 'Get firstname (givenname) and lastname (sn, aka surname) DisplayName=objUser.GivenName & " " & objUser.sn If len(userPhone)=0 Then userPhone="None Provided" if instr(useremail,"@")<1 then MailString="Email: Not mail enabled." Else MailString="Email: " & useremail end If if instr(Homedir,"\")<1 Then HomeDirString="Note: As this user is located outside of NY, a separate email has been dispatched to the Branch Support team for home drive creation." Else HomeDirString="Home Directory: " & HOMEDIR end If 'RecipientList=chr(34) & "karl.weckstrom@rbccm.com" & chr(34) RecipientList=chr(34) & requestoremail & chr(34) & ";" & chr(34) & "orderdesk.usa@rbccm.com" & chr(34) & ";" & chr(34) & "dsusapcserver@rbccm.com" & chr(34) & ";" & chr(34) & "CM-USA-NewHireNotification@rbc.com" & chr(34) objMessage.Subject = "New user: " & DisplayName & " (" & TICKET & ")" objMessage.From = "orderdesk.usa@rbccm.com" objMessage.To = RecipientList strBody = "As per your request a Windows account has been created for " & DisplayName & ":" & vbcrlf &_ vbTab & "LAN ID: " & samid & vbcrlf & vbtab & "Temporary Password: weLcome!" & vbcrlf & vbtab & "Email: " & userEmail & vbcrlf &_ vbtab & HomeDirString strbody=strbody & VbCrLf & vbtab & "Phone Number: " & UserPhone & VBCRLF & VBCRLF & "*Note: The user is required to change their password at first logon." &_ vbcrlf & "All NT passwords must always be at least 6 characters long, in a combination of at least 3 different character types (lowercase, uppercase, number, or symbol)." & vbcrlf & VBCRLF & _ "The helpdesk should be contacted in an event of any problems at 212-858-7474." & VBCRLF & VBCRLF & _ "Thanks." & VBCRLF & "RBCCM Order Desk - USA" objMessage.TextBody = strBody objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailer.rbc.com" objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objMessage.Configuration.Fields.Update For RetryLoop=0 To 5 On Error Resume Next objMessage.Send If Err.Number=0 Then Exit For If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Error sending final email (" & Err.Number & "). Waiting 10 Seconds." WScript.Sleep 10000 Next End Sub Sub ChangeDefaultEmail(DN,Addr) Dim UsrDN,EmailAddr,sAddress,oUser,objRecip,bIsFound,vProxyAddresses,nProxyAddresses,email 'Add RBCCM address and make it primary. UsrDN="LDAP://" & DN EmailAddr=Addr sAddress = "SMTP:" & EmailAddr Set oUser = GetObject (UsrDN) Set objRecip = oUser On Error Resume Next bIsFound = False vProxyAddresses = objRecip.ProxyAddresses nProxyAddresses = UBound(vProxyAddresses) i = 0 Do While i <= nProxyAddresses email = vProxyAddresses(i) If Left (email,5) = "SMTP:" Then vProxyAddresses (i) = "smtp:" & Mid (email,6) End If If vProxyAddresses(i) = sAddress Then bIsFound = True Exit Do End If i = i + 1 Loop If Not bIsFound Then ReDim Preserve vProxyAddresses(nProxyAddresses + 1) vProxyAddresses(nProxyAddresses + 1) = sAddress objRecip.ProxyAddresses = vProxyAddresses oUser.SetInfo oUser.mail=EmailAddr ouser.SetInfo End If End Sub Sub HomeDirReq(DN,recip,Ticket) Dim strBody,objMessage Set objUser=GetObject("LDAP://" & DN) objMessage.Subject = "HOME DIRECTORY REQUEST: " & objUser.DisplayName & " (" & TICKET & ")" objMessage.From = "dsusapcserver@rbccm.com" objMessage.To = Recip strBody = "A user account has been created for the following new hire: " & objuser.DisplayName & "." & VBCRLF & VBCRLF & "Because this user will not have a share on a New York netapp, their share must be manually created on their local File/Print server. Here are the details of this request:" & VBCRLF & VBCRLF strbody = strBody & "MAC: " & Ticket & VbCrLf strbody = strBody & "Lastname: " & objUser.sn & VbCrLf strbody = strbody & "Firstname: " & objUser.GivenName & VbCrLf strbody = strbody & "DisplayName: " & objUser.DisplayName & VbCrLf strBody = strbody & "Phone: " & objUser.telephoneNumber & VbCrLf strbody = strbody & "Address: " & objUser.postalAddress & VbCrLf strbody = strbody & "City: " & objUser.l & VbCrLf strbody = strbody & "State: " & objUser.st & VbCrLf strbody = strbody & "Zip: " & objUser.PostalCode & VbCrLf strbody = strbody & "Email: " & objUser.Mail & VbCrLf strbody = strbody & "Department: " & objUser.Department & VbCrLf strbody = strbody & "LanID: " & objUser.sAMAccountName & vbcrlf & vbcrlf objMessage.TextBody = strBody objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailer.rbc.com" objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objMessage.Configuration.Fields.Update objMessage.Send Set objMessage=Nothing end Sub Sub CreateDirectory(Directory,Samid,Ticket) Dim NTFSPermSet,objExec,ReadSTDOut If FSO.FolderExists(Directory) Then Call FailMail("NON-FATAL: Directory " & Directory & " Already Exists",Ticket) Logging.WriteLine(Date & " " & Time & " ***UNABLE TO CREATE HOME DIR: " & Directory) Logging.WriteLine(Date & " " & Time & " ***NON-FATAL, Sending error email and continuing.") Else FSO.CreateFolder(directory) Logging.WriteLine(Date & " " & Time & " Created home dir: " & Directory) NTFSPermSet="Failed" Set objExec=wshShell.Exec("cacls " & Directory & " /e /g " & samid & ":C") Do While objExec.StdOut.AtEndOfStream <> True ReadSTDOUT=objExec.StdOut.ReadLine 'Successful processing always nets the stdout string of 'processed dir: dirname' If InStr(ReadSTDOUT,"processed")>0 Then NTFSPermSet="Succeeded" Logging.WriteLine(Date & " " & Time & " Successfully permissioned NTFS directory " & Directory) End If Loop If NTFSPermSet="Failed" Then Logging.WriteLine(Date & " " & Time & " ***ERROR PERMISSIONING NTFS DIRECTORY: " & Directory) Call FailMail("NON-FATAL: CACLS.EXE reports an error permissioning directory" & Directory,Ticket) End If End If 'Yes, yes, I know, this part is pasta, but I'm doing it anyway for the profile directory since it's easier 'to troubleshoot if something goes heinously wrong. If FSO.FolderExists(Directory & "\profile") Then Call FailMail("NON-FATAL: Directory " & Directory & "\profile already exists",Ticket) Logging.WriteLine(Date & " " & Time & " ***UNABLE TO CREATE PROFILE DIR: " & Directory & "\profile") Logging.WriteLine(Date & " " & Time & " ***NON-FATAL, Sending error email and continuing.") Else FSO.CreateFolder(directory & "\profile") Logging.WriteLine(Date & " " & Time & " Created profile dir: " & Directory & "\profile") NTFSPermSet="Failed" Set objExec=wshShell.Exec("cacls " & Directory & "\profile /e /g " & samid & ":F") Do While objExec.StdOut.AtEndOfStream <> True ReadSTDOUT=objExec.StdOut.ReadLine 'Successful processing always nets the stdout string of 'processed dir: dirname' If InStr(ReadSTDOUT,"processed")>0 Then NTFSPermSet="Succeeded" Logging.WriteLine(Date & " " & Time & " Successfully permissioned NTFS directory " & Directory & "\profile") End If Loop If NTFSPermSet="Failed" Then Logging.WriteLine(Date & " " & Time & " ***ERROR PERMISSIONING NTFS DIRECTORY: " & Directory & "\profile") Call FailMail("NON-FATAL: CACLS.EXE error permissioning directory" & Directory & "\profile",Ticket) End If End If Set objexec=Nothing End Sub Sub CreateShare(Sharename,LiteralPath,sAMID,Ticket) Dim CreateShareStatus,objExec,ReadStdOut If FSO.FolderExists(Sharename) Then Call FailMail("NON-FATAL: Share " & ShareName & " Already Exists",Ticket) Logging.WriteLine(Date & " " & Time & " ***UNABLE TO CREATE SHARE: " & ShareName) Logging.WriteLine(Date & " " & Time & " ***NON-FATAL, Sending error email and continuing.") Else CreateShareStatus="Passed" Set objExec=wshShell.Exec("rmtshare " & Sharename & "=" & LiteralPath & " /GRANT " & sAMID & ":F /remove Everyone /Unlimited") Do While objExec.StdOut.AtEndOfStream <> True ReadSTDOUT=objExec.StdOut.ReadLine If InStr(CreateShareStatus,"failed:")>0 Then CreateShareStatus="Failed" Call FailMail("NON-FATAL: Share " & ShareName & " cannot be created",Ticket) Logging.WriteLine(Date & " " & Time & " ***UNABLE TO CREATE SHARE: " & ShareName) Logging.WriteLine(Date & " " & Time & " ***NON-FATAL, Sending error email and continuing.") End If Loop If CreateShareStatus="Passed" Then 'Logging Logging.WriteLine(Date & " " & Time & " Successfully created share: " & Sharename) Else Logging.WriteLine(Date & " " & Time & " ***SHARE CREATION FAILED: " & Sharename) Call FailMail("NON-FATAL: Share " & ShareName & " could not be created",Ticket) End If End If Set objExec=Nothing End Sub Sub WaitForDefaultMailPolicy(DN) Dim PassedDN,objRecip,objUser,x PassedDN=DN 'This is a wait routine to make sure the Email Addresses fields are populated. Set objUser = GetObject("LDAP://" & DN) Set objRecip = objUser If vartype(objRecip.ProxyAddresses)<>8204 then 'wscript.echo vbtab & "Waiting for mailbox creation to complete (" & x & ")" Logging.WriteLine(Date & " " & Time & " Waiting 10 seconds for application of default Exchange mail policy") wscript.sleep(9999) x=x+1 If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Still waiting for DMP (" & x & ")" call WaitForDefaultMailPolicy(PassedDN) end if end sub Sub CreateUser(OU,UserCN,sAMID) Dim objRoot,objOU,objUser If OU="" Then OU="OU=Uncategorized Users,OU=United States,DC=oak,DC=fg,DC=RBC,DC=com" Set objRoot = GetObject("LDAP://rootDSE") Set objOU=GetObject("LDAP://" & OU) Set objUser = objOU.Create("User", "CN=" & UserCN) ObjUser.sAMAccountName=sAMID Logging.WriteLine(Date & " " & Time & " Creating container: " & UserCN) objUser.SetInfo 'And enable it... objUser.userAccountControl = 512 objUser.pwdLastSet = 0 objUser.SetPassword "weLcome!" objUser.AccountDisabled = False Logging.WriteLine(Date & " " & Time & " Enabling account: " & sAMID) objUser.SetInfo End Sub Sub CreateMailbox(UserDN,Mdb) Dim ObjUser Set ObjUser = GetObject("LDAP://" & UserDN) ObjUser.CreateMailbox "LDAP://" & Mdb ObjUser.SetInfo objuser.submissionContlength=25600 objUser.SetInfo End Sub Sub ApplyLDAPProperty(userCN,Property,Value) Dim objUser 'WScript.Echo "Applying " & Property & ", " & Value & " to " & UserCN Set objUser=GetObject("LDAP://" & UserCN) objuser.put Property, Value objUser.Setinfo End Sub Sub FailMail(ErrorMessage,Ticket) Dim objMessage Set objMessage = CreateObject("CDO.Message") objMessage.Subject = "(Ticket: " & Ticket & ") " & ErrorMessage objMessage.From = "dsusapcserver@rbccm.com" objMessage.To = "dsusapcserver@rbccm.com" 'objMessage.To = "karl.weckstrom@rbccm.com" objMessage.TextBody = "An error occurred when trying to process the data in MAC request #" & Ticket & ". The error encountered was: " & VbCrLf & VbCrLf & ErrorMessage & VbCrLf & VbCrLf If Not InStr(ErrorMessage,"NON-FATAL")>0 Then objMessage.TextBody=objMessage.TextBody & "The datafile has been moved to \\" & ThisComputer & "\C$\AUTOUSER\WORKDATA\ERROR and will not be processed further without intervention." objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailer.rbc.com" objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objMessage.Configuration.Fields.Update objMessage.Send End Sub Function FindEmailAddress(PassedEmail) Dim oCont,oGC,strADsPath,oConnection,oRecordset,strQuery 'This sub checks for an email address to see if it's in use. Set oCont = GetObject("GC:") For Each oGC In oCont strADsPath = oGC.ADsPath Next Set oConnection = CreateObject("ADODB.Connection") Set oRecordset = CreateObject("ADODB.Recordset") oConnection.Provider = "ADsDSOObject" oConnection.Open "ADs Provider" strQuery = "<" & strADsPath & ">;(&(objectClass=user)(objectCategory=person)(mail=" & PassedEmail & "));mail,cn,distinguishedName;subtree" If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Executing query: " & strQuery Set oRecordset = oConnection.Execute(strQuery) If oRecordset.EOF And oRecordset.BOF Then FindEmailAddress="N" Else While Not oRecordset.EOF FindEmailAddress="Y" oRecordset.MoveNext Wend End If Set oCont = Nothing Set oGC = Nothing Set oRecordset = Nothing Set oConnection = Nothing End Function Sub MoveFile(sSource,sDestination) Dim FSO,objFileCopy,RandomNumber,sFileName,sPathCtr,Filetocopy,spath,sTargetPath,NewtargetPath Dim aFiletmp Set FSO=CreateObject("Scripting.FileSystemObject") Filetocopy=replace(sSource,"\\","\") aFiletmp=Split(Filetocopy,"\") sFileName=aFiletmp(uBound(aFileTmp)) For sPathctr=0 To Ubound(aFileTmp)-1 If sPathctr=0 Then sPath=aFileTmp(sPathCtr) Else spath=spath & "\" & aFileTmp(sPathCtr) End If Next sTargetPath=sDestination & "\" & sFileName sTargetPath=Replace(sTargetPath,"\\","\") If FSO.FileExists(sTargetPath) Then Randomize RandomNumber=Rnd RandomNumber=Replace(RandomNumber,".","") NewTargetPath=sDestination & sFileName NewtargetPath=Replace(NewtargetPath,"\\","\") NewtargetPath=Replace(NewtargetPath,".",".dupe" & RandomNumber & ".") FSO.MoveFile sTargetPath,NewtargetPath FSO.Movefile sSource,sDestination Else FSO.Movefile sSource,sDestination End If End Sub Function RetrieveValue(DataType,Data,ObjName) 'This is my HomeGrown Generic AD Cherrypicker. If you do any scripting at all with AD, you will find this VERY valuable. Dim oRootDSE,oConnection,oCommand,oRecordSet Set oRootDSE = GetObject("LDAP://rootDSE") Set oConnection = CreateObject("ADODB.Connection") oConnection.Open "Provider=ADsDSOObject;" Set oCommand = CreateObject("ADODB.Command") oCommand.ActiveConnection = oConnection If DataType="EmployeeID" then oCommand.CommandText = ";(&(objectCategory=User)(" & DataType & "=" & Data & "*));" & objName & ";subtree" Else oCommand.CommandText = ";(&(objectCategory=User)(" & DataType & "=" & Data & "));" & objName & ";subtree" End If 'WScript.Echo oCommand.CommandText Set oRecordSet = oCommand.Execute on error resume Next 'WScript.Echo oRecordSet.Fields(objName) RetrieveValue = oRecordSet.Fields(objName) Set oRecordSet = Nothing Set oCommand = Nothing Set oConnection = Nothing Set oRootDSE = Nothing End function Sub BlockList(DN,bType) 'Add user to proper block group... Dim BlockDN,objGroup,objUser Set objUser = GetObject("LDAP://" & DN) If bType="IB" Then Logging.WriteLine(Date & " " & Time & " Adding user to IB Block List.") Logging.WriteLine(Date & " " & Time & " Blocking ability to send to Analysts.") 'If they're in one group, they get blocked from the other.... bType="CN=\+CM-CMP-USA-IBBlock,OU=Compliance,OU=Special,OU=Mail Groups,OU=Exchange 2000,DC=oak,DC=fg,DC=rbc,DC=com" BlockDN="CN=\+CM-CMP-USA-AnalystsBlock,OU=Compliance,OU=Special,OU=Mail Groups,OU=Exchange 2000,DC=oak,DC=fg,DC=rbc,DC=com" End If If bType="ER" Then Logging.WriteLine(Date & " " & Time & " Adding user to Analyst Block List.") Logging.WriteLine(Date & " " & Time & " Blocking ability to send to Investment Banking.") bType="CN=\+CM-CMP-USA-AnalystsBlock,OU=Compliance,OU=Special,OU=Mail Groups,OU=Exchange 2000,DC=oak,DC=fg,DC=rbc,DC=com" BlockDN="CN=\+CM-CMP-USA-IBBlock,OU=Compliance,OU=Special,OU=Mail Groups,OU=Exchange 2000,DC=oak,DC=fg,DC=rbc,DC=com" End If 'Add them to the group... Set objGroup = GetObject("LDAP://" & bType) objGroup.Add(objUser.ADsPath) 'Then restrict them from sending to members of the other group. objUser.dlMemRejectPerms=BlockDN objUser.SetInfo End Sub Sub SetExpirationDate(userCN,passedDate) Dim objUser Set objUser=GetObject("LDAP://" & UserCN) objuser.AccountExpirationDate=DateAdd("d",1,PassedDate) objUser.Setinfo End Sub Function GetBestMDB() Dim SXGM501,SXGM502,SXGM503,SXGM601,SXGM602,SXGM603,NumberToTest,CurrentWinner,LowestCount,x,i 'Initialize the array For x=1 To 55 store(x)=0 Next SXGM501=CountMailboxes("SXGM-501") SXGM502=CountMailboxes("SXGM-502") SXGM503=CountMailboxes("SXGM-503") SXGM601=CountMailboxes("SXGM-601") SXGM602=CountMailboxes("SXGM-602") SXGM603=CountMailboxes("SXGM-603") If SXGM501<>"ERROR" Then Logging.WriteLine(Date & " " & Time & " Mailbox Store 1D (SXGM-501):" & store(1)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 2A (SXGM-501):" & store(2)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3A (SXGM-501):" & store(3)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3B (SXGM-501):" & store(4)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3C (SXGM-501):" & store(5)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3D (SXGM-501):" & store(6)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4A (SXGM-501):" & store(7)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4B (SXGM-501):" & store(8)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4C (SXGM-501):" & store(9)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4D (SXGM-501):" & store(10)) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Mailbox Store 1D (SXGM-501):" & store(1) WScript.Echo Date & " " & Time & " Mailbox Store 2A (SXGM-501):" & store(2) WScript.Echo Date & " " & Time & " Mailbox Store 3A (SXGM-501):" & store(3) WScript.Echo Date & " " & Time & " Mailbox Store 3B (SXGM-501):" & store(4) WScript.Echo Date & " " & Time & " Mailbox Store 3C (SXGM-501):" & store(5) WScript.Echo Date & " " & Time & " Mailbox Store 3D (SXGM-501):" & store(6) WScript.Echo Date & " " & Time & " Mailbox Store 4A (SXGM-501):" & store(7) WScript.Echo Date & " " & Time & " Mailbox Store 4B (SXGM-501):" & store(8) WScript.Echo Date & " " & Time & " Mailbox Store 4C (SXGM-501):" & store(9) WScript.Echo Date & " " & Time & " Mailbox Store 4D (SXGM-501):" & store(10) End If Else for i=1 To 10 'Set the array elements to a high number so they never "win" store(i)=99999 Next if UseDebug="Yes" then WScript.Echo Date & " " & Time & " Cannot contact server SXGM-501 via WMI." Logging.WriteLine(Date & " " & Time & " Cannot contact server SXGM-501 via WMI.") End If If SXGM502<>"ERROR" Then Logging.WriteLine(Date & " " & Time & " Mailbox Store 1D (SXGM-502):" & store(11)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3A (SXGM-502):" & store(12)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3B (SXGM-502):" & store(13)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3C (SXGM-502):" & store(14)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3D (SXGM-502):" & store(15)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4A (SXGM-502):" & store(16)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4B (SXGM-502):" & store(17)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4C (SXGM-502):" & store(18)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4D (SXGM-502):" & store(19)) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Mailbox Store 1D (SXGM-502):" & store(11) WScript.Echo Date & " " & Time & " Mailbox Store 3A (SXGM-502):" & store(12) WScript.Echo Date & " " & Time & " Mailbox Store 3B (SXGM-502):" & store(13) WScript.Echo Date & " " & Time & " Mailbox Store 3C (SXGM-502):" & store(14) WScript.Echo Date & " " & Time & " Mailbox Store 3D (SXGM-502):" & store(15) WScript.Echo Date & " " & Time & " Mailbox Store 4A (SXGM-502):" & store(16) WScript.Echo Date & " " & Time & " Mailbox Store 4B (SXGM-502):" & store(17) WScript.Echo Date & " " & Time & " Mailbox Store 4C (SXGM-502):" & store(18) WScript.Echo Date & " " & Time & " Mailbox Store 4D (SXGM-502):" & store(19) End If Else for i=11 To 19 'Set the array elements to a high number so they never "win" store(i)=99999 Next if UseDebug="Yes" then WScript.Echo Date & " " & Time & " Cannot contact server SXGM-502 via WMI." Logging.WriteLine(Date & " " & Time & " Cannot contact server SXGM-502 via WMI.") End If If SXGM503<>"ERROR" Then Logging.Writeline(Date & " " & Time & " Mailbox Store 1D (SXGM-503):" & store(20)) Logging.Writeline(Date & " " & Time & " Mailbox Store 3A (SXGM-503):" & store(21)) Logging.Writeline(Date & " " & Time & " Mailbox Store 3B (SXGM-503):" & store(22)) Logging.Writeline(Date & " " & Time & " Mailbox Store 3C (SXGM-503):" & store(23)) Logging.Writeline(Date & " " & Time & " Mailbox Store 3D (SXGM-503):" & store(24)) Logging.Writeline(Date & " " & Time & " Mailbox Store 4A (SXGM-503):" & store(25)) Logging.Writeline(Date & " " & Time & " Mailbox Store 4B (SXGM-503):" & store(26)) Logging.Writeline(Date & " " & Time & " Mailbox Store 4C (SXGM-503):" & store(27)) Logging.Writeline(Date & " " & Time & " Mailbox Store 4D (SXGM-503):" & store(28)) If UseDebug="Yes" then WScript.Echo Date & " " & Time & " Mailbox Store 1D (SXGM-503):" & store(20) WScript.Echo Date & " " & Time & " Mailbox Store 3A (SXGM-503):" & store(21) WScript.Echo Date & " " & Time & " Mailbox Store 3B (SXGM-503):" & store(22) WScript.Echo Date & " " & Time & " Mailbox Store 3C (SXGM-503):" & store(23) WScript.Echo Date & " " & Time & " Mailbox Store 3D (SXGM-503):" & store(24) WScript.Echo Date & " " & Time & " Mailbox Store 4A (SXGM-503):" & store(25) WScript.Echo Date & " " & Time & " Mailbox Store 4B (SXGM-503):" & store(26) WScript.Echo Date & " " & Time & " Mailbox Store 4C (SXGM-503):" & store(27) WScript.Echo Date & " " & Time & " Mailbox Store 4D (SXGM-503):" & store(28) End If Else for i=20 to 28 'Set the array elements to a high number so they never "win" store(i)=99999 Next if UseDebug="Yes" then WScript.Echo Date & " " & Time & " Cannot contact server SXGM-503 via WMI." Logging.WriteLine(Date & " " & Time & " Cannot contact server SXGM-503 via WMI.") End If If SXGM601<>"ERROR" Then Logging.WriteLine(Date & " " & Time & " Mailbox Store 1D (SXGM-601):" & store(29)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3A (SXGM-601):" & store(30)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3B (SXGM-601):" & store(31)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3C (SXGM-601):" & store(32)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3D (SXGM-601):" & store(33)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4A (SXGM-601):" & store(34)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4B (SXGM-601):" & store(35)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4C (SXGM-601):" & store(36)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4D (SXGM-601):" & store(37)) If UseDebug="Yes" then WScript.Echo Date & " " & Time & " Mailbox Store 1D (SXGM-601):" & store(29) WScript.Echo Date & " " & Time & " Mailbox Store 3A (SXGM-601):" & store(30) WScript.Echo Date & " " & Time & " Mailbox Store 3B (SXGM-601):" & store(31) WScript.Echo Date & " " & Time & " Mailbox Store 3C (SXGM-601):" & store(32) WScript.Echo Date & " " & Time & " Mailbox Store 3D (SXGM-601):" & store(33) WScript.Echo Date & " " & Time & " Mailbox Store 4A (SXGM-601):" & store(34) WScript.Echo Date & " " & Time & " Mailbox Store 4B (SXGM-601):" & store(35) WScript.Echo Date & " " & Time & " Mailbox Store 4C (SXGM-601):" & store(36) WScript.Echo Date & " " & Time & " Mailbox Store 4D (SXGM-601):" & store(37) End If Else for i=29 To 37 'Set the array elements to a high number so they never "win" store(i)=99999 Next Logging.WriteLine(Date & " " & Time & " Cannot contact server SXGM-601 via WMI.") End If If SXGM602<>"ERROR" Then Logging.WriteLine(Date & " " & Time & " Mailbox Store 1D (SXGM-602):" & store(38)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3A (SXGM-602):" & store(39)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3B (SXGM-602):" & store(40)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3C (SXGM-602):" & store(41)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3D (SXGM-602):" & store(42)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4A (SXGM-602):" & store(43)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4B (SXGM-602):" & store(44)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4C (SXGM-602):" & store(45)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4D (SXGM-602):" & store(46)) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Mailbox Store 1D (SXGM-602):" & store(38) WScript.Echo Date & " " & Time & " Mailbox Store 3A (SXGM-602):" & store(39) WScript.Echo Date & " " & Time & " Mailbox Store 3B (SXGM-602):" & store(40) WScript.Echo Date & " " & Time & " Mailbox Store 3C (SXGM-602):" & store(41) WScript.Echo Date & " " & Time & " Mailbox Store 3D (SXGM-602):" & store(42) WScript.Echo Date & " " & Time & " Mailbox Store 4A (SXGM-602):" & store(43) WScript.Echo Date & " " & Time & " Mailbox Store 4B (SXGM-602):" & store(44) WScript.Echo Date & " " & Time & " Mailbox Store 4C (SXGM-602):" & store(45) WScript.Echo Date & " " & Time & " Mailbox Store 4D (SXGM-602):" & store(46) End If Else For i=38 To 46 'Set the array elements to a high number so they never "win" store(i)=99999 Next Logging.WriteLine(Date & " " & Time & " Cannot contact server SXGM-602 via WMI.") End If If SXGM603<>"ERROR" Then Logging.WriteLine(Date & " " & Time & " Mailbox Store 1D (SXGM-603):" & store(47)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3A (SXGM-603):" & store(48)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3B (SXGM-603):" & store(49)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3C (SXGM-603):" & store(50)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 3D (SXGM-603):" & store(51)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4A (SXGM-603):" & store(52)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4B (SXGM-603):" & store(53)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4C (SXGM-603):" & store(54)) Logging.WriteLine(Date & " " & Time & " Mailbox Store 4D (SXGM-603):" & store(55)) If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Mailbox Store 1D (SXGM-603):" & store(47) WScript.Echo Date & " " & Time & " Mailbox Store 3A (SXGM-603):" & store(48) WScript.Echo Date & " " & Time & " Mailbox Store 3B (SXGM-603):" & store(49) WScript.Echo Date & " " & Time & " Mailbox Store 3C (SXGM-603):" & store(50) WScript.Echo Date & " " & Time & " Mailbox Store 3D (SXGM-603):" & store(51) WScript.Echo Date & " " & Time & " Mailbox Store 4A (SXGM-603):" & store(52) WScript.Echo Date & " " & Time & " Mailbox Store 4B (SXGM-603):" & store(53) WScript.Echo Date & " " & Time & " Mailbox Store 4C (SXGM-603):" & store(54) WScript.Echo Date & " " & Time & " Mailbox Store 4D (SXGM-603):" & store(55) End If Else for i=47 To 55 'Set the array elements to a high number so they never "win" store(i)=99999 Next if UseDebug="Yes" then WScript.Echo Date & " " & Time & " Cannot contact server SXGM-603 via WMI." Logging.WriteLine(Date & " " & Time & " Cannot contact server SXGM-603 via WMI.") End If LowestCount=9999 for x=1 to 55 NumberToTest=store(x) 'If UseDebug="Yes" Then WScript.Echo Date & " " & Time & " Store(" & x & ") has " & store(x) & " MailBoxes." if store(x)0 Then CountMailboxes="ERROR" Exit Function End If Set listExchange_Mailboxs = objWMIExchange.InstancesOf(cWMIInstance) If (listExchange_Mailboxs.count > 0) Then i=0 For Each objExchange_Mailbox in listExchange_Mailboxs If instr(objExchange_Mailbox.MailboxDisplayname,"SystemMailbox")=0 And instr(objExchange_Mailbox.MailboxDisplayname,"SMTP ")=0 and instr(objExchange_Mailbox.MailboxDisplayName,"SXGM")=0 and instr(objExchange_Mailbox.MailboxDisplayName,"System Attendant")=0 Then If UseDebug="Yes" then WScript.Echo Date & " " & Time & " Checking " & objExchange_Mailbox.storename & "/" & objExchange_Mailbox.MailboxDisplayName If instr(objExchange_Mailbox.storename,"SXGM-501")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 1D")>0 Then Store(1)=Store(1)+1 if instr(objExchange_Mailbox.storename,"SXGM-501")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 2A")>0 then Store(2)=Store(2)+1 if instr(objExchange_Mailbox.storename,"SXGM-501")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3A")>0 then Store(3)=Store(3)+1 if instr(objExchange_Mailbox.storename,"SXGM-501")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3B")>0 then Store(4)=Store(4)+1 if instr(objExchange_Mailbox.storename,"SXGM-501")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3C")>0 then Store(5)=Store(5)+1 if instr(objExchange_Mailbox.storename,"SXGM-501")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3D")>0 then Store(6)=Store(6)+1 if instr(objExchange_Mailbox.storename,"SXGM-501")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4A")>0 then Store(7)=Store(7)+1 if instr(objExchange_Mailbox.storename,"SXGM-501")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4B")>0 then Store(8)=Store(8)+1 if instr(objExchange_Mailbox.storename,"SXGM-501")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4C")>0 then Store(9)=Store(9)+1 if instr(objExchange_Mailbox.storename,"SXGM-501")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4D")>0 then Store(10)=Store(10)+1 if instr(objExchange_Mailbox.storename,"SXGM-502")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 1D")>0 then Store(11)=Store(11)+1 if instr(objExchange_Mailbox.storename,"SXGM-502")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3A")>0 then Store(12)=Store(12)+1 if instr(objExchange_Mailbox.storename,"SXGM-502")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3B")>0 then Store(13)=Store(13)+1 if instr(objExchange_Mailbox.storename,"SXGM-502")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3C")>0 then Store(14)=Store(14)+1 if instr(objExchange_Mailbox.storename,"SXGM-502")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3D")>0 then Store(15)=Store(15)+1 if instr(objExchange_Mailbox.storename,"SXGM-502")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4A")>0 then Store(16)=Store(16)+1 if instr(objExchange_Mailbox.storename,"SXGM-502")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4B")>0 then Store(17)=Store(17)+1 if instr(objExchange_Mailbox.storename,"SXGM-502")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4C")>0 then Store(18)=Store(18)+1 if instr(objExchange_Mailbox.storename,"SXGM-502")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4D")>0 then Store(19)=Store(19)+1 if instr(objExchange_Mailbox.storename,"SXGM-503")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 1D")>0 then Store(20)=Store(20)+1 if instr(objExchange_Mailbox.storename,"SXGM-503")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3A")>0 then Store(21)=Store(21)+1 if instr(objExchange_Mailbox.storename,"SXGM-503")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3B")>0 then Store(22)=Store(22)+1 if instr(objExchange_Mailbox.storename,"SXGM-503")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3C")>0 then Store(23)=Store(23)+1 if instr(objExchange_Mailbox.storename,"SXGM-503")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3D")>0 then Store(24)=Store(24)+1 if instr(objExchange_Mailbox.storename,"SXGM-503")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4A")>0 then Store(25)=Store(25)+1 if instr(objExchange_Mailbox.storename,"SXGM-503")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4B")>0 then Store(26)=Store(26)+1 if instr(objExchange_Mailbox.storename,"SXGM-503")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4C")>0 then Store(27)=Store(27)+1 if instr(objExchange_Mailbox.storename,"SXGM-503")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4D")>0 then Store(28)=Store(28)+1 if instr(objExchange_Mailbox.storename,"SXGM-601")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 1D")>0 then Store(29)=Store(29)+1 if instr(objExchange_Mailbox.storename,"SXGM-601")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3A")>0 then Store(30)=Store(30)+1 if instr(objExchange_Mailbox.storename,"SXGM-601")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3B")>0 then Store(31)=Store(31)+1 if instr(objExchange_Mailbox.storename,"SXGM-601")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3C")>0 then Store(32)=Store(32)+1 if instr(objExchange_Mailbox.storename,"SXGM-601")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3D")>0 then Store(33)=Store(33)+1 if instr(objExchange_Mailbox.storename,"SXGM-601")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4A")>0 then Store(34)=Store(34)+1 if instr(objExchange_Mailbox.storename,"SXGM-601")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4B")>0 then Store(35)=Store(35)+1 if instr(objExchange_Mailbox.storename,"SXGM-601")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4C")>0 then Store(36)=Store(36)+1 if instr(objExchange_Mailbox.storename,"SXGM-601")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4D")>0 then Store(37)=Store(37)+1 if instr(objExchange_Mailbox.storename,"SXGM-602")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 1D")>0 then Store(38)=Store(38)+1 if instr(objExchange_Mailbox.storename,"SXGM-602")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3A")>0 then Store(39)=Store(39)+1 if instr(objExchange_Mailbox.storename,"SXGM-602")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3B")>0 then Store(40)=Store(40)+1 if instr(objExchange_Mailbox.storename,"SXGM-602")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3C")>0 then Store(41)=Store(41)+1 if instr(objExchange_Mailbox.storename,"SXGM-602")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3D")>0 then Store(42)=Store(42)+1 if instr(objExchange_Mailbox.storename,"SXGM-602")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4A")>0 then Store(43)=Store(43)+1 if instr(objExchange_Mailbox.storename,"SXGM-602")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4B")>0 then Store(44)=Store(44)+1 if instr(objExchange_Mailbox.storename,"SXGM-602")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4C")>0 then Store(45)=Store(45)+1 if instr(objExchange_Mailbox.storename,"SXGM-602")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4D")>0 then Store(46)=Store(46)+1 if instr(objExchange_Mailbox.storename,"SXGM-603")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 1D")>0 then Store(47)=Store(47)+1 if instr(objExchange_Mailbox.storename,"SXGM-603")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3A")>0 then Store(48)=Store(48)+1 if instr(objExchange_Mailbox.storename,"SXGM-603")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3B")>0 then Store(49)=Store(49)+1 if instr(objExchange_Mailbox.storename,"SXGM-603")>0 And instr(objExchange_Mailbox.storename,"Mailbox Store 3C")>0 then Store(50)=Store(50)+1 if instr(objExchange_Mailbox.storename,"SXGM-603")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 3D")>0 then Store(51)=Store(51)+1 if instr(objExchange_Mailbox.storename,"SXGM-603")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4A")>0 then Store(52)=Store(52)+1 if instr(objExchange_Mailbox.storename,"SXGM-603")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4B")>0 then Store(53)=Store(53)+1 if instr(objExchange_Mailbox.storename,"SXGM-603")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4C")>0 then Store(54)=Store(54)+1 if instr(objExchange_Mailbox.storename,"SXGM-603")>0 and instr(objExchange_Mailbox.storename,"Mailbox Store 4D")>0 then Store(55)=Store(55)+1 End If Next End If End Function