{"id":912,"date":"2010-08-16T14:49:58","date_gmt":"2010-08-16T14:49:58","guid":{"rendered":"https:\/\/www.wapshere.com\/missmiis\/?p=912"},"modified":"2010-09-28T07:22:13","modified_gmt":"2010-09-28T07:22:13","slug":"archiving-the-import-and-export-logs-and-viewing-them-with-a-stylesheet","status":"publish","type":"post","link":"https:\/\/www.wapshere.com\/missmiis\/archiving-the-import-and-export-logs-and-viewing-them-with-a-stylesheet","title":{"rendered":"Archiving the Import and Export Logs, and viewing them with a stylesheet"},"content":{"rendered":"<p>A <a href=\"https:\/\/www.wapshere.com\/missmiis\/a-stylesheet-for-the-import-and-export-logs\">long time ago<\/a> I wrote up a method that could be used to archive the MIIS import and export logs, while also making them more readable with a stylesheet. I&#8217;ve now implemented this on a FIM 2010 server, and it works, so I&#8217;m going to write it up again.<!--more--><\/p>\n<h3>The Problem<\/h3>\n<p>The FIM Sync Service, just like its predecessors, only stores information about the current state of objects. Run History is almost completely worthless and <a href=\"http:\/\/social.technet.microsoft.com\/Forums\/en-US\/ilm2\/thread\/7e60ec1f-939c-4475-bfb9-01e739b8e5fc\">should be cleared regularly<\/a>. However there will be times when you will be asked to trace through a series of events &#8211; perhaps leading to the CEO&#8217;s account being inadvertently disabled. At times like this it is important to be able to show that FIM was just responding appropriately to an imported data change, and not acting maliciously in some skynet-esque awakening.<\/p>\n<p>However, as we know, the import and export run profiles, while allowing a log file to be dumped, then helpfully overwrite it at the next run. We need a way to hang on to that historical data.<\/p>\n<h3>The Proposal<\/h3>\n<p>If you&#8217;re already running your tasks using vbscripts it&#8217;s pretty simple to add an extra step which copies the log file off to a datestamped version in an archive location (script below).<\/p>\n<p>At the same time, we can do a little manipulation to the log file to make it more readable. By inserting a couple of lines in the top of the log file it can now be used with an XML Stylesheet, allowing it to be browsed in a nice table format.<\/p>\n<h3>Provisos<\/h3>\n<p>The log file will only be archived if you run your export and import jobs via your scripts. Anything\u00c2\u00a0run directly from the Sync Service GUI may still produce a log file, but it won&#8217;t be archived.<\/p>\n<p>Also, the timestamp is a approximate as it represents the time the log was archived, rather than the exact time specific objects were modified in a target directory. But if you archive the log straight after the Export profile runs then it should be close enough for most purposes.<\/p>\n<h3>log.xsl<\/h3>\n<p>First, you need to create a folder somewhere with the same sub-folders as your MaData folder (in the script example below, I&#8217;m using D:\\FIM\\MALogArchives). Then, into this new folder, create a text file called &#8220;log.xsl&#8221; and paste in <a href=\"https:\/\/www.wapshere.com\/missmiis\/code-snippets\/logxsl\">this content<\/a>.<\/p>\n<h3>ArchiveLog.vbs<\/h3>\n<p>Now here&#8217;s a vbscript that will copy the named log file, while modifying it to work with the stylesheet.<\/p>\n<p><code><\/p>\n<pre>' This script copies the export and import logs to datestamped versions\r\n' and modifies them to work with a stylesheet called ..\/log.xsl.\r\n'\r\n'   Usage: cscript archivelog.vbs MaName LogFileName\r\n'\r\n'   Eg:    cscript archivelog.vbs HR import.xml\r\n'\r\n' Written by Carol Wapshere\r\n\r\nOption Explicit\r\nConst XML_STYLESHEET = \"..\\log.xsl\"\r\nConst MIIS_FOLDER = \"C:\\Program Files\\Microsoft Forefront Identity Manager\\2010\\Synchronization Service\"\r\nConst ARCHIVE_FOLDER = \"D:\\FIM\\MALogArchives\"\r\nConst ForReading = 1\r\nConst ForWriting = 2\r\nConst ForAppending = 8\r\nConst Unicode = -1\r\n\r\nDim objFS, MaName, LogName\r\nSet objFS = CreateObject(\"Scripting.FileSystemObject\")\r\n\r\nIf WScript.Arguments.Count &lt;&gt; 2 Then\r\n  Usage\r\nEnd If\r\n\r\nMaName = WScript.Arguments.Item(0)\r\nLogName = WScript.Arguments.Item(1)\r\n\r\nArchiveLog MaName, LogName\r\n\r\nSub ArchiveLog(MA, LogFile)\r\n\r\n  Dim objLogFile, objArchiveFile\r\n  Dim strLogName, strArchiveName, logTime, dateStamp, strLine\r\n\r\n  strLogName = MIIS_FOLDER &amp; \"\\MaData\\\" &amp; MA &amp; \"\\\" &amp; LogFile\r\n  If objFS.FileExists(strLogName) Then\r\n    logTime = Now()\r\n    dateStamp = DatePart(\"yyyy\", logTime) &amp; TwoChars(\"m\", logTime) &amp;_\r\n                                 TwoChars(\"d\", logTime) &amp; TwoChars(\"h\", logTime) &amp;_\r\n                                 TwoChars(\"n\", logTime) &amp; TwoChars(\"s\", logTime)\r\n    strArchiveName = ARCHIVE_FOLDER &amp; \"\\\" &amp; MA &amp; \"\\\" &amp; Split(LogFile,\".\")(0) &amp; \"_\" &amp; dateStamp &amp; \".xml\"\r\n    set objLogFile = objFS.OpenTextFile(strLogName, ForReading, false, Unicode)\r\n    set objArchiveFile = objFS.OpenTextFile(strArchiveName, ForWriting, true, Unicode)\r\n    objLogFile.ReadLine()\r\n    objArchiveFile.WriteLine(\"&lt;?xml version=\"\"1.0\"\" encoding=\"\"UTF-16\"\"?&gt;\")\r\n    objArchiveFile.WriteLine(\"&lt;?xml-stylesheet type=\"\"text\/xsl\"\" href=\"\"\" &amp; XML_STYLESHEET &amp; \"\"\"?&gt;\")\r\n    objArchiveFile.WriteLine(\"&lt;top&gt;\")\r\n    objArchiveFile.WriteLine(\"&lt;xmlfile-time&gt;\")\r\n    objArchiveFile.WriteLine(logTime)\r\n    objArchiveFile.WriteLine(\"&lt;\/xmlfile-time&gt;\")\r\n    objLogFile.ReadLine() 'skip mmsml\r\n    objLogFile.ReadLine() 'skip directory-entries\r\n    strLine = objLogFile.ReadLine()\r\n    Do Until InStr(strLine, \"&lt;\/directory-entries&gt;\") &gt; 0\r\n       objArchiveFile.WriteLine(strLine)\r\n       strLine = objLogFile.ReadLine()\r\n    Loop\r\n    objArchiveFile.WriteLine(\"&lt;\/top&gt;\")\r\n    objLogFile.Close()\r\n    objArchiveFile.Close()\r\n  End If\r\nEnd Sub\r\n\r\nFunction TwoChars(dtvar, time)\r\n  Dim i\r\n  i = DatePart(dtvar, time)\r\n  If i &lt; 10 Then\r\n   TwoChars = \"0\" &amp; CStr(i)\r\n  Else\r\n   TwoChars = CStr(i)\r\n  End If\r\nEnd Function\r\n\r\nSub Usage\r\n  Wscript.echo \"Usage: cscript archivelog.vbs MaName import|export\"\r\n  Wscript.Quit\r\nEnd Sub<\/pre>\n<p>\u00c2\u00a0<\/p>\n<p><\/code><\/p>\n<h3>Modify the Run scripts<\/h3>\n<p>Your last step is to modify your scheduled scripts to archive the import\/export log directly after the task has run.<\/p>\n<p><code><\/p>\n<pre>cscript AD_Export.vbs\r\ncscript ArchiveLog.vbs \"AD MA\" export.xml<\/pre>\n<p>\u00c2\u00a0<\/p>\n<p><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A long time ago I wrote up a method that could be used to archive the MIIS import and export logs, while also making them more readable with a stylesheet. I&#8217;ve now implemented this on a FIM 2010 server, and it works, so I&#8217;m going to write it up again.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[42,9,10],"tags":[],"class_list":["post-912","post","type-post","status-publish","format-standard","hentry","category-fim-2010","category-logs","category-vbscript"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pkp1o-eI","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/comments?post=912"}],"version-history":[{"count":11,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/912\/revisions"}],"predecessor-version":[{"id":1778,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/912\/revisions\/1778"}],"wp:attachment":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/media?parent=912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/categories?post=912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/tags?post=912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}