Get Fim / Mim MIIS_RunHistory

$UserForestMAName = "AD Source"
$ResourceForestMAName = "AD Destination"
$ResourceForestMADestination2Name = "AD Destination2"

$GetNamespace = Get-WmiObject -Class “MIIS_RunHistory” -Namespace root\MicrosoftIdentityIntegrationServer

# 00 Destination2 Delta Import 
$RunProfileName00 = $GetNamespace[0].RunProfile.ToString()
$RunStatusInfo00 = $GetNamespace[0].RunStatus
$ResourceForestMATradingName+” $RunProfileName00 “+$RunStatusInfo00

# 01 Destination2 Export 
$RunProfileName01 = $GetNamespace[1].RunProfile.ToString()
$RunStatusInfo01 = $GetNamespace[1].RunStatus
$ResourceForestMATradingName+” $RunProfileName01 “+$RunStatusInfo01

# 02 Destination2 Delta Sync 
$RunProfileName02 = $GetNamespace[2].RunProfile.ToString()
$RunStatusInfo02 = $GetNamespace[2].RunStatus
$ResourceForestMATradingName+” $RunProfileName02 “+$RunStatusInfo02

# 03 Destination Delta Import
$RunProfileName03 = $GetNamespace[3].RunProfile.ToString()
$RunStatusInfo03 = $GetNamespace[3].RunStatus
$ResourceForestMAName+” $RunProfileName03 “+$RunStatusInfo03

# 04 Destination Export
$RunProfileName04 = $GetNamespace[4].RunProfile.ToString()
$RunStatusInfo04 = $GetNamespace[4].RunStatus
$ResourceForestMAName+” $RunProfileName04 “+$RunStatusInfo04

# 05 Destination Delta Sync
$RunProfileName05 = $GetNamespace[5].RunProfile.ToString()
$RunStatusInfo05 = $GetNamespace[5].RunStatus
$ResourceForestMAName+” $RunProfileName05 “+$RunStatusInfo05

# 06 Source Delta Sync
$RunProfileName06 = $GetNamespace[6].RunProfile.ToString()
$RunStatusInfo06 = $GetNamespace[6].RunStatus
$UserForestMAName+” $RunProfileName06 “+$RunStatusInfo06

# 07 source Delta Import
$RunProfileName07 = $GetNamespace[7].RunProfile.ToString()
$RunStatusInfo07 = $GetNamespace[7].RunStatus
$ResourceForestMAName+” $RunProfileName07 “+$RunStatusInfo07

# 08 Source Delta Import
$RunProfileName08 = $GetNamespace[8].RunProfile.ToString()
$RunStatusInfo08 = $GetNamespace[8].RunStatus
$UserForestMAName+” $RunProfileName08 “+$RunStatusInfo08

# some variables and files
$jetzt = get-date -uformat "%Y-%m-%d %H:%M:%S"

# Script will send an email at the end. Needed Parameters
$myServer = "$env:computername.$env:userdnsdomain" # Name of the Maschine
$emailFrom = "$myServer <mail adres of the server>" # Servername und Verteilerliste
$emailBetreff = (get-date -uformat %Y-%m-%d)+" Some Run Fimprofiles no Succes."

$emailTo = "mail@domain.come" # testing

$emailServer = "your mail releay server here" # INFO: server that runs script must be allowed in FW, on mailrelay and in McAfee Virus Console outgoing connection to port 25 must be allowed!

# create email
$emailBody = "`r`n $ResourceForestMADestination2Name $RunProfileName00 $RunStatusInfo00`
                 `r`n $ResourceForestMADestination2Name $RunProfileName01 $RunStatusInfo00`
                 `r`n $ResourceForestMADestination2Name $RunProfileName02 $RunStatusInfo00`
                 `r`n $ResourceForestMAName $RunProfileName03 $RunStatusInfo00`
                 `r`n $ResourceForestMAName $RunProfileName04 $RunStatusInfo00`
                 `r`n $ResourceForestMAName $RunProfileName05 $RunStatusInfo00`
                 `r`n $UserForestMAName $RunProfileName06 $RunStatusInfo00`
                 `r`n $ResourceForestMAName $RunProfileName07 $RunStatusInfo00`
                 `r`n $UserForestMAName $RunProfileName08 $RunStatusInfo00`
                  `r`n"

 
If (`
$RunStatusInfo00 -ne "success"`
 -or $RunStatusInfo01 -ne "success"`
 -or $RunStatusInfo02 -ne "success"`
 -or $RunStatusInfo03 -ne "success"`
 -or $RunStatusInfo04 -ne "success"`
 -or $RunStatusInfo05 -ne "success"`
 -or $RunStatusInfo06 -ne "success"`
 -or $RunStatusInfo07 -ne "success"`
  -or $RunStatusInfo08 -ne "success"`
) {Send-MailMessage -From $emailFrom -To $emailTo -Subject $emailBetreff -SmtpServer $emailServer -Body $emailBody}