Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A script to synchronize only selected objects in MIM MetaVerse
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 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
#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