vbscript: ArchiveLog

Archive the export/import.xml file, and modify so it works with the stylesheet.

The log.xsl stylesheet should be copied into the root of the MaData folder.

 

' This script copies the MIIS export and import logs to datestamped versions
' and modifies them to work with a stylesheet called ../log.xsl.
'
' The logs should be called 'import.xml' or 'export.xml'
' Enter the MA name and just 'import' or 'export' when calling the script.
'   Usage: cscript archivelog.vbs MaName import|export
'
' Written by Carol Wapshere https://www.wapshere.com/missmiis
Option Explicit
Const XML_STYLESHEET = "..\log.xsl"
Const MIIS_FOLDER = "C:\Program Files\Microsoft Identity Integration Server"
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const Unicode = -1
Dim objFS, MaName, LogName
Set objFS = CreateObject("Scripting.FileSystemObject")
If WScript.Arguments.Count <> 2 Then
  Usage
End If
MaName = WScript.Arguments.Item(0)
LogName = WScript.Arguments.Item(1)
ArchiveLog MaName, LogName
Sub ArchiveLog(MA, Profile)
  Dim objLogFile, objArchiveFile
  Dim strLogName, strArchiveName, logTime, dateStamp, strLine
  strLogName = MIIS_FOLDER & "\MaData\" & MA & "\" & Profile & ".xml"
  If objFS.FileExists(strLogName) Then
    logTime = Now()
    dateStamp = DatePart("yyyy", logTime) & TwoChars("m", logTime) &_
                                 TwoChars("d", logTime) & TwoChars("h", logTime) &_
                                 TwoChars("n", logTime) & TwoChars("s", logTime) 
    strArchiveName = MIIS_FOLDER & "\MaData\" & MA & "\" & Profile & dateStamp & ".xml"
    set objLogFile = objFS.OpenTextFile(strLogName, ForReading, false, Unicode)
    set objArchiveFile = objFS.OpenTextFile(strArchiveName, ForWriting, true, Unicode)
    objLogFile.ReadLine()
    objArchiveFile.WriteLine("<?xml version=""1.0"" encoding=""UTF-16""?>")
    objArchiveFile.WriteLine("<?xml-stylesheet type=""text/xsl"" href="" mce_href=""" & XML_STYLESHEET & """?>")
    objArchiveFile.WriteLine("<top>")
    objArchiveFile.WriteLine("<xmlfile-time>")
    objArchiveFile.WriteLine(logTime)
    objArchiveFile.WriteLine("</xmlfile-time>")
    objLogFile.ReadLine() 'skip mmsml
    objLogFile.ReadLine() 'skip directory-entries
    strLine = objLogFile.ReadLine()
    Do Until InStr(strLine, "</directory-entries>") > 0
       objArchiveFile.WriteLine(strLine)
       strLine = objLogFile.ReadLine()    
    Loop
    objArchiveFile.WriteLine("</top>")
    objLogFile.Close()
    objArchiveFile.Close()
  End If
End Sub
Function TwoChars(dtvar, time)
  Dim i
  i = DatePart(dtvar, time)
  If i < 10 Then
   TwoChars = "0" & CStr(i)
  Else
   TwoChars = CStr(i)
  End If
End Function
Sub Usage
  Wscript.echo "Usage: cscript archivelog.vbs MaName import|export"
  Wscript.Quit
End Sub