powershell icon indicating copy to clipboard operation
powershell copied to clipboard

[BUG] Get-PnPSitePolicy doesn't return the policies on recently created sites or if the policy has been created recently even when the Site policy is showing in UI

Open kares94 opened this issue 2 years ago • 3 comments

Reporting an Issue or Missing Feature

Get-PnPSitePolicy doesn't return the policies on recently created sites or if the policy has been created recently even when the Site policy is showing in UI

Expected behavior

When executing Get-PnPSitePolicy -AllAvailable, the list of available policies should match the ones from the SharePoint UI image

Actual behavior

If the site has been created recently or the policy has been created recently, the policy is not being returned by Get-PnPSitePolicy image

Steps to reproduce behavior

Case 1

  1. Create a new Site policy in the https://{tenant}.sharepoint.com/sites/contentTypeHub and publish it
  2. Execute PowerShell script from below for a site

Case 2

  1. Create a new site
  2. Execute PowerShell script from below for this new site (the policy should have been created before)
$SiteUrl = "https://{tenant}.sharepoint.com/sites/{site}"
Connect-PnPOnline -Url $SiteUrl -Interactive
$AllPolicies = Get-PnPSitePolicy -AllAvailable
Write-Host "Policies: " $AllPolicies
Disconnect-PnPOnline

What is the version of the Cmdlet module you are running?

Manifest 1.10.0 PnP.PowerShell

Which operating system/environment are you running PnP PowerShell on?

  • [x ] Windows
  • [ ] Linux
  • [ ] MacOS
  • [ ] Azure Cloud Shell
  • [x ] Azure Functions
  • [ ] Other : please specify

kares94 avatar May 06 '22 11:05 kares94

@kares94 - I've tested both scenarios (new site or new policy on existing site) and have no problem when testing within a couple of minutes. Also try in your script with $AllPolicies.Name

image

veronicageek avatar May 07 '22 20:05 veronicageek

Hi @veronicageek - Thanks for your help! I have tested what you suggested and for some reason Get-PnPSitePolicy doesn't show policies from the ContentTypeHub as you can see in the images below (working with Windows PowerShell ISE).

I have just created a new Site Policy directly on the site and it is displayed by Get-PnPSitePolicy, meanwhile the other Site Policy, which was created on the https://{tenant}.sharepoint.com/sites/contentTypeHub, doesn't show.

image

image

Also, both policies work in the Sites Closure and Deletion.

image

kares94 avatar May 09 '22 06:05 kares94

I am having this exact issue also

canberranet avatar May 26 '22 00:05 canberranet

Any resolution to this? Im having the same issue

michaellumbuku avatar Oct 21 '22 13:10 michaellumbuku

We ended up using Set-SPOSite -Identity $SiteURL -LockState "ReadOnly" You will get an annoying banner saying the site is under maintenance

canberranet avatar Oct 24 '22 00:10 canberranet

FYI the command Get-PnPSitePolicy is working when you first call Add-PnPContentTypesFromContentTypeHub -ContentTypes [GUID] -Site [SiteURL] cheers

PeterdenHarder avatar Dec 01 '22 15:12 PeterdenHarder

This issue is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days

github-actions[bot] avatar Dec 24 '22 02:12 github-actions[bot]

@kares94 - Can you please update to the latest release 2.1.x however you will need PS 7.2 or later to benefit from all the bug fixes and improvements.

PS5 support has been dropped in the new and future releases.

Feel free to reopen if the issue persists. Thanks.

veronicageek avatar Apr 04 '23 21:04 veronicageek