ConvertHashtableToResource

Updated: May 27, 2010

Applies To: Forefront Identity Manager 2010

This is an example of a Windows PowerShell function that converts a hash table into a FIM resource. For more information, see FIM Windows PowerShell Cmdlet Examples.

ConvertHashtableToResource Function

This is an example of a Windows PowerShell function that takes as a parameter a hash table that represents a FIM resource and returns an ExportObject object based on that resource.


function ConvertHashtableToResource
{
    PARAM($Hashtable)
    END
    {
        $DefaultUri = "http://localhost:5725"
        $ExportObject = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ExportObject
        $ExportObject.Source = $DefaultUri
        $ExportObject.ResourceManagementObject = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ResourceManagementObject
        foreach($key in $Hashtable.Keys)
        {
            $value = $Hashtable[$key]
            $newAttribute = New-Object Microsoft.ResourceManagement.Automation.ObjectModel.ResourceManagementAttribute
            $newAttribute.AttributeName = $key
            $newAttribute.Value = $value
            $newAttribute.HasReference = 0
            $newAttribute.IsMultiValue = 0
            
            if($newAttribute.AttributeName -eq "ObjectID")
            {
                $ExportObject.ResourceManagementObject.ObjectIdentifier = $newAttribute.Value
            }
            
            if($newAttribute.AttributeName -eq "ObjectType")
            {
                $ExportObject.ResourceManagementObject.ObjectType = $newAttribute.Value
            }
            
            $ExportObject.ResourceManagementObject.IsPlaceholder = 0
            
            if($ExportObject.ResourceManagementObject.ResourceManagementAttributes -eq $null)
            {
                $ExportObject.ResourceManagementObject.ResourceManagementAttributes = (,$newAttribute)
            }
            else
            {
                $ExportObject.ResourceManagementObject.ResourceManagementAttributes += $newAttribute
            }
        }
        $ExportObject
    }
}

Remarks

This function can convert a hash table into a resource if the hash table was created by using the ConvertResourceToHashtable function. You can use this function as a helper function in a Windows PowerShell script that performs bulk export operations from the FIM Service database.

See Also

Community Additions

ADD
Show: