sp-dev-docs icon indicating copy to clipboard operation
sp-dev-docs copied to clipboard

Property Bag Values on Groups/New Modern Sites

Open suz7777 opened this issue 9 years ago • 9 comments

  • [ ] 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 $_
}

suz7777 avatar Jul 01 '17 23:07 suz7777

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?

chackman avatar Jul 03 '17 19:07 chackman

there is no correlation ID as this is executed via Powershell... how do I get one for you? Please advise

suz7777 avatar Jul 06 '17 17:07 suz7777

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.

chackman avatar Jul 06 '17 18:07 chackman

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()
}

VesaJuvonen avatar Jul 10 '17 15:07 VesaJuvonen

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

suz7777 avatar Jul 13 '17 23:07 suz7777

this appears to work now

suz7777 avatar Jul 24 '17 15:07 suz7777

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

patrickabel avatar Feb 15 '18 03:02 patrickabel

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.

praveenbattula avatar Apr 23 '19 19:04 praveenbattula

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

msft-github-bot avatar Jan 29 '20 06:01 msft-github-bot