So,
A long time ago I wrote a post showing how you can do Composite write-back to FIMService via Powershell. That used “Search-ResourcePaged” command from the Lithnet Module. But it’s not helpful in the scenario where you already have a list of users (say an exported CSV or a text file) you want to perform some action on. In that scenario, XPath is not needed (and might not help if there is no pattern to search) as you already have your objects to work on.
So say, for example, I have a list of 10000 objectID from FIM and want to delete them.
Simple way will be
1 2 3 4 5 6 7 8 9 10 11 12 |
$objects = ("objectID1", "objectID2", "objectID3" ........) $i = 0 foreach ($obj in $objects) { Remove-Resource $obj $i++ write-host "Done $i of" $objects.count } |
Pretty simple but will take about 1/sec and take 10000 seconds to do it.
Yeah I am not going to wait that long…
Did some RnD (and Google) and found some different ways of going about it..
One way was doing ForEach -Parallels flag. I tried it but actually had a reverse affect for me… I did it wrong obviously.. It worked but took long/er for some reason (Even with -throttlelimit set)… Moved on… Went above my head for the limited time I had to do the job.
Then found a pretty simple way to do it online and made some modification to suit my scenario
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
$objects = ("objectID1", "objectID2", "objectID3", .........) for($i = 0; $i -lt $objects.Count; $i += 1000) #Change 1000 to the number you want to process in a single batch { $num = $i + 999 #Change this number to 1 less that the batch number if ($num -ge $objects.Count) { $num = $objects.Count } $newarray = $objects[$i..$num] Remove-Resource $newarray #Delete the Resource from FIMService or you can do any other action like foreach for the $newarray and do a Get-Resource and modify and then save after the loop is over Write-Host "No of Objects in the batch:" $newarray.Count Write-Host "Done $num of" $objects.Count -ForegroundColor Cyan } |
Voila!!! it’s done in seconds. It will send batch of 1000 objects at a time to FIMService as a composite request and do them quickly. I did like 10000 in 10-15 seconds or so. You can also import a csv/txt file and create an array as well.
I am not a powershell expert and it may not be perfect or most elegant way of doing it but gets the job done quickly.
You can use the logic for virtually anything and not just to write back to FIMService. But yeah helped me to do large modifications / deletes pretty quickly.
Till the next time…
0 Comments