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

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

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

All Replies

  • Monday, January 21, 2013 9:21 AM
     
      Has Code

    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:24 AM
     
     
  • Monday, January 21, 2013 1:29 PM
     
      Has Code

    Thank you.

    We use similar one now and sometime it return error when it run

    Run.RunDetails()

    how could I detect this rundetails error , and return this script result as error ?

  • Monday, January 21, 2013 6:16 PM
     
      Has Code

    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
    }
    


  • Tuesday, January 22, 2013 1:36 AM
     
     

    Thank you.

    And sorry , I use MIIS so, I can not use Powershell.

    I am using Vbscript.

  • Tuesday, January 22, 2013 3:41 AM
     
     Answered Has Code

    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 4:57 AM
     
      Has Code

    Thank you.

    I got SWbemObjectEx: lack of memory error

    when running

    Run.RunDetails()

    Is there any way to avoid that ?

  • Thursday, January 31, 2013 1:25 AM
     
     

    Thank you.

    If Run.Rundetail failed, is it possible to run Wscript.quit(1) and finished the script as failure status ?