Functions/Internal/Remove-ClusterLibrariesMetaDataAsPSObject.ps1

function Remove-ClusterLibrariesMetaDataAsPSObject {
    [CmdletBinding()]
    param ( 
        [Parameter(  
            Position = 0,   
            Mandatory = $true,   
            ValueFromPipeline = $true,  
            ValueFromPipelineByPropertyName = $true  
        )] [PSObject]$customObject
    );

    process {
        [array]$objectArray = $null
    
        # $object = @{ egg = 'dbfs:/FileStore/jars/kinship_engineering_0_81_py3_7.egg' }
        # [array] $objectArray += $object

        foreach ($lib in $customObject.library_statuses | Where-Object { $_.is_library_for_all_clusters -eq $false }) {

            if ($lib.library.pypi) {
                $object = New-Object -TypeName PSObject
                $object = @{ pypi = @{package = $lib.library.pypi.package 
                        repo                  = $lib.library.pypi.repo
                    } 
                }
                [array] $objectArray += $object
            }

            if ($lib.library.egg) {
                $object = New-Object -TypeName PSObject
                $object = @{ egg = $lib.library.egg }
                [array] $objectArray += $object
            }
            if ($lib.library.whl) {
                $object = New-Object -TypeName PSObject
                $object = @{ whl = $lib.library.whl }
                [array] $objectArray += $object
            }
            if ($lib.library.jar) {
                $object = New-Object -TypeName PSObject
                $object = @{ whl = $lib.library.jar }
                [array] $objectArray += $object
            }

            if ($lib.library.maven) {
                $object = New-Object -TypeName PSObject
                $object = @{ maven = @{coordinates = $lib.library.maven.coordinates
                        repo                       = $lib.library.maven.repo
                        exclusions                 = $lib.library.maven.exclusions
                    } 
                }
                [array] $objectArray += $object
            }
            if ($lib.library.cran) {
                $object = New-Object -TypeName PSObject
                $object = @{ cran = @{package = $lib.library.cran.package 
                        repo                  = $lib.library.cran.repo
                    } 
                }
                [array] $objectArray += $object
            }
        }

        $customObject.PSObject.Properties.Remove('library_statuses')
        $customObject | Add-Member -NotePropertyValue $objectArray -NotePropertyName libraries
        return $customObject
    }
}