none
How could I make batch job of clear runs , save runs before clearing them in MIIS ?

    Question

  • How could I make batch job of clear runs , save runs before clearing them in MIIS ?
    Monday, January 21, 2013 8:09 AM

Answers

  • ok you can use the error variable as follows.

    On Error Resume Next
    
    'Option Explicit
    Const ForAppending = 8
    Dim Service
    Dim Runs
    Dim Run
    Dim DateTill 
    Dim strDirectory
    Dim strFile
    DateTill = "2013-01-22 00:00:00.000"
    Set Service = GetObject("winmgmts:root\MicrosoftIdentityIntegrationServer")
    Set Runs = Service.ExecQuery("Select * From MIIS_RunHistory where RunStartTime <= '" & DateTill & "'")
    Set ServiceC = Service.ExecQuery("Select * From MIIS_SERVER")
    strDirectory = "c:\SomeDirectory\"
    strFile = "RunHistory" & Replace(DateTill,":","-") & ".xml"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile(strDirectory & strFile, ForAppending, True)
    objTextFile.WriteLine "<execution-histories>"
    For Each Run in Runs
        retVal = Run.RunDetails()
        If (Err) Then
            objTextFile.WriteLine (Err.Source & Err.Message)
        Else
        	objTextFile.WriteLine Replace(retVal,"<?xml version=""1.0"" encoding=""utf-16""?>","")
        End If
    
    Next
    objTextFile.WriteLine "</execution-histories>"
    objTextFile.Close
    For Each SvcC in ServiceC
    	SvcC.ClearRuns(DateTill)
    Next
    
    
    • Marked as answer by blackjack08 Friday, April 12, 2013 10:44 PM
    Tuesday, January 22, 2013 3:41 AM

All replies

  • To Save and Clear the RUNS you can follow the following vb script,

    'Option Explicit
    Const ForAppending = 8
    Dim Service
    Dim Runs
    Dim Run
    Dim DateTill 
    Dim strDirectory
    Dim strFile
    DateTill = "2013-01-22 00:00:00.000"
    Set Service = GetObject("winmgmts:root\MicrosoftIdentityIntegrationServer")
    Set Runs = Service.ExecQuery("Select * From MIIS_RunHistory where RunStartTime <= '" & DateTill & "'")
    Set ServiceC = Service.ExecQuery("Select * From MIIS_SERVER")
    strDirectory = "c:\SomeDirectory\"
    strFile = "RunHistory" & Replace(DateTill,":","-") & ".xml"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile(strDirectory & strFile, ForAppending, True)
    objTextFile.WriteLine "<execution-histories>"
    For Each Run in Runs
        objTextFile.WriteLine Replace(Run.RunDetails(),"<?xml version=""1.0"" encoding=""utf-16""?>","")
    Next
    objTextFile.WriteLine "</execution-histories>"
    objTextFile.Close
    For Each SvcC in ServiceC
    	SvcC.ClearRuns(DateTill)
    Next

    You can take DateTill as a param input as well.
    • Edited by Furqan Asghar Monday, January 21, 2013 9:21 AM Addition
    Monday, January 21, 2013 9:21 AM
  • Monday, January 21, 2013 9:24 AM
  • If you are asking about the PowerShell script

    replace the trap section with the following

    Trap
    {
    Write-Host "Error: $($_.Exception.Message)" -foregroundcolor white -backgroundcolor darkred
    
    $doc = New-Object System.Xml.XmlDocument
    $doc.LoadXml($_.Exception.Message)
    $dateNow = Get-Date -format "yyyyMMddHHmm"
    $filePathName = $exportDirectory + $dateNow + ".xml"
    $doc.Save($filePathName)
    
    Exit
    }
    


    Monday, January 21, 2013 6:16 PM
  • ok you can use the error variable as follows.

    On Error Resume Next
    
    'Option Explicit
    Const ForAppending = 8
    Dim Service
    Dim Runs
    Dim Run
    Dim DateTill 
    Dim strDirectory
    Dim strFile
    DateTill = "2013-01-22 00:00:00.000"
    Set Service = GetObject("winmgmts:root\MicrosoftIdentityIntegrationServer")
    Set Runs = Service.ExecQuery("Select * From MIIS_RunHistory where RunStartTime <= '" & DateTill & "'")
    Set ServiceC = Service.ExecQuery("Select * From MIIS_SERVER")
    strDirectory = "c:\SomeDirectory\"
    strFile = "RunHistory" & Replace(DateTill,":","-") & ".xml"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile(strDirectory & strFile, ForAppending, True)
    objTextFile.WriteLine "<execution-histories>"
    For Each Run in Runs
        retVal = Run.RunDetails()
        If (Err) Then
            objTextFile.WriteLine (Err.Source & Err.Message)
        Else
        	objTextFile.WriteLine Replace(retVal,"<?xml version=""1.0"" encoding=""utf-16""?>","")
        End If
    
    Next
    objTextFile.WriteLine "</execution-histories>"
    objTextFile.Close
    For Each SvcC in ServiceC
    	SvcC.ClearRuns(DateTill)
    Next
    
    
    • Marked as answer by blackjack08 Friday, April 12, 2013 10:44 PM
    Tuesday, January 22, 2013 3:41 AM