Skip to content

Breaking down the size of a FIM Service query with PowerShell

When trying to perform bulk operations against objects in FIM from PowerShell you can run into some pretty slow and heavy going queries. This little snippet shows how you can loop through each letter of the alphabet as a way to reduce the size of the batch of objects you deal with in one go.

$i = 65
do
{
    $c = [char]$i

    $filter = "/Person[starts-with(DisplayName,'{0}')]" -f $c
    $objs = export-fimconfig -CustomConfig $filter -OnlyBaseResources

    foreach ($obj in $objs)
    {
        whatever you need to do
    }

    $i += 1

} while ($i -lt 91)

{ 2 } Comments

  1. Joe Leibowitz | March 8, 2013 at 6:43 pm | Permalink

    Hi Carol,

    The code below uses your ideas but goes three levels deep to start with, e.g., ‘Aba’ rather than ‘A’. So that even in a very large environment, results begin to show up early:

    $i = 65
    do
    {
        $c = [char]$i
        $j = 65
        do
        {
        	$c2 = [char]$j
            $k = 65
                do
                {
                    $c3 = [char]$k
        	        $first_three = $c + $c2 + $c3
                    $first_three_display = $c.ToString().ToUpper() + $c2.ToString().ToLower() +
                        $c3.ToString().ToLower()
                    write-host $first_three.ToString().ToLower()
                    Write-host $first_three_display
        	        $filter = "/Person[starts-with(AccountName,'{0}')]" -f $first_three.ToString().ToLower()
        	        #$filter = "/Person[starts-with(DisplayName,'{0}')]" -f $first_three_display
    
                    $objs = export-fimconfig -uri $URI -CustomConfig $filter -OnlyBaseResources
    
        	        foreach ($obj in $objs)
        	        {
                        #whatever you need to do
                        for($u = 0; $u -lt 10; $u +=1)
                        {
                        write-host 
                          $obj.ResourceManagementObject.ResourceManagementAttributes[$u].AttributeName + ': ' +
                          $obj.ResourceManagementObject.ResourceManagementAttributes[$u].Value
        	            }
                        write-host "`r`n`r`n"
                    }
         $k +=1
                 } while ($k -lt 91)
    
         $j += 1
    
        } while ($j -lt 91)
    
         $i += 1
    
    } while ($i -lt 91)
  2. Carol | March 8, 2013 at 8:49 pm | Permalink

    Awesome! Thanks for sharing.

Post a Comment

Your email is never published nor shared. Required fields are marked *

Spam comments will be blocked by Akismet

*

best finpecia online pill where buy Lisinopril purchasing finpecia with overnight delivery Lisinopril overnight cod buy Premarin online free fedex delivery Premarin cheap order rx metformin cheapest place to buy Metformin purchase Metformin online buy Alli no prescription low cost uk order Metformin Metformin online Maxalt no prescription needed 10mg Maxalt 10mg canada where to buy Maxalt uk buy mail order Metformin buy low cost Metformin buy Alli canada buy generic Maxalt canada Premarin online buy generic Maxalt australia Maxalt without a rx buy Premarin 0.625 mg buy metformin cod Metformin order online pharmacy Metformin how to buy Metformin without a prescription Metformin price buy Alli without prescription