Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Setting the lock state for a site collection has a few rules that aren't entirely clear. You can set the lock state via PowerShell using the Set-SPOSite command:
Set-SPOSite https://[tenant].sharepoint.com/sites/targetsite -LockState [NoAccess|Unlock]
You can read more about that on the TechNet article for it here: https://technet.microsoft.com/en-us/library/cc263238(v=office.15).aspx
The site must not be one of the following:
To do this in CSOM, you can utilize the TenantAdministration API; however, this is only available in the v16 SharePoint Online API.
using (var clientContext = new ClientContext(tenantUrl)) {
clientContext.Credentials = spoCredentials;
var tenant = new Tenant(clientContext);
var siteProperties = tenant.GetSitePropertiesByUrl(siteUrl, true);
clientContext.Load(siteProperties);
clientContext.ExecuteQuery();
Console.WriteLine("LockState: {0}", siteProperties.LockState);
siteProperties.LockState = "Unlock";
siteProperties.Update();
clientContext.ExecuteQuery();
}
This will will also be a future OfficeDevPnP.Core extension (in the dev branch, now). The method is TenantExtensions.SetSiteLockState(this Tenant tenant, string siteUrl, SiteLockState lockState).
When the site is locked, you'll see it in the admin site with a lock icon next to it as seen below.
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in