%3CLINGO-SUB%20id%3D%22lingo-sub-972395%22%20slang%3D%22en-US%22%3ERun%20Profile%20Script%20Builder%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-972395%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Sep%2024%2C%202014%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EThe%20Following%20script%20can%20be%20used%20to%20build%20a%20basic%20Run%20Profile%20Script%20around%20your%20current%20environment.%20Included%20in%20run%20profile%20script%20that%20is%20built%20for%20you%20is%20a%20method%20for%20a%20single%20run%20profile%20script%20to%20run%20Delta%20Import%20sync%26nbsp%3Bduring%20the%20week%20and%20the%20first%20run%20every%20Saturday%20would%20be%20a%20Full%20Sync%20Cycle%26nbsp%3Band%26nbsp%3Ba%20delta%20every%20sync%20after.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThere%20are%202%20Files%20required%20to%20build%20your%20Basic%20Run%20Profile%20Script.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1.%20The%20MAScriptCreator.ps1%20file%20which%20does%20a%20WMI%20call%20to%20gather%20the%20Management%20Agents%20which%20are%20defined%20in%20the%20WMI%20Namespace.%20The%20script%20than%20builds%20the%20script%20using%20the%20MAScript.txt%20file.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2.%20The%20MAScript.txt%20file%20is%20use%20as%20a%20base%20file%20for%20the%20MAScriptCreator.ps1%20file.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBoth%20files%20can%20be%20found%20in%20the%20attached%20ZIP%20File%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20style%3D%22text-decoration%3A%20underline%3B%20background-color%3A%20%23ffff00%3B%22%3E%20%3CSTRONG%3E%20MAScript.ps1%20%3C%2FSTRONG%3E%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Efunction%20Get-ScriptDirectory%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24Invocation%20%3D%20(Get-Variable%20MyInvocation%20-Scope%201).Value%20%3CBR%20%2F%3ESplit-Path%20%24Invocation.MyCommand.Path%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3E%24dir%20%3D%20Get-ScriptDirectory%20%3CBR%20%2F%3E%24input%20%3D%20%5BSystem.IO.File%5D%3A%3AReadAllText(%22%24dir%5CMAScript.txt%22)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23%23%24names%20%3D%20get-wmiObject%20where%20-query%20%3D%20%22Select%26nbsp%3B%20*%20from%20MIIS_ManagementAgent%22%20-Namespace%20%22root%2Fmicrosoftidentityintegrationserver%22%20%7C%20select%20Name%20%3CBR%20%2F%3E%24names%20%3Dget-wmiObject%20-query%20%22Select%26nbsp%3B%20*%20from%20MIIS_ManagementAgent%22%20-Namespace%20%22root%2Fmicrosoftidentityintegrationserver%22%20%7C%20select%20Name%20%3CBR%20%2F%3E%24sb%20%3D%20New-Object%20System.Text.StringBuilder%20%3CBR%20%2F%3Eforeach(%24name%20in%20%24names)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24sb.Append('%22')%20%3CBR%20%2F%3E%24sb.Append(%24name.Name)%20%3CBR%20%2F%3E%24sb.Append('%22')%20%3CBR%20%2F%3E%24sb.Append('%2C%20')%20%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24sb.Length%20%3D%20%24sb.Length%20-%202%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24input%20%3D%20%24input.Replace(%22%5BMANAMES%5D%22%2C%20%24sb.ToString())%20%3CBR%20%2F%3Eecho%20%24input%20%26gt%3B%20%22MyNewMAScript.ps1%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20style%3D%22text-decoration%3A%20underline%3B%20background-color%3A%20%2300ffff%3B%22%3E%20%3CSTRONG%3E%20MAScript.txt%20%3C%2FSTRONG%3E%20%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20PARAMETERS%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24params_ComputerName%20%3D%20%22.%22%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23%20%22.%22%20is%20the%20current%20computer%20%3CBR%20%2F%3E%24params_delayBetweenExecs%20%3D%205%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23delay%20between%20each%20execution%2C%20in%20seconds%20%3CBR%20%2F%3E%24params_numOfExecs%20%3D%201%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%23Number%20of%20executions%200%20for%20infinite%20%3CBR%20%2F%3E%24params_keepRunHistoryDays%20%3D%207%26nbsp%3B%20%26nbsp%3B%23Number%20of%20days%20to%20keep%20Run%20History%20%3CBR%20%2F%3E%24params_runProfilesOrder%20%3D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24MAS%20%3D%20%40(%5BMANAMES%5D)%20%3CBR%20%2F%3E%24FullCycleprofilesToRun%20%3D%20%40(%22FI%22%2C%20%22FS%22%2C%20%22EX%22%2C%20%22DI%22)%20%3CBR%20%2F%3E%24DeltaCycleprofilesToRun%20%3D%20%40(%22DI%22%2C%20%22DS%22%2C%20%22EX%22%2C%20%22DI%22)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20FUNCTIONS%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24line%20%3D%20%22-----------------------------%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Efunction%20Write-Output-Banner(%5Bstring%5D%24msg)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3EWrite-Output%20%24line%2C(%22-%20%22%2B%24msg)%2C%24line%20%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Efunction%20Clear-Run-History%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%23--------------------------------------------------------------------------------------------------------------------%20%3CBR%20%2F%3EClear-Host%20%3CBR%20%2F%3E%24DeleteDay%20%3D%20Get-Date%20%3CBR%20%2F%3E%24DayDiff%20%3D%20New-Object%20System.TimeSpan%20%24params_keepRunHistoryDays%2C%200%2C%200%2C%200%2C%200%20%3CBR%20%2F%3E%24DeleteDay%20%3D%20%24DeleteDay.Subtract(%24DayDiff)%20%3CBR%20%2F%3E%3CBR%20%2F%3EWrite-Host%20%22%22%20%3CBR%20%2F%3EWrite-Host%20%22Deleting%20run%20history%20earlier%20than%20or%20equal%20to%3A%22%20%24DeleteDay.toString('MM%2Fdd%2Fyyyy')%20%3CBR%20%2F%3E%24lstSrv%20%3D%20%40(get-wmiobject%20-class%20%22MIIS_SERVER%22%20-namespace%20%22root%5CMicrosoftIdentityIntegrationServer%22%20-computer%20%22.%22)%20%3CBR%20%2F%3EWrite-Host%20%22Result%3A%20%22%20%24lstSrv%5B0%5D.ClearRuns(%24DeleteDay.toString('yyyy-MM-dd')).ReturnValue%20%3CBR%20%2F%3EWrite-Host%20%22%22%20%3CBR%20%2F%3E%23--------------------------------------------------------------------------------------------------------------------%20%3CBR%20%2F%3ETrap%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3EWrite-Host%20%22%60nError%3A%20%24(%24_.Exception.Message)%60n%22%20-foregroundcolor%20white%20-backgroundcolor%20darkred%20%3CBR%20%2F%3EExit%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3E%23--------------------------------------------------------------------------------------------------------------------%20%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Efunction%20Get-IsSomebodyRunning%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3Eforeach(%24maName%20in%20%24MAS)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24MA%20%3D%20%24maObjects%20%7C%20%3F%20%7B%24_.Name%20-eq%20%24maName%7D%20%3CBR%20%2F%3E%24myMas%20%2B%3D%20%24MA%20%3CBR%20%2F%3Eif(%24MA%20-ne%20%24null)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24MARunStatus%20%3D%20%24MA.RunStatus()%20%3CBR%20%2F%3EIf%20(%24MARunStatus.ReturnValue%20-eq%20%22in-progress%22)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3EWrite-Host%20%22%24MA.Name%20is%20running%22%20%3CBR%20%2F%3Ereturn%20%24true%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20DATA%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%24numOfExecDone%20%3D%200%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%23%20PROGRAM%20%3CBR%20%2F%3E%23%23%23%23%23%23%23%23%23%23%23%23%20%3CBR%20%2F%3E%24maObjects%20%3D%20get-wmiObject%20-query%20%22Select%26nbsp%3B%20*%20from%20MIIS_ManagementAgent%22%20-Namespace%20%22root%2Fmicrosoftidentityintegrationserver%22%20%3CBR%20%2F%3E%24myMas%20%3D%20%40()%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Ewhile(Get-IsSomebodyRunning%20-eq%20%24true)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3EStart-Sleep%2010%20%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EClear-Run-History%20%3CBR%20%2F%3Edo%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3EWrite-Output-Banner(%22Execution%20%23%3A%22%2B(%2B%2B%24numOfExecDone))%20%3CBR%20%2F%3Eforeach(%24MA%20in%20%24myMas)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3Eif(%24MA%20-ne%20%24null)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3EWrite-Output-Banner(%22MA%3A%20%22%2B%24maName)%20%3CBR%20%2F%3E%24date%20%3D%20%5BDateTime%5D%3A%3ANow%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24file%20%3D%20Get-ChildItem%20%22lastRun.txt%22%20-EA%20SilentlyContinue%20%3CBR%20%2F%3Eif(%24file%20-ne%20%24null)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24lastRun%20%3D%20%5BDateTime%5D%3A%3AParse(%5BSystem.IO.File%5D%3A%3AReadAllText(%22lastRun.txt%22))%20%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24needsFullImort%20%3D%20%24file%20-eq%20%24null%20-or%20%24lastRun.Date%20-lt%20%5BDateTime%5D%3A%3ANow.AddDays(-6)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eif(%24date.DayOfWeek%20-eq%20%22Saturday%22%20-and%20%24needsFullImort)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24profilesToRun%20%3D%20%24FullCycleprofilesToRun%20%3CBR%20%2F%3E%24dateString%20%3D%20%5BDateTime%5D%3A%3ANow.Date.ToString()%20%3CBR%20%2F%3Eecho%20%24dateString%20%26gt%3B%20%22lastRun.txt%22%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3Eelse%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24profilesToRun%20%3D%20%24DeltaCycleprofilesToRun%20%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%24maType%20%3D%20%24MA.Type%20%3CBR%20%2F%3E%23Do%20something%20with%20this%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eforeach(%24profileName%20in%20%24profilesToRun)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3EWrite-Output%20(%22%20%22%2B%24profileName)%2C%22%26nbsp%3B%20-%26gt%3B%20starting%22%20%3CBR%20%2F%3E%24datetimeBefore%20%3D%20Get-Date%3B%20%3CBR%20%2F%3E%24result%20%3D%20%24MA.Execute(%24profileName)%3B%20%3CBR%20%2F%3E%24datetimeAfter%20%3D%20Get-Date%3B%20%3CBR%20%2F%3E%24duration%20%3D%20%24datetimeAfter%20-%20%24datetimeBefore%3B%20%3CBR%20%2F%3Eif(%22success%22.Equals(%24result.ReturnValue))%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24msg%20%3D%20%22done.%20Duration%3A%20%22%2B%24duration.Hours%2B%22%3A%22%2B%24duration.Minutes%2B%22%3A%22%2B%24duration.Seconds%20%3CBR%20%2F%3E%7D%20else%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3E%24msg%20%3D%20%22Error%3A%20%22%2B%24result%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3EWrite-Output%20(%22%26nbsp%3B%20-%26gt%3B%20%24msg%22)%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3Eelse%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3EWrite-Output%20(%22Not%20found%20MA%20type%20%3A%22%2B%24maName)%3B%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3E%7D%20%3CBR%20%2F%3E%3CBR%20%2F%3E%24continue%20%3D%20(%24params_numOfExecs%20-EQ%200)%20-OR%20(%24numOfExecDone%20-lt%20%24params_numOfExecs)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3Eif(%24continue)%20%3CBR%20%2F%3E%7B%20%3CBR%20%2F%3EWrite-Output-Banner(%22Sleeping%20%22%2B%24params_delayBetweenExecs%2B%22%20seconds%22)%20%3CBR%20%2F%3EStart-Sleep%20-s%20%24params_delayBetweenExecs%20%3CBR%20%2F%3E%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%7D%20%3CBR%20%2F%3Ewhile(%24continue)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%23%23%20%3CA%20href%3D%22http%3A%2F%2Fblogs.msdn.com%2Fconnector_space%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20http%3A%2F%2Fblogs.msdn.com%2Fconnector_space%20%3C%2FA%3E%20%23%23%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CA%20href%3D%22https%3A%2F%2Fmsdnshared.blob.core.windows.net%2Fmedia%2FMSDNBlogsFS%2Fprod.evol.blogs.msdn.com%2FCommunityServer.Components.PostAttachments%2F00%2F10%2F56%2F03%2F29%2FRunProfiler.zip%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3E%20RunProfiler.zip%20%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-972395%22%20slang%3D%22en-US%22%3E%3CP%3EFirst%20published%20on%20MSDN%20on%20Sep%2024%2C%202014%20The%20Following%20script%20can%20be%20used%20to%20build%20a%20basic%20Run%20Profile%20Script%20around%20your%20current%20environment.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-972395%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAnthonyMarsiglia%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

First published on MSDN on Sep 24, 2014

The Following script can be used to build a basic Run Profile Script around your current environment. Included in run profile script that is built for you is a method for a single run profile script to run Delta Import sync during the week and the first run every Saturday would be a Full Sync Cycle and a delta every sync after.

 

There are 2 Files required to build your Basic Run Profile Script.

 

1. The MAScriptCreator.ps1 file which does a WMI call to gather the Management Agents which are defined in the WMI Namespace. The script than builds the script using the MAScript.txt file.

 

2. The MAScript.txt file is use as a base file for the MAScriptCreator.ps1 file.

 

Both files can be found in the attached ZIP File

 

MAScript.ps1

 

function Get-ScriptDirectory
{
$Invocation = (Get-Variable MyInvocation -Scope 1).Value
Split-Path $Invocation.MyCommand.Path
}
$dir = Get-ScriptDirectory
$input = [System.IO.File]::ReadAllText("$dir\MAScript.txt")

 

##$names = get-wmiObject where -query = "Select  * from MIIS_ManagementAgent" -Namespace "root/microsoftidentityintegrationserver" | select Name
$names =get-wmiObject -query "Select  * from MIIS_ManagementAgent" -Namespace "root/microsoftidentityintegrationserver" | select Name
$sb = New-Object System.Text.StringBuilder
foreach($name in $names)
{
$sb.Append('"')
$sb.Append($name.Name)
$sb.Append('"')
$sb.Append(', ')
}

 

$sb.Length = $sb.Length - 2

 

$input = $input.Replace("[MANAMES]", $sb.ToString())
echo $input > "MyNewMAScript.ps1"

 

 

 

MAScript.txt

 

############
# PARAMETERS
############

 

$params_ComputerName = "."          # "." is the current computer
$params_delayBetweenExecs = 5       #delay between each execution, in seconds
$params_numOfExecs = 1              #Number of executions 0 for infinite
$params_keepRunHistoryDays = 7   #Number of days to keep Run History
$params_runProfilesOrder =

 

$MAS = @([MANAMES])
$FullCycleprofilesToRun = @("FI", "FS", "EX", "DI")
$DeltaCycleprofilesToRun = @("DI", "DS", "EX", "DI")

 

############
# FUNCTIONS
############

 

$line = "-----------------------------"

 

function Write-Output-Banner([string]$msg)
{
Write-Output $line,("- "+$msg),$line
}

 

function Clear-Run-History
{
#--------------------------------------------------------------------------------------------------------------------
Clear-Host
$DeleteDay = Get-Date
$DayDiff = New-Object System.TimeSpan $params_keepRunHistoryDays, 0, 0, 0, 0
$DeleteDay = $DeleteDay.Subtract($DayDiff)

Write-Host ""
Write-Host "Deleting run history earlier than or equal to:" $DeleteDay.toString('MM/dd/yyyy')
$lstSrv = @(get-wmiobject -class "MIIS_SERVER" -namespace "root\MicrosoftIdentityIntegrationServer" -computer ".")
Write-Host "Result: " $lstSrv[0].ClearRuns($DeleteDay.toString('yyyy-MM-dd')).ReturnValue
Write-Host ""
#--------------------------------------------------------------------------------------------------------------------
Trap
{
Write-Host "`nError: $($_.Exception.Message)`n" -foregroundcolor white -backgroundcolor darkred
Exit
}
#--------------------------------------------------------------------------------------------------------------------
}

 

function Get-IsSomebodyRunning
{
foreach($maName in $MAS)
{
$MA = $maObjects | ? {$_.Name -eq $maName}
$myMas += $MA
if($MA -ne $null)
{
$MARunStatus = $MA.RunStatus()
If ($MARunStatus.ReturnValue -eq "in-progress")
{
Write-Host "$MA.Name is running"
return $true
}
}
}
}

 

############
# DATA
############
$numOfExecDone = 0
############
# PROGRAM
############
$maObjects = get-wmiObject -query "Select  * from MIIS_ManagementAgent" -Namespace "root/microsoftidentityintegrationserver"
$myMas = @()

 

while(Get-IsSomebodyRunning -eq $true)
{
Start-Sleep 10
}

 

Clear-Run-History
do
{
Write-Output-Banner("Execution #:"+(++$numOfExecDone))
foreach($MA in $myMas)
{
if($MA -ne $null)
{
Write-Output-Banner("MA: "+$maName)
$date = [DateTime]::Now

 

$file = Get-ChildItem "lastRun.txt" -EA SilentlyContinue
if($file -ne $null)
{
$lastRun = [DateTime]::Parse([System.IO.File]::ReadAllText("lastRun.txt"))
}

 

$needsFullImort = $file -eq $null -or $lastRun.Date -lt [DateTime]::Now.AddDays(-6)

 

if($date.DayOfWeek -eq "Saturday" -and $needsFullImort)
{
$profilesToRun = $FullCycleprofilesToRun
$dateString = [DateTime]::Now.Date.ToString()
echo $dateString > "lastRun.txt"
}
else
{
$profilesToRun = $DeltaCycleprofilesToRun
}

 

$maType = $MA.Type
#Do something with this

 

foreach($profileName in $profilesToRun)
{
Write-Output (" "+$profileName),"  -> starting"
$datetimeBefore = Get-Date;
$result = $MA.Execute($profileName);
$datetimeAfter = Get-Date;
$duration = $datetimeAfter - $datetimeBefore;
if("success".Equals($result.ReturnValue))
{
$msg = "done. Duration: "+$duration.Hours+":"+$duration.Minutes+":"+$duration.Seconds
} else
{
$msg = "Error: "+$result
}
Write-Output ("  -> $msg")
}
}
else
{
Write-Output ("Not found MA type :"+$maName);
}
}

$continue = ($params_numOfExecs -EQ 0) -OR ($numOfExecDone -lt $params_numOfExecs)

 

if($continue)
{
Write-Output-Banner("Sleeping "+$params_delayBetweenExecs+" seconds")
Start-Sleep -s $params_delayBetweenExecs
}

 

}
while($continue)

 

 

 

## http://blogs.msdn.com/connector_space ##

 

RunProfiler.zip