Property Bag Values on Groups/New Modern Sites
- [ ] Question
- [ ] Typo
- [x ] Bug
- [ ] Additional article idea
Expected or Desired Behavior
I am trying to set the property bag value of a group - per my understanding the process is:
- disable DenyAddAndCustomizePages
- set the property bag value
- enable DenyAddAndCustomizePages
Observed Behavior
I get the error:
Set-PnPPropertyBagValue : The pipeline has been stopped.
At E:\0-install\3M\projects\DWP-SiteCollRpt\testScript.ps1:43 char:1
+ Set-PnPPropertyBagValue -Key "SiteType" -Value "Group" -Indexed
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Set-PnPPropertyBagValue], PipelineStoppedException
+ FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.SetPropertyBagValue
Steps to Reproduce
Clear-Host
#Import-Module -Name SharePointPnPPowerShellOnline -DisableNameChecking
# Shorten name!
$z=(pwd).path
$Component="O365"
try {
$weburl="https://me.sharepoint.com/teams/windowfilms2"
$AdminURL = 'https://me-admin.sharepoint.com'
$UserID = ([System.Security.Principal.WindowsIdentity]::GetCurrent().Name.Split('\',2))[1]
$UserIDFile = $z + "\..\..\SecuredCredentials\" + $UserID + "-" + $Component + "credID.txt"
$PasswordFile = $z + "\..\..\SecuredCredentials\" + $UserID + "-" + $Component + "credPassword.txt"
$Global:O365UserID = get-content $UserIDFile
$Global:O365password = get-content $PasswordFile | convertto-securestring
$Global:PScred = new-object -TypeName System.Management.Automation.PSCredential -ArgumentList $Global:O365UserID, $Global:O365password
Connect-PnPOnline -Url $adminurl -Credentials $PScred
$context = Get-PnPContext
$site = Get-PnPTenantSite -Detailed -Url $weburl
if ($site.DenyAddAndCustomizePages -ne "Disabled") {
Write-Host "Disabling customize pages"
$site.DenyAddAndCustomizePages = "Disabled"
$site.Update()
$context.ExecuteQuery()
}
#Connect-SPOnline -Url $SiteUrl -Credentials $PScred
Connect-PNPonline -Url $weburl -Credentials $PScred
$customizeValue=Get-PnPTenantSite -Detailed -Url $weburl | select DenyAddAndCustomizePages
$currentValue=Get-PnPPropertyBag -Key "SiteType"
$currentSearchValue = (Get-PnPPropertyBag | select key,value |where {$_.Key -eq "vti_searchversion"}).Value
Write-Host "Site URL - " (Get-PnPSite).Url
Write-Host "DenyAddAndCustomizePages - $($customizeValue.DenyAddAndCustomizePages)"
Write-Host "Search - $currentSearchValue"
Write-Host "siteType - $currentValue"
Set-PnPPropertyBagValue -Key "SiteType" -Value "Group" -Indexed
# To Enable
$site.DenyAddAndCustomizePages = "Enabled"
$site.Update()
$context.ExecuteQuery()
Get-PnPTenantSite -Detailed -Url $weburl | select DenyAddAndCustomizePages
Disconnect-PnPOnline
} catch {
Write-Error $_.InvocationInfo
Write-Error $_
}
Thanks for your feedback. Could you please provide more information about the error? For example, a correlation ID or a more specific error message from SharePoint?
there is no correlation ID as this is executed via Powershell... how do I get one for you? Please advise
These PowerShell cmdlets use CSOM to communicate with SharePoint. Using Fiddler, for example, you can get the correlation ID for a CSOM request (look for a POST to _vti_bin/client.svc/ProcessQuery) and get the value of the SPRequestGuid response header.
Hi suz, the problem was in the PowerShell script where the context was mixed up cross admin and normal site, so your updates were not properly applied. Here's updated and validated script to do this using PnP PowerShell. I'll close the issue now, but obviously please let us know if there are any follow-up things to discuss.
$adminUrl = "https://tenant-admin.sharepoint.com"
$weburl = "https://tenant.sharepoint.com/sites/Test-Modern-Group"
Connect-PnPOnline -Url $adminurl
$site = Get-PnPTenantSite -Detailed -Url $weburl
if ($site.DenyAddAndCustomizePages -ne "Disabled") {
Write-Host "Disabling customize pages"
$site.DenyAddAndCustomizePages = "Disabled"
$site.Update()
$site.Context.ExecuteQuery()
}
## Update property bag value
Connect-PnPOnline -Url $weburl
$customizeValue=Get-PnPTenantSite -Detailed -Url $weburl | select DenyAddAndCustomizePages
$currentValue=Get-PnPPropertyBag -Key "SiteType"
$currentSearchValue = (Get-PnPPropertyBag | select key,value |where {$_.Key -eq "vti_searchversion"}).Value
Write-Host "Site URL - " (Get-PnPSite).Url
Write-Host "DenyAddAndCustomizePages - $($customizeValue.DenyAddAndCustomizePages)"
Write-Host "Search - $currentSearchValue"
Write-Host "siteType - $currentValue"
Set-PnPPropertyBagValue -Key "SiteType" -Value "Group" -Indexed
# To Enable noscript again - Notice that we need to reconnect,
# since currently context is pointing to actual site, not admin site
Connect-PnPOnline -Url $adminurl
$site = Get-PnPTenantSite -Detailed -Url $weburl
if ($site.DenyAddAndCustomizePages -ne "Enabled") {
Write-Host "Disabling customize pages"
$site.DenyAddAndCustomizePages = "Enabled"
$site.Update()
$site.Context.ExecuteQuery()
}
I have found the root of the issue… when I do: • Create a group • Run the script • All is well ....YAY
When I do: • Someone else creates a public group • Does not add me as a specific member • Run the script • I cannot update the property bag.
So the question is: How do I make myself a member of a public group via powershell?
suz
this appears to work now
@VesaJuvonen I am running into 401 unauthorized errors using your above script when executing the Get-PnPTenantSite cmdlet from within an Azure Function. At first I thought this issue spawned from my use of app-only access but I'm seeing the same error passing in -Credentials as well.
Outside of my azure function, the same script executes successfully.
Any idea on what could be causing this? I'm looking to incorporate property-bag updates into a site provisioning solution extending site designs with PnP PowerShell.
Thats correct. You will run the 401 errors because the below lines are not correct.
Connect-PnPOnline -Url $weburl
$customizeValue=Get-PnPTenantSite -Detailed -Url $weburl | select DenyAddAndCustomizePages
After connecting PnPOnline for web url you cannot connect to Tenant Site using Get-PnPTenantSite without connecting to admin url again. So you need to move second line to first line to get it work. Here is complete code.
$adminUrl = "https://tenant-admin.sharepoint.com"
$weburl = "https://tenant.sharepoint.com/sites/Test-Modern-Group"
Connect-PnPOnline -Url $adminurl
$site = Get-PnPTenantSite -Detailed -Url $weburl
if ($site.DenyAddAndCustomizePages -ne "Disabled") {
Write-Host "Disabling customize pages"
$site.DenyAddAndCustomizePages = "Disabled"
$site.Update()
$site.Context.ExecuteQuery()
}
## Update property bag value
$customizeValue=Get-PnPTenantSite -Detailed -Url $weburl | select DenyAddAndCustomizePages
Connect-PnPOnline -Url $weburl
$currentValue=Get-PnPPropertyBag -Key "SiteType"
$currentSearchValue = (Get-PnPPropertyBag | select key,value |where {$_.Key -eq "vti_searchversion"}).Value
Write-Host "Site URL - " (Get-PnPSite).Url
Write-Host "DenyAddAndCustomizePages - $($customizeValue.DenyAddAndCustomizePages)"
Write-Host "Search - $currentSearchValue"
Write-Host "siteType - $currentValue"
Set-PnPPropertyBagValue -Key "SiteType" -Value "Group" -Indexed
## To Enable noscript again - Notice that we need to reconnect,
## since currently context is pointing to actual site, not admin site
Connect-PnPOnline -Url $adminurl
$site = Get-PnPTenantSite -Detailed -Url $weburl
if ($site.DenyAddAndCustomizePages -ne "Enabled") {
Write-Host "Disabling customize pages"
$site.DenyAddAndCustomizePages = "Enabled"
$site.Update()
$site.Context.ExecuteQuery()
}
-Praveen.
Issues that have been closed & had no follow-up activity for at least 7 days are automatically locked. Please refer to our wiki for more details, including how to remediate this action if you feel this was done prematurely or in error: Issue List: Our approach to locked issues