FIM ScriptBox Item

Summary

This script will delete all users from the Portal except for the Administrator and Built-In Sync Account. This should only be used in test environments when you want to clear things out and start over.

Script Code

001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
#----------------------------------------------------------------------------------------------------------
 set-variable -name URI -value "http://localhost:5725/resourcemanagementservice' "
 set-variable -name ADMINGUID -value "7fb2b853-24f0-4498-9534-4e10589723c4"
 set-variable -name SYNCGUID -value "fb89aefa-5ea1-47f1-8890-abe7797d6497"
#----------------------------------------------------------------------------------------------------------
 function DeleteObject
 {
    PARAM($objectType, $objectId)
    END
    {
       $importObject = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ImportObject
       $importObject.ObjectType = $objectType
       $importObject.TargetObjectIdentifier = $objectId
       $importObject.SourceObjectIdentifier = $objectId
       $importObject.State = 2 
       $importObject | Import-FIMConfig -uri $URI
     } 
 }
#----------------------------------------------------------------------------------------------------------
 if(@(get-pssnapin | where-object {$_.Name -eq "FIMAutomation"} ).count -eq 0) {add-pssnapin FIMAutomation}
 $allobjects = export-fimconfig -uri $URI `
                                –onlyBaseResources `
                                -customconfig "/Person"
 $allobjects | Foreach-Object {
    $objectId = (($_.ResourceManagementObject.ObjectIdentifier).split(":"))[2]
    if($objectID -eq $ADMINGUID)
    {write-host "Administrator NOT deleted"}
    elseif($objectID -eq $SYNCGUID)
    {write-host "Built-in Synchronization Account NOT deleted"}

    else { 
      DeleteObject -objectType "Person" `
                  -objectId $objectId
      write-host "`nObject deleted`n"}
 }

 

note Note
To provide feedback about this script, create a post on the FIM TechNet Forum.
For more FIM related Windows PowerShell scripts, see the FIM ScriptBox.

 



See Also