I am working on a project for work that has me redirect the Documents and Desktop folders of my users to a share on a SAN that is attached to our network. I am accomplishing this through GPM in Windows Server 2008r2. I am also tasked with creating a home drive (H:\) with a script that transfers all the user data over in those respective locations. Once the script executes initially and everything is transferred successfully, i would like the file transfer(robocopy) portion to delete itself but the H:\ to remain mapped. A big concern for me are my users that are on the road and connect through VPN. The VPN connects after logon. I took a script from
RaisKazi, 9 May 2013 to establish an IF/THEN statement for my vbscript.
VBScript to check - Am I connected to VPN?[
^]the rest of the code looks like this. Please advise me how I can improve on this
Function IsVPNConnected()
IsVPNConnected = False
sComputer = "."
Set oWMIService = GetObject("winmgmts:\\" _
& sComputer & "\root\CIMV2")
Set colItems = oWMIService.ExecQuery( _
"SELECT * FROM Win32_NetworkAdapterConfiguration",,48)
For Each objItem in colItems
If(InStr(LCase(objItem.Description),"vpn")) Then
IsVPNConnected = objItem.IPEnabled
End If
Next
If(IsVPNConnected) Then
IsVPNConnected = "I am Connected to VPN."
Else
IsVPNConnected = "I am Not Connected to VPN."
End If
End Function
Sub MapNetworkDrive
Dim objNetwork, strUserName, strDriveLetter, strRemotePath, strUserName, strSourceOne, strSourceTwo, strTarget, WshShell, strHomeDrive, WshNetwork
Set objNetwork = CreateObject(Wscript.Network)
Set objExec = objShell.Exec("ping -n 6 -w 4000 " & strTarget
Set WshNetwork = Wscript.CreateObject("Wscript.Network")
WshNetwork.MapNetworkDrive "H:", \\10.100.1.218\HomeFolder\Users$\username*\
On Error Resume Next
strDriveLetter = "H:"
strRemotePath = "\\10.100.1.218\HomeFolder\Users$\username*\"
strUserName = objNetwork.Username
objNetwork.MapNetworkDrive strDriveLetter, strRemotePath, & "\" & strUserName, True
homeDriveSet objShell.namespace(strDriveLetter).Self.Name(Shell.Application)
strNewName = strUserName & "'s Home Folder"
objShell.NameSpace(strDriveLetter).Self.Name = strNewName <user> Home Drive
Set oShell = Wscript.CreateObject(Wscript.shell)
Set objFSO = Wscript.CreateObject(Scripting.FileSystemObject)
strSourceOne = Chr(34) & "C:\User\username*\Documents" & Chr(34)
strTarget = Chr(34) & "\\10.100.1.218\HomeFolder$\Users$\username*\" & Chr(34)
strParms = " /mir /sec /copy:datsou /if *.pdf *.doc *.docx *.xls *.txt *.xlsx *.pptx /R:4 /W:2 /NP /log+:" & "\\10.100.1.218\HomeFolder$\Logs\RoboCOPLog.dco"
Set oshell = CreateObject("Wscript.Shell")
strCommand = Robocopy.exe
WshShell.Run ("robocopy " & strSourceOne & " " & strTarget & strParms)
Set oShell = Wscript.CreateObject(Wscript.shell)
Set objFSO = Wscript.CreateObject(Scripting.FileSystemObject)
strSourceTwo = Chr(34) & "C:\User\username*\Desktop" & Chr(34)
strTarget = Chr(34) & "\\10.100.1.218\HomeFolder$\Users$\username*\" & Chr(34)
strParms = " /mir /sec /copy:datsou /if *.pdf *.doc *.docx *.xls *.txt *.xlsx /R:4 /W:2 /NP /log+:" & "\\10.100.1.218\HomeFolder\Logs\RoboCOPLog.doc"
Set oshell = CreateObject("Wscript.Shell")
strCommand = Robocopy.exe
WshShell.Run ("robocopy" & strSourceTwo & " " & strTarget & strParms)