none
save and clear run history in FIM 2010 R2 RRS feed

  • General discussion

  • Hi

    I am trying to make a powershell script to save and clear runs from the sync engine.

    I modifyed a script I found in the forum, but I can not get the 'save' part to work with specific dates. It just generates 'one' XML entry. It does not save the same period as I clear.

    How can I save runs for the same period as I clear ??  (btw. I am not a great powershell guy - so foregive me the code :-))

    Powershell script :

    $dayDiff=85

    $dateDelete = Get-Date

    #if the dayDiff parameter is passed, subtract it from the current day.
    If($dayDiff -ne 0)
    {
    $dateDelete = $dateDelete.AddDays(-$dayDiff)
    }
    Else
    {
    $dateDelete = $dateDelete.AddDays(1)
    }

    Write-Host “Exporting full run history.”

    $lstManagementAgent = @(get-wmiobject -class “MIIS_ManagementAgent” -namespace “root\MicrosoftIdentityIntegrationServer” -computer “.”)
    $runDetails = $lstManagementAgent[0].RunDetails().ReturnValue

    $doc = New-Object System.Xml.XmlDocument
    $doc.LoadXml($runDetails)
    $dateNow = $dateDelete.toString(‘yyyyMMdd’)

    $filePathName = "C:\FIMbackup af runs i sync motor\Runs frem til $dateNow.xml”
    $doc.Save($filePathName)

    Write-Host “Successfully exported run history to: ” $filePathName

    #finally, delete the run history:
    Write-Host “Deleting run history earlier than:” $dateDelete.toString(‘MM/dd/yyyy’)

    $lstSrv = @(get-wmiobject -class “MIIS_SERVER” -namespace “root\MicrosoftIdentityIntegrationServer” -computer “.”)
    Write-Host “Result: ” $lstSrv[0].ClearRuns($dateDelete.toString(‘yyyy-MM-dd’)).ReturnValue

    #——————————————————————————————————————–
    Trap
    {
    Write-Host “Error: $($_.Exception.Message)” -foregroundcolor white -backgroundcolor darkred
    Exit
    }
    #——————————————————————————————————————–

    Regards

    Per

    Monday, March 11, 2013 9:26 AM

All replies

  • The code you have writen is producing exactly one xml file and that is true, you are fetching all the management agents but then write the rundetails for the first management agent to a xml file:
    $lstManagementAgent = @(get-wmiobject -class “MIIS_ManagementAgent” -namespace “root\MicrosoftIdentityIntegrationServer” -computer “.”)
    $runDetails = $lstManagementAgent[0].RunDetails().ReturnValue

    The position [0] indicates the 1st management agent from the list, using this list it only saves the current (latest) run details for the management agent.

    You should skip the save part using the MIIS_ManagementAgent WMI class, you need to use the WMI class MIIS_RunHistory, these classes can be retrieved using the call $lstSrv.GetHistory($dateDelete.toString("yyyy-MM-dd") the MIIS_RunHistory also contains the property RunDetails.

    You need to save that contents to a xml file and then delete the history from the server using the ClearRuns method

    I have done this myself but using C# code, and therefore cannot share it.



    Need realtime FIM synchronization and advanced reporting? check out the new http://www.imsequencer.com that supports FIM 2010, Omada Identity Manager, SQL, File, AD or Powershell real time synchronization!

    Monday, March 11, 2013 12:32 PM
  • Hi Paul

    Thanks for the answer

    I have tryed to put it into the code, but got the error 'error: method invocation failed because [system.object[]] doesn't contain a method named 'GetHistory'

    suggestion :-)

    code :

    $dayDiff=85

    $dateDelete = Get-Date

    #if the dayDiff parameter is passed, subtract it from the current day.
    If($dayDiff -ne 0)
    {
    $dateDelete = $dateDelete.AddDays(-$dayDiff)
    }
    Else
    {
    $dateDelete = $dateDelete.AddDays(1)
    }

    Write-Host “Exporting full run history.”

    $lstSrv = @(get-wmiobject -class “MIIS_RunHistory” -namespace “root\MicrosoftIdentityIntegrationServer” -computer “.”)
    $runDetails = $lstSrv.GetHistory($dateDelete.toString("yyyy-MM-dd"))

    $doc = New-Object System.Xml.XmlDocument
    $doc.LoadXml($runDetails)
    $dateNow = $dateDelete.toString(‘yyyyMMdd’)

    $filePathName = "C:\FIMbackup af runs i sync motor\Runs frem til $dateNow.xml”
    $doc.Save($filePathName)

    Write-Host “Successfully exported run history to: ” $filePathName

    Regards

    Per

    Friday, March 15, 2013 1:12 PM
  • You should get the run history using this line:

    $lstSrv = @(get-wmiobject -class “MIIS_SERVER” -namespace “root\MicrosoftIdentityIntegrationServer” -computer “.”)
    $runHistory = $lstSrv[0].GetHistory($dateDelete.toString(‘yyyy-MM-dd’))

    the $runHistory should now contain objects from the type MIIS_Runhistory


    Need realtime FIM synchronization and advanced reporting? check out the new http://www.imsequencer.com that supports FIM 2010, Omada Identity Manager, SQL, File, AD or Powershell real time synchronization!

    Friday, March 15, 2013 1:28 PM
  • Hi Paul

    Pasted Youre lines into the script.

    Got the error :

    method invocation failed because [System.Management.ManagementObject#root\MicrosoftIdentityIntegrationserver\MIIS_Server] doesn't contain a method named 'GetHistory'.

    In the first line i then changed the "MIIS_SERVER" to "MIIS_Runhistory"  because it looked in the text as what it should be :-)

    But i get almost the same error just that MIIS_Runhistory doesn't contain 'GetHistory'

    method invocation failed because [System.Management.ManagementObject#root\MicrosoftIdentityIntegrationserver\MIIS_RunHistory] doesn't contain a method named 'GetHistory'.

    Do I have to import some modules to get it working or what is missing ?

    Thanks

    Regards

    Per

    Monday, March 18, 2013 12:02 PM
  • Hi,

    I am sorry i have looking something within my own solution, but there is indeed no GetHistory method....

    What you should do is use a query (.NET is using SelectQuery) to select the MIIS_Runhistory using the property RunEndTime to filter.

    Like this:

    $lstSrv = @(get-wmiobject -class “MIIS_RunHistory” -namespace “root\MicrosoftIdentityIntegrationServer” -computer “.”) 

    and add a additional filter like RunEndTime <= 'yyyy-MM-dd hh:mm;ss'

    that will get an arraylist of runhistory elements which you can save to xml.


    Need realtime FIM synchronization and advanced reporting? check out the new http://www.imsequencer.com that supports FIM 2010, Omada Identity Manager, SQL, File, AD or Powershell real time synchronization!

    Monday, March 18, 2013 1:35 PM
  • Hi Paul

    how will that look in the script ?

    I tried this but i did not work (I have also tried with hour-min-sek added to the runendtime) :

    $lstSrv = @(get-wmiobject -class “MIIS_Runhistory” -namespace “root\MicrosoftIdentityIntegrationServer” -computer “.”)
    $runHistory = $lstSrv[0].RunEndTime = '2012-12-15'

    Per

    Monday, March 18, 2013 2:07 PM