{"id":2841,"date":"2020-10-30T16:06:18","date_gmt":"2020-10-30T15:06:18","guid":{"rendered":"https:\/\/www.itidea.nl\/?p=2841"},"modified":"2020-10-30T16:22:22","modified_gmt":"2020-10-30T15:22:22","slug":"to-lock-or-unlock-a-site","status":"publish","type":"post","link":"https:\/\/www.itidea.nl\/index.php\/to-lock-or-unlock-a-site\/","title":{"rendered":"To lock or unlock a SharePoint Online site"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">SharePoint sites can be locked or put in read-only mode.<br>In this post PowerShell is used to lock a site. Another option is to use the Site Policies settings of the site.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The PowerShell commands are quite straightforward.<br>First connect to a site:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nConnect-PnPOnline $siteUrl\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Lock the site by using:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nSet-PnPSite -LockState NoAccess\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">When the site is accessed once locked a 403 forbidden response is displayed in the browser as shown in the following figure.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"162\" height=\"50\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2020\/10\/1-Unlock-a-site.png\" alt=\"\" class=\"wp-image-2846\"\/><figcaption>403 forbidden<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">You can make it more fancy to redirect the visitor of the site to another url by setting this tenant-wide using the command:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nSet-PnPTenant -NoAccessRedirectUrl &quot;&lt;your url&gt;&quot;\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">Now the visitor doesn&#8217;t see the 403 response, but another webpage as configured.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At a certain point in time once mind has changed and the has to be unlocked.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Well, the command again is straightforward after reconnecting to the site:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nSet-PnPSite -LockState Unlock\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\">But the response is:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: powershell; title: ; notranslate\" title=\"\">\nSet-PnPSite : The remote server returned an error: (403) Forbidden.\nAt line:1 char:1\n+ Set-PnPSite -LockState Unlock -Connection $siteConnection\n+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n    + CategoryInfo          : WriteError: (:) &#x5B;Set-PnPSite], WebException\n    + FullyQualifiedErrorId : EXCEPTION,SharePointPnP.PowerShell.Commands.Site.SetSite\n<\/pre><\/div>\n\n\n<p class=\"wp-block-paragraph\"><em>Which actually makes sense, but<\/em>&#8230;<\/p>\n\n\n\n<figure class=\"wp-block-pullquote\"><blockquote><p>How to unlock the site then?<\/p><\/blockquote><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">In PowerShell the connection is made with the account which has assigned the Global admininistrator role.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the SharePoint admin center, logged in with that same account, the locked site is listed and marked as locked in the properties panel as shown below.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"600\" height=\"416\" src=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2020\/10\/2-Unlock-a-site.png\" alt=\"\" class=\"wp-image-2847\" srcset=\"https:\/\/www.itidea.nl\/wp-content\/uploads\/2020\/10\/2-Unlock-a-site.png 600w, https:\/\/www.itidea.nl\/wp-content\/uploads\/2020\/10\/2-Unlock-a-site-300x208.png 300w\" sizes=\"auto, (max-width: 600px) 100vw, 600px\" \/><figcaption>Admin center shows a site is locked<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">These actions were performed on a Teamsite with a group, a Teamsite without a group and a Communication site, all with the same result: they are all inaccessible in any way now.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"has-inline-color has-accent-color\">Please help me out and put your suggestions in the comments below and I&#8217;ll get back to it!<\/span><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>SharePoint sites can be locked or put in read-only mode.In this post PowerShell is used to lock a site. Another option is to use the Site Policies settings of the site. The PowerShell commands are quite straightforward.First connect to a &#8230; <a class=\"more-link\" href=\"https:\/\/www.itidea.nl\/index.php\/to-lock-or-unlock-a-site\/\">Read More &raquo;<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[39,22],"tags":[37,43],"class_list":["post-2841","post","type-post","status-publish","format-standard","hentry","category-office-365","category-powershell","tag-office365","tag-powershell"],"_links":{"self":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/2841","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/comments?post=2841"}],"version-history":[{"count":8,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/2841\/revisions"}],"predecessor-version":[{"id":2853,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/posts\/2841\/revisions\/2853"}],"wp:attachment":[{"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/media?parent=2841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/categories?post=2841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.itidea.nl\/index.php\/wp-json\/wp\/v2\/tags?post=2841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}