GetProjectPolicies() throws an exception on a read-only web RRS feed

  • Question

  • I am writing a PowerShell script to check if all the sites have a site policy propagated to them by Content Type Hub. I execute this line on every site (SSOM code, i.e. Microsoft.SharePoint.PowerShell snap-in):


    It returns a list of site policies on the normal sites, but fails on read-only sites (read-only status is set by a policy application):

    Read-only site screenshot

    The policy is propagated:

    Policy in the site

    And the policy is applied in the site (what made the site read-only):

    Policy is applied

    The exception is

    Exception calling "GetProjectPolicies" with "1" argument(s): "Sorry, this site hasn't been shared with you."
    But I can open the site with a browser from under the same user I execute the script with.

    What can be wrong here?


    Tuesday, March 21, 2017 10:25 AM

All replies

  • Hi Vadim,

    I can reproduce it in my environment for the closed sites:

    For the open sites, it works fine like this:

    Seems that this is a by design message when using this method in such scenario.

    To work around this issue at this moment, a thought is that, you can add an exception handling in your script to recognize this issue as an exception:

    Best regards,


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact

    Wednesday, March 22, 2017 7:23 AM
  • Thank you, Patrick.

    The exception handling is not an issue. I just cannot read the policy list. And the site can be set as read-only via SPSite.ReadOnly property,

    $site.ReadOnly = $true

    and in this case the same exception is thrown by GetProjectPolicies(). The goal was to actually check if the sites have policies from Content Type Hub. And it's a bit confusing to get an exception during a 'read' operation on a read-only site.


    Wednesday, March 22, 2017 7:48 AM