GitHub Icon Image
GitHub

Download sppkgs from App Catalog

Summary

Download all packages from the App Catalog.

  • PnP PowerShell

param (
  [Parameter(Mandatory = $true)]
  [string]$url,
  [Parameter(Mandatory = $true)]
  [string]$appCatalog,
  [Parameter(Mandatory = $true)]
  [string]$username,
  [Parameter(Mandatory = $true)]
  [string]$password
)

Clear-Host
Write-Progress -activity "Downloading packages..." -status "downloading" -PercentComplete 0

# Connect
$psw = ConvertTo-SecureString -String $password -AsPlainText -Force
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $username, $psw
Connect-PnPOnline -Url $url -Credentials $credentials

Try {
  $list = Get-PnPList -Identity $appCatalog
  $folder = Get-PnPFolder -RelativeUrl $appCatalog
  $props = Get-PnPProperty -ClientObject $folder -Property Files
  $destinationfolder = ".\pkg"

  if (!(Test-Path -path $destinationfolder)) {
    $newItem = New-Item $destinationfolder -type directory
  }

  $item = Get-ChildItem -Path $destinationfolder -Include *.* -File -Recurse | ForEach-Object { $_.Delete() }
  $total = $folder.Files.Count

  For ($i = 0; $i -lt $total; $i++) {
    $file = $folder.Files[$i]
    $fileName = $file.Name
    $extn = [IO.Path]::GetExtension($file.Name)

    if ($extn -eq ".sppkg" ) {
      Write-Progress -activity "Downloading packages..." -status "downloading $fileName" -PercentComplete (($i / $total) * 100)
      $f = Get-PnPFile -ServerRelativeUrl $file.ServerRelativeUrl -Path $destinationfolder -FileName $file.Name -AsFile
    }
  }
}
Catch {
  Write-host -f Red "Error downloading packages:" $_.Exception.Message
}

Write-Host ("PACKAGES DOWNLOADED") -ForegroundColor Green
Disconnect-PnPOnline

Check out the PnP PowerShell to learn more at: https://aka.ms/pnp/powershell

The way you login into PnP PowerShell has changed please read PnP Management Shell EntraID app is deleted : what should I do ?

Contributors

Author(s)
Matteo Serpi

Disclaimer

THESE SAMPLES ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.

Back to top Script Samples
Generated by DocFX with Material UI