Commands/Export-OpenPackage.ps1
|
function Export-OpenPackage { <# .SYNOPSIS Exports OpenPackage packages .DESCRIPTION Exports loaded packages to a file or directory. #> [Alias( 'Export-OP','epop','epOpenPackage', 'Save-OpenPackage','Save-OP','svop', 'svOpenPackage' )] param( # The package file path. # If this has no extension, it will be considered a directory name. # If the path already exists and is a directory, it will be considered a directory name. [Parameter(Mandatory,ValueFromPipelineByPropertyName)] [Alias('Path','FilePath','Fullname')] [string] $DestinationPath, <# Includes the specified parts. Enter a wildcard pattern, such as `*.txt` #> [ValidateNotNullOrEmpty()] [SupportsWildcards()] [string[]] $Include, <# Excludes the specified parts. Enter a wildcard pattern, such as `*.txt` #> [ValidateNotNullOrEmpty()] [SupportsWildcards()] [string[]] $Exclude, <# Includes the specified content types. Enter a wildcard pattern, such as `text/*` #> [ValidateNotNullOrEmpty()] [SupportsWildcards()] [string[]] $IncludeContentType, # The input object. # This must be a package loaded with this module. [Parameter(ValueFromPipeline)] [Alias('Package')] [PSObject] $InputObject, # If set, will force the export even if a file already exists. [switch] $Force ) process { # If there is no input return if (-not $InputObject) { return } # If the input is not a package, pass it thru if ($InputObject -isnot [IO.Packaging.Package]) { return $InputObject } # Get the item if it already exists $destinationItem = Get-Item $DestinationPath -ErrorAction Ignore # Copy parameters to simply any future debugging. $parameterCopy = [Ordered]@{} + $PSBoundParameters if ( # If the destination is a directory ($destinationItem -is [IO.DirectoryInfo]) -or # Or the last segment has no extension. (@($DestinationPath -split '[\\/]' -ne '')[-1] -notlike '*.*') ) { # install the open package into that directory. Install-OpenPackage @parameterCopy -PassThru } else { # Otherwise, copy the package to that path $copiedPackage = Copy-OpenPackage @parameterCopy # Get the output item $outputFile = Get-Item $DestinationPath # and add the package to the file. $outputFile | Add-Member NoteProperty Package $copiedPackage -Force -PassThru } } } |