GitHub Icon Image
GitHub

Enable Site Collection App Catalog on a specific sites using CSV

Summary

The script reads list of SharePoint site collection URLs from a CSV and enables the Site collection app catalog on them.

Example Screenshot

Implementation

  • Create csv file with the list of site collection URLs to enable app catalog
  • Open Windows PowerShell ISE
  • Create a new file
  • Copy the code below
  • Save the file and run it
  • Make sure you must have access to the app catalog to apply
  • SPO Management Shell
  • PnP PowerShell
  • CLI for Microsoft 365
  • CSV file sample
# Example: .\Enable-SiteCollectionAppCatalog.ps1 -AdminUrl "https://contoso-admin.sharepoint.com" -CsvPath ".\SiteURLs.csv"
[CmdletBinding()]
param (
    [Parameter(Mandatory = $true, HelpMessage = "URL of the SharePoint Admin Center, e.g.https://contoso-admin.sharepoint.com")]
    [string]$AdminUrl,
    [Parameter(Mandatory = $false, HelpMessage = "Path to CSV file with list of SharePoint sites to enable Site Collection App Catalog")]
    [string]$CsvPath = ".\SiteURLs.csv"
)

begin  {
    Write-Host "Connecting to SharePoint Admin Site '$($AdminUrl)'" -f Yellow
    Connect-SPOService -Url $AdminUrl
}
process {
    $data = Import-Csv -Path $CsvPath

    $data | Foreach-Object{
        Write-Host "Adding site collection app catalog to site '$($_.SiteUrl)'..." -f Yellow
        $site = Get-SPOSite $_.SiteUrl
        Add-SPOSiteCollectionAppCatalog -Site $site
    }
}
end {
    Disconnect-SPOService
    Write-Host "Finished" -ForegroundColor Green
}

Check out the SPO Management Shell to learn more at: Introduction SharePoint Online Management Shell | Microsoft Docs

# Example: .\Enable-SiteCollectionAppCatalog.ps1 -AdminUrl "https://contoso-admin.sharepoint.com" -CsvPath ".\SiteURLs.csv"
[CmdletBinding()]
param (
    [Parameter(Mandatory = $true, HelpMessage = "URL of the SharePoint Admin Center, e.g.https://contoso-admin.sharepoint.com")]
    [string]$AdminUrl,
    [Parameter(Mandatory = $false, HelpMessage = "Path to CSV file with list of SharePoint sites to enable Site Collection App Catalog")]
    [string]$CsvPath = ".\SiteURLs.csv"
)

begin  {
    Write-Host "Connecting to SharePoint Admin Site '$($AdminUrl)'" -f Yellow
    Connect-PnPOnline -Url $AdminUrl
}
process {
    $data = Import-Csv -Path $CsvPath

    $data | Foreach-Object{
        Write-Host "Adding site collection app catalog to site '$($_.SiteUrl)'..." -f Yellow
        Add-PnPSiteCollectionAppCatalog -Site $_.SiteUrl
    }
}
end {
    Disconnect-PnPOnline
    Write-Host "Finished" -ForegroundColor Green
}

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 ?

# Example: .\Enable-SiteCollectionAppCatalog.ps1 -CsvPath ".\SiteURLs.csv"
[CmdletBinding()]
param (
    [Parameter(Mandatory = $false, HelpMessage = "Path to CSV file with list of SharePoint sites to enable Site Collection App Catalog")]
    [string]$CsvPath = ".\SiteURLs.csv"
)

begin  {
    #Log in to Microsoft 365
    Write-Host "Connecting to Tenant" -f Yellow

    $m365Status = m365 status
    if ($m365Status -match "Logged Out") {
        m365 login
    }

    Write-Host "Connection Successful!" -f Green
}
process {
    $data = Import-Csv -Path $CsvPath

    $data | Foreach-Object{
        Write-Host "Adding site collection app catalog to site '$($_.SiteUrl)'..." -f Yellow
        m365 spo site appcatalog add --siteUrl $_.SiteUrl
    }
}
end {
    m365 logout
    Write-Host "Finished" -ForegroundColor Green
}

Check out the CLI for Microsoft 365 to learn more at: https://aka.ms/cli-m365

Important changes coming to the way you login into CLI for Microsoft 365 (effective 9th September 2024) see Changes in PnP Management Shell registration in Microsoft 365

SiteUrl
https://contoso.sharepoint.com/sites/Audits
https://contoso.sharepoint.com/sites/Finance
https://contoso.sharepoint.com/sites/HR
https://contoso.sharepoint.com/sites/Innovations
https://contoso.sharepoint.com/sites/Retail

Contributors

Author(s)
Nanddeep Nachan

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