-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSPJeff-Inventory-SPKG-Available.ps1
More file actions
66 lines (52 loc) · 2.14 KB
/
SPJeff-Inventory-SPKG-Available.ps1
File metadata and controls
66 lines (52 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# SPJeff-Inventory-SPKG-Available.ps1
# Scan all site collection app catalogs for available SPPKG files and write report to CSV with full SPPKG details
# Load Modules
Import-Module PnP.PowerShell
# Memory collection
$coll = @()
# Load CSV with SiteURLs and loop through each site
$tenantAdminUrl = "https://spjeffdev-admin.sharepoint.com"
# Connect to the site
Connect-PnPOnline -Url $tenantAdminUrl -UseWebLogin -WarningAction SilentlyContinue
# $token = Get-PnPAccessToken
# Open the Tenant App Catalog
$catalogUrl = Get-PnPTenantAppCatalogUrl
# Open the Site Collection App Catalogs
$tenantAppCatalogSite = Get-PnPSiteCollectionAppCatalog
$tenantAppCatalogSite.Count
# Append array with Tenant App Catalog new PSObject with property AbsoluteUrl
$tenantAppCatalogSite += [PSCustomObject]@{
AbsoluteUrl = $catalogUrl
}
# Loop through each site collection app catalog
foreach ($site in $tenantAppCatalogSite) {
$global:siteUrl = $site.AbsoluteUrl
$global:siteUrl
# Connect to the site
Connect-PnPOnline -Url $global:siteUrl -UseWebLogin -WarningAction SilentlyContinue
# Get all SPPKG files in the Tenant App Catalog
$files = Get-PnPListItem -List "Apps for SharePoint" -Fields "FileLeafRef", "FileRef", "Title", "ID"
# Loop through each file
foreach ($file in $files) {
$fileUrl = $file["FileRef"]
$fileName = $file["FileLeafRef"]
$fileTitle = $file["Title"]
$fileID = $file["ID"]
# Match with PNP App
$app = Get-PnPApp -Scope "Site" | Where-Object { $_.Title -eq $fileTitle }
# Write to CSV
$coll += [PSCustomObject]@{
SiteUrl = $global:siteUrl
FileUrl = $fileUrl
FileName = $fileName
FileTitle = $fileTitle
FileID = $fileID
AppCatalogVersion = $app.AppCatalogVersion
Deployed = $app.Deployed
AppId = $app.Id
IsClientSideSolution = $app.IsClientSideSolution
}
}
}
# Write to CSV
$coll | Export-Csv -Path "SPJeff-SPKG-Available.csv" -NoTypeInformation -Force