Share via


[SUPPORT TIP] How to delete a single group from the Identity Management Portal using PowerShell

PURPOSE

The purpose of this blog is to illustrate how to delete a single group in the FIM Portal.

SCRIPT

#----------------------------------------------------------------------------------------------------------

set-variable -name URI -value "http://localhost:5725/resourcemanagementservice' " -option constant

#----------------------------------------------------------------------------------------------------------

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}

clear-host

if($args.count -ne 1) {throw "Missing name parameter"}

$objectName = $args[0]

if(0 -eq [String]::Compare($objectName,"administrator", $true))

{throw "You can't delete administrator"}

if(0 -eq [String]::Compare($objectName,"Built-in Synchronization Account", $true))

{throw "You can't delete Built-in Synchronization Account"}

$exportObject = export-fimconfig -uri $URI `

–onlyBaseResources `

-customconfig "/Group[DisplayName='$objectName']"

if($exportObject -eq $null) {throw "L:Object not found"}

$objectId = (($exportObject.ResourceManagementObject.ObjectIdentifier).split(":"))[2]

DeleteObject -objectType "Group" `

-objectId $objectId

write-host "`nObject Deleted successfully`n"

#----------------------------------------------------------------------------------------------------------

trap

{

$exMessage = $_.Exception.Message

if($exMessage.StartsWith("L:"))

{write-host "`n" $exMessage.substring(2) "`n" -foregroundcolor white -backgroundcolor darkblue}

else {write-host "`nError: " $exMessage "`n" -foregroundcolor white -backgroundcolor darkred}

Exit

}

#----------------------------------------------------------------------------------------------------------

Comments

  • Anonymous
    July 26, 2016
    Or, if you can use 3rd party software - try the Lithnet PowerShell module for FIM/MIM Service (https://github.com/lithnet/resourcemanagement-powershell) and do it in a couple of linesimport-module LithnetRMARemove-Resource | Get-Resource -ObjectType Group -AttributeName DisplayName -AttributeValue "MyGroup"