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 Replies to “Breaking down the size of a FIM Service query with PowerShell”

  1. 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)

Leave a Reply

Your email address will not be published. Required fields are marked *


*