Commands/Remove-OpenPackage.ps1

function Remove-OpenPackage {
    <#
    .SYNOPSIS
        Removes parts from an open package
    .DESCRIPTION
        Removes content parts from an open package.
    .LINK
        Get-OpenPackage
    .LINK
        Select-OpenPackage
    .EXAMPLE
        Get-OpenPackage @{
            "a.html" = "<h1>a html file</h1>"
        } |
            Remove-OpenPackage -Uri '/a.html'
    .EXAMPLE
        Get-OpenPackage @{
            "a.html" = "<h1>a html file</h1>"
            "a.css" = "body { max-width: 100vw; height: 100vh}"
        } |
            Select-OpenPackage -Include *.html |
            Remove-OpenPackage
    #>

    [CmdletBinding(SupportsShouldProcess,ConfirmImpact='High')]
    [Alias('Remove-OP','rop','rOpenPackage')]
    param(
    # One or more URIs to remove
    [Parameter(ValueFromPipelineByPropertyName)]
    [Uri[]]
    $Uri,

    # The input object.
    # If this is not a package, the input will be passed thru and nothing will be removed.
    [Parameter(ValueFromPipeline,ValueFromPipelineByPropertyName)]
    [Alias('Package')]
    [PSObject]
    $InputObject
    )

    process {
        # If the input object is not a package,
        if ($InputObject -isnot [IO.Packaging.Package]) {
            # look for a property named package
            if ($inputObject.Package -is [IO.Packaging.Package]) {
                # and use that as our input.
                $inputObject = $inputObject.Package
            } else {
                # Otherwise, pass thru the input.
                return $InputObject
            }            
        }
        
        foreach ($part in @($InputObject.GetParts())) {
            # If -WhatIf was passed, return the part
            if ($whatIfPreference) {
                $part
                continue
            }

            # If the part uri is in the list of uris
            if ($part.Uri -in $Uri -and 
                # and we confirmed our intention to delete it
                $PSCmdlet.ShouldProcess("Remove $Uri")
            ) {
                # delete the part.
                $InputObject.DeletePart($part.Uri)
            }
        }

        $InputObject
    }
}