Private-XMLtoPSObject.ps1

Function Convert-XMLtoPSObject
{
    <#
    .SYNOPSIS
        Get Info about the Device group
 
    .DESCRIPTION
        Get Info about the Device group
         
    .PARAMETER Credential
        Specifies a user account that has permission to access to ftp location.
             
    .PARAMETER Server
        Specifies the ftp server you want to connect.
             
    .PARAMETER EnableSsl
        Specifies that an SSL connection should be used.
             
    .PARAMETER ignoreCert
        If you use SSL connection you may ignore certificate error.
             
    .PARAMETER KeepAlive
        Specifies whether the control connection to the ftp server is closed after the request completes.
             
    .PARAMETER UseBinary
        Specifies the data type for file transfers.
             
    .PARAMETER UsePassive
        Behavior of a client application's data transfer process.
 
    .PARAMETER Session
        Specifies a friendly name for the ftp session. Default session name is 'DefaultFTPSession'.
     
    .EXAMPLE
 
        Set-FTPConnection -Credentials userName -Server myftpserver.com
         
    .EXAMPLE
 
        $Credentials = Get-Credential
        Set-FTPConnection -Credentials $Credentials -Server ftp://myftpserver.com -EnableSsl -ignoreCert -UsePassive
 
    .NOTES
        Author: MK
 
    .LINK
        Get-OMEDeviceGroups
    #>
    

    [CmdletBinding(
    )]
    Param(
        [parameter(Mandatory=$true)]
        $xml,
        $ObjectType
    )
    
    Begin
    {
    }
    
    Process
    {
        $obj=@()
        foreach ($item in $xml) {
            $properties=@{}
            if (($($item | Get-Member -MemberType Properties | Measure-Object ).Count -eq 1) -and ($($item | Get-Member -MemberType Properties).TypeName -eq [System.Xml.XmlElement])) {
                $object=Convert-XMLtoPSObject -xml $item.GetEnumerator() -ObjectType "OME.$($item.Name)"
            }
            else {
                foreach ($prop in $item | Get-Member -MemberType Properties) {
                    if ($item."$($prop.Name)" -is [System.Xml.XmlElement]) {
                        $properties."$($prop.Name)"=Convert-XMLtoPSObject -xml $item."$($prop.Name)" -ObjectType "OME.$($prop.Name)"
                    }
                    else {
                        $properties."$($prop.Name)"=$item."$($prop.Name)"
                    }
                }
                $object=New-Object -TypeName PSObject -Property $properties
            }
            if ($ObjectType) {$Object.PsObject.TypeNames.Insert(0,"$ObjectType")}
            $obj+=$object
            if ($ObjectType) {$Obj.PsObject.TypeNames.Insert(0,"$ObjectType")}
        }
        return $obj
    }
    
    End{}                
}