Adaptive Scopes Property Bag Scripts⚓︎
These scripts are to be used as examples showing how you can use SharePoint Patterns & Practices (PnP) to add custom properties to a large number of existing sites in SharePoint Online.
Requirements⚓︎
- Ensure you've read the disclaimer and running the scripts sections of this documentation.
- For the first script (Export-SPOSites.ps1) you will be required to connect to SharePoint Online using the SharePoint Online PowerShell Module and will need permissions that allow you to run
Get-SPOSite
: - For the second script (Add-BulkPropertyBagValues.ps1) you will be required to use PnP.PowerShell module and will need to be a site collection administrator for each site you want to add custom properties to.
-
If this is the first time you are using PnP PowerShell, you will need to first log in interactively and allow permissions:
Connect-PnPOnline -Url https://{tenantName}.sharepoint.com/sites/{sitename} -Interactive
-
Since the purpose of these scripts are to update many existing SharePoint Online sites, you must save your credentials (at least temporarily) in the credential manager. Follow these instructions to do so.
Note
This method only works with Windows. There are other methods available, but you will need to update the scripts to use them.
-
Some optional parameters may require connectivity to the Exchange Online PowerShell module and will require permissions to run
Get-UnifiedGroup
.
Usage⚓︎
Step 1: Export the existing sites⚓︎
-
Log in to SharePoint Online PowerShell
Connect-SPOService -Url https://{tenantName}-admin.sharepoint.com
-
Use Export-SPOSites.ps1 to export all SPO sites to a CSV file. Use
-customKeyToAdd
to provide the name of the custom property you will be adding to all sites..\Export-SPOSites.ps1 -customKeyToAdd customKeyName
Note
Replace
customKeyName
with whatever custom key name you want to use, such ascustomDepartment
orcustomProjectName
. -
All sites that the script exports will be stored in a CSV file. The location will be output once the script is completed.
Note
The default location and name of the CSV file will be
c:\temp\SPOSitesExport.csv
. You can use optional parameters to change the default location and name.
Step 2: Add a property bag value for each site in the CSV file⚓︎
-
Open the CSV file that was created.
-
A column for the custom property you specified with the
-customKeyToAdd
switch has been added. -
Add a value in this column for each site that you want to add the custom property to, then save the CSV file.
Note
Any site that you add a value for will be processed. Any site that you do not add a value for will be skipped. In this example, 4 sites have values set so only 4 sites will be updated.
Step 3: Update the property bag for each site⚓︎
-
Execute Add-BulkPropertyBagValues.ps1 using
-customKeyToAdd
to specify the name of the custom property added in the previous steps,-csvFile
to provide the path to the CSV file updated in the previous steps, and-storedCredential
to provide the credential stored in the credential manager. This script will automatically connect to each site and add the new custom properties.Note
Unless optional parameters are specified, the script will default to not overwriting custom property values if the properties already exist.
.\Add-BulkPropertyBagValues.ps1 -customKeyToAdd "customKeyName" -csvFile c:\temp\SPOSitesExport.csv -storedCredential PropertyBagExample
Optional parameters⚓︎
Export-SPOSites.ps1⚓︎
customValueToAdd
: You can alternatively have the script automatically populate custom values in the CSV. Keep in mind this will apply to ALL exported sites.csvExportPath
: Path to export CSV. Default is c:\temp.csvExportFileName
: Name of CSV file. Default is SPOSitesExport.csv.identifyTeamsConnectedGroups
: When enabled, will connect to EXO to identify which M365 groups are teams. Default is disabled ($false
). Enabling this parameter will require connection to Exchange Online PowerShell.outputAllAvailableSPOSiteProperties
: when enabled, the script will not limit output columns. when disabled, only select columns are output. Default is disabled ($false
).
The following parameters are optional but cannot be combined with each other⚓︎
TeamsConnectedGroupsOnly
: Outputs only M365 groups which are Teams connected. Enabling this parameter will require connection to Exchange Online PowerShell. Default is disabled ($false
).M365GroupsOnly
: Outputs only M365 groups. IfidentifyTeamsConnectedGroups
is enabled, it will output non-Teams M365 groups. Default is disabled ($false
).SPOSitesOnly
: Outputs only SPO Sites (non-Group connected). Default is disabled ($false
).
Update-BulkPropertyBagValues.ps1⚓︎
overwrite
: If enabled, the script will overwrite any existing property bag values that match the custom property being added. Default is disabled ($false
).
Download⚓︎
Changelog⚓︎
Export-SPOSites.ps1⚓︎
October 27, 2021 (0586751)⚓︎
- Initial release
Update-BulkPropertyBagValues.ps1⚓︎
January 14, 2022 (8394ccd)⚓︎
- Updated with new PnP cmdlet and module version check
October 27, 2021 (0586751)⚓︎
- Initial release