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⚓︎

Figure 1: When first using PnP PowerShell you must accept the AAD permissions by logging in with the -Interactive switch.


  • 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⚓︎

  1. Log in to SharePoint Online PowerShell

    Connect-SPOService -Url https://{tenantName}-admin.sharepoint.com
    
  2. 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 as customDepartment or customProjectName.

  3. 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.

Figure 2: Using Export-SPOSites.


Step 2: Add a property bag value for each site in the CSV file⚓︎

  1. Open the CSV file that was created.

  2. A column for the custom property you specified with the -customKeyToAdd switch has been added.

  3. 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.

Figure 3: Specifying the custom property values.


Step 3: Update the property bag for each site⚓︎

  1. 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
    
Figure 4: Add-BulkPropertyBagValues.ps1 will give a status bar as it is running giving an indication as to how many sites were completed, skipped, and failed.


Figure 5: Add-BulkPropertyBagValues.ps1 will give a status report after running indicating how many sites were completed, skipped, and failed.


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. If identifyTeamsConnectedGroups 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