Skip to content

Instantly share code, notes, and snippets.

@KentNordstrom
Created September 1, 2022 08:30
Show Gist options
  • Save KentNordstrom/89592645223888b19675ae36587b1fc6 to your computer and use it in GitHub Desktop.
Save KentNordstrom/89592645223888b19675ae36587b1fc6 to your computer and use it in GitHub Desktop.
A script to synchronize only selected objects in MIM MetaVerse
<#
.SYNOPSIS
This script serves as example on how to find and run scripted sync on selected objects in MIM.
Queries are run against MetaVerse to find the objects and then it finds the ConnectorSpace object and runs sync.
#>
Import-Module LithnetMIISAutomation
$CStoSync = "ADviaPS" #The name of the ConnectorSpace you want the sync to run in.
#region Queries
<#
Queries is the collection of queries you use to find the MVObjects.
Read https://github.com/lithnet/miis-powershell/wiki/New-MVQuery for details on how to use New-MVQuery
Use UI to validate if needed
#>
[System.Collections.ArrayList]$Queries = @()
[void]$Queries.Add((New-MVQuery -Attribute accountExpire -Operator IsPresent))
[void]$Queries.Add((New-MVQuery -Attribute IAMMasterFlag -Operator Equals -Value true))
#endregion Queries
$MVObjectsToSync = Get-MVObject -Queries $Queries
foreach($MVObject in $MVObjectsToSync){
$CSObjectID = ($MVObject.CSMVLinks | Where-Object{$_.ManagementAgentName -eq $CStoSync}).ConnectorSpaceID
if($CSObjectID){
#We can only run sync if connector is available
$SyncResult = Get-CSObject -ID $CSObjectID -MA $CStoSync | Sync-CSObject -Commit
if($SyncResult.Error){"Error when synchronizing $CSObjectID"}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment