' **Make Changes Below This Line** ' Create log file. Change "logPath" to place log in desired directory. logPath = "c:\" ' change the "archivePath" to point to your archive directory archivePath = "\\sccm.pvt\corpshare$\Archive" ' ** No Changes Needed Below This Line Const ForAppending = 8 Set objFSO = CreateObject("Scripting.FileSystemObject") Set WshShell = CreateObject("WScript.Shell") Set f1 = objFSO.OpenTextFile(logPath & "Archive.log", ForAppending, TRUE) ' Script accepts a single argument, which is the file (including path). ' File (with path) is placed in "filespec" filespec = GetArgument() ' Get the file path filePath = mid(filespec, 4, InStrRev(filespec, "\", -1, 1) - 4) ' Get the file name fileName = right(filespec, Len(filespec) - InStrRev(filespec, "\", -1, 1)) f1.Writeline Date & " " & Time & " : Evaluating file: " & filespec f1.Writeline Date & " " & Time & " : Checking whether " & chr(34) & archivePath & "\" & filePath & "\" & fileName & chr(34) & " exists." ' Check if file exists If objFSO.FileExists(archivePath & "\" & filePath & "\" & fileName) Then f1.Writeline Date & " " & Time & " : File exists...exiting." wscript.quit Else f1.Writeline Date & " " & Time & " : File does not exist...creating archive." ' Check if directory exists f1.Writeline Date & " " & Time & " : Checking whether " & chr(34) & archivePath & "\" & filePath & chr(34) & " exists." If Not objFSO.FolderExists(archivePath & "\" & filePath) Then ' Make the directory structure Set oExec = WshShell.Exec("cmd.exe /c md " & chr(34) & archivePath & "\" & filePath & chr(34)) Do While oExec.Status = 0 WScript.Sleep 100 Loop If oExec.ExitCode <> 0 then f1.writeline Date & " " & Time & " : Error while running Make Directory command. Error code is " & oExec.ExitCode wscript.quit Else f1.writeline Date & " " & Time & " : Make directory command was successful." End If End If ' Move the file Set oExec = WshShell.Exec("cmd.exe /c move " & chr(34) & filespec & chr(34) & " " & chr(34) & archivePath & "\" & filePath & chr(34)) Do While oExec.Status = 0 WScript.Sleep 100 Loop If oExec.ExitCode <> 0 then f1.writeline Date & " " & Time & " : Error while running moving file to archive. Error code is " & oExec.ExitCode wscript.quit Else f1.writeline Date & " " & Time & " : File move was successful." End If ' Create the symbolic link Set oExec = WshShell.Exec("cmd.exe /c mklink " & chr(34) & filespec & chr(34) & " " & chr(34) & archivePath & "\" & filePath & "\" & fileName & chr(34)) Do While oExec.Status = 0 WScript.Sleep 100 Loop If oExec.ExitCode <> 0 then f1.writeline Date & " " & Time & " : Error while creating symbolic link. Error code is " & oExec.ExitCode wscript.quit Else f1.writeline Date & " " & Time & " : Symbolic link creation was successful." End If End If Function GetArgument() Dim arg If WScript.Arguments.Count <> 1 Then f1.Writeline Date & " " & Time & " : Incorrect number of arguments." Else For each arg in WScript.Arguments GetArgument = arg Next End If End Function