07 January 2016

Convert exported FIM object to a custom PSObject

Function Convert-FimObjectToPSObject {
    Param (
        [parameter(Mandatory=$true, ValueFromPipeline = $true)]
        [Microsoft.ResourceManagement.Automation.ObjectModel.ExportObject]
        $FIMObject
    )
    Process
    {      
        $PSObject = New-Object PSObject

        foreach($Attribute in $FIMObject.ResourceManagementObject.ResourceManagementAttributes){
                if ($Attribute.Value -ne $null) { $Value = $Attribute.Value }
                elseif($Attribute.Values -ne $null)  { $Value = $Attribute.Values  }
                else  { $Value = $null }

                $PSObject | Add-Member -MemberType NoteProperty -Name $Attribute.AttributeName -Value $Value
        }
        Write-Output $PSObject
    }
}

$FIMPSObject = Convert-FimObjectToPSObject -FIMObject $FimGroup
$FIMPSObject

No comments:

Post a Comment