Hi there,
I am fairly new to VBScripts and require some help please.
I have a script that copies users PST files from a network share to the local machine and then a batch file imports this into outlook.
THe script currently work well at head office as it is set to copy from the file server. The problem I know face is that I need to do this for remote sites. These sites have site servers on them and the plan is to dump the pst files in a share and for users to to copy this.
I would like to create a single script which will look at the IP Address of the pc, if the PC has an IP range for the Newcastle Site that user must copy their pst from the Newcastle Server and so on for the other sites.
The script currently does the following:
Option Explicit
Const PST_SOURCE = "\\10.17.0.2\EASPST\"
Const NEW_PST_FLDR = "C:\PST"
Const FOR_APPENDING = 8
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell : Set objShell = CreateObject("Wscript.Shell")
Dim objNetwork : Set objNetwork = WScript.CreateObject("WScript.Network")
Dim strUser : strUser = objNetwork.UserName
Dim strFileName : strFileName = PST_SOURCE & strUser & ".pst"
Dim strPSTDestinationPath : strPSTDestinationPath = objShell.ExpandEnvironmentStrings("C:\PST\")
Dim objLog : Set objLog = objFSO.OpenTextFile("\\10.17.0.2\Log\PST_IMPORT_" & struser & ".LOG", FOR_APPENDING, True)
If Not objFSO.FolderExists(NEW_PST_FLDR) Then
Dim objNewFolder : Set objNewFolder = objFSO.CreateFolder(NEW_PST_FLDR)
'Response.Write("A new folder has been created at: " NEW_PST_FLDR)
End If
MSGbox "Please be patient. Do not reboot or shutdown your pc. Your PST file is being copied, do not open OUTLOOK!!!!"
'Create a log header
objLog.WriteLine String(50, "*")
objLog.WriteLine "PST Import log for: " & strUser
objLog.WriteLine "Script started at: " & Now()
objLog.WriteLine String(50, "*")
objLog.WriteBlankLines(1)
If Not objFSO.FileExists(NEW_PST_FLDR & "\" & strUser & ".pst") Then
objLog.WriteLine Now() & vbTab & "Initiating file copy from " & strFileName & " to " & strPSTDestinationPath
On Error Resume Next
objFSO.CopyFile strFileName, strPSTDestinationPath
If Err.Number = 0 Then
objLog.WriteLine Now() & vbTab & "File copy operation completed successfully"
objLog.WriteLine Now() & vbTab & "Initiating " & PST_SOURCE & "script\outlookimport.bat"
objShell.run "CMD /C " & PST_SOURCE & "script\outlookimport.bat", 0, True
Else
objLog.WriteLine Now() & vbTab & "ERROR " & Err.Number & " - File Copy operation failed. " & Err.Description
End If
On Error GoTo 0
Else
objLog.WriteLine Now() & vbTab & "File already exists, operation aborted"
End If
objLog.WriteLine Now() & vbTab & WScript.ScriptFullName & " completed"
objLog.Close
If someone could help me with the IP based stuff will really appreciate it.
Thanks
I am fairly new to VBScripts and require some help please.
I have a script that copies users PST files from a network share to the local machine and then a batch file imports this into outlook.
THe script currently work well at head office as it is set to copy from the file server. The problem I know face is that I need to do this for remote sites. These sites have site servers on them and the plan is to dump the pst files in a share and for users to to copy this.
I would like to create a single script which will look at the IP Address of the pc, if the PC has an IP range for the Newcastle Site that user must copy their pst from the Newcastle Server and so on for the other sites.
The script currently does the following:
Option Explicit
Const PST_SOURCE = "\\10.17.0.2\EASPST\"
Const NEW_PST_FLDR = "C:\PST"
Const FOR_APPENDING = 8
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell : Set objShell = CreateObject("Wscript.Shell")
Dim objNetwork : Set objNetwork = WScript.CreateObject("WScript.Network")
Dim strUser : strUser = objNetwork.UserName
Dim strFileName : strFileName = PST_SOURCE & strUser & ".pst"
Dim strPSTDestinationPath : strPSTDestinationPath = objShell.ExpandEnvironmentStrings("C:\PST\")
Dim objLog : Set objLog = objFSO.OpenTextFile("\\10.17.0.2\Log\PST_IMPORT_" & struser & ".LOG", FOR_APPENDING, True)
If Not objFSO.FolderExists(NEW_PST_FLDR) Then
Dim objNewFolder : Set objNewFolder = objFSO.CreateFolder(NEW_PST_FLDR)
'Response.Write("A new folder has been created at: " NEW_PST_FLDR)
End If
MSGbox "Please be patient. Do not reboot or shutdown your pc. Your PST file is being copied, do not open OUTLOOK!!!!"
'Create a log header
objLog.WriteLine String(50, "*")
objLog.WriteLine "PST Import log for: " & strUser
objLog.WriteLine "Script started at: " & Now()
objLog.WriteLine String(50, "*")
objLog.WriteBlankLines(1)
If Not objFSO.FileExists(NEW_PST_FLDR & "\" & strUser & ".pst") Then
objLog.WriteLine Now() & vbTab & "Initiating file copy from " & strFileName & " to " & strPSTDestinationPath
On Error Resume Next
objFSO.CopyFile strFileName, strPSTDestinationPath
If Err.Number = 0 Then
objLog.WriteLine Now() & vbTab & "File copy operation completed successfully"
objLog.WriteLine Now() & vbTab & "Initiating " & PST_SOURCE & "script\outlookimport.bat"
objShell.run "CMD /C " & PST_SOURCE & "script\outlookimport.bat", 0, True
Else
objLog.WriteLine Now() & vbTab & "ERROR " & Err.Number & " - File Copy operation failed. " & Err.Description
End If
On Error GoTo 0
Else
objLog.WriteLine Now() & vbTab & "File already exists, operation aborted"
End If
objLog.WriteLine Now() & vbTab & WScript.ScriptFullName & " completed"
objLog.Close
If someone could help me with the IP based stuff will really appreciate it.
Thanks