SOLVED

LockState NoAccess for all

%3CLINGO-SUB%20id%3D%22lingo-sub-2070816%22%20slang%3D%22en-US%22%3ELockState%20NoAccess%20for%20all%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2070816%22%20slang%3D%22en-US%22%3E%3CP%3EIs%20it%20possible%20to%20put%20all%20site%20collections%20in%20LockState%20NoAccess%3F%3C%2FP%3E%3CP%3EIf%20yes%20could%20you%20please%20provide%20a%20PowerShell%20code%20or%20a%20GUI%20place%20where%20I%20can%20do%20that%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20want%20to%20kill%20my%20Sharepoint%20temporarily%20-%20taking%20away%20licenses%20didn't%20work%2C%20and%20when%20I%20took%20away%20site%20collection%20rights%20it%20helped%2C%20but%20I%20have%201000%20users%20I%20do%20not%20want%20to%20change%20permissions%20manually.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20help%20me.%20Thank%20you!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2070816%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2074567%22%20slang%3D%22en-US%22%3ERe%3A%20LockState%20NoAccess%20for%20all%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2074567%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F905007%22%20target%3D%22_blank%22%3E%40F0RCE%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUncomment%20lines%20for%20O365%3C%2FP%3E%3CP%3E%23%20Required%20for%20SharePoint%202010.%20You%20May%20need%20to%20open%20PowerShell%20and%20Run%20this%20first%20before%3CBR%20%2F%3E%23%20Executing%20this%20script%3C%2FP%3E%3CP%3E%23C%3A%5CWindows%5CSystem32%5CWindowsPowerShell%5Cv1.0%5Cpowershell.exe%20-Version%202.0%20-NoExit%20%22%20%26amp%3B%20'%20C%3A%5CProgram%20Files%5CCommon%20Files%5CMicrosoft%20Shared%5CWeb%20Server%20Extensions%5C14%5CCONFIG%5CPOWERSHELL%5CRegistration%5C%5Csharepoint.ps1%20'%20%22%3C%2FP%3E%3CP%3EAdd-PSSnapin%20Microsoft.SharePoint.PowerShell%20-ErrorAction%20SilentlyContinue%3CBR%20%2F%3EWrite-Host%20%22Microsoft.SharePoint.PowerShell%20Snap-In%20Added...%22%20-ForegroundColor%20Green%3CBR%20%2F%3EWrite-Host%3CBR%20%2F%3E%23*******************************************************************************%3C%2FP%3E%3CP%3E%23State%20has%20one%20of%20the%20following%20values%3A%3C%2FP%3E%3CP%3E%23Unlock%20to%20unlock%20the%20site%20collection%20and%20make%20it%20available%20to%20users.%3CBR%20%2F%3E%23NoAdditions%20to%20prevent%20users%20from%20adding%20new%20content%20to%20the%20site%20collection.%20Updates%20and%20deletions%20are%20still%20allowed.%3CBR%20%2F%3E%23ReadOnly%20to%20prevent%20users%20from%20adding%2C%20updating%2C%20or%20deleting%20content.%3CBR%20%2F%3E%23NoAccess%20to%20prevent%20users%20from%20accessing%20the%20site%20collection%20and%20its%20content.%20Users%20who%20attempt%20to%20access%20the%20site%20receive%20an%20error%3C%2FP%3E%3CP%3E%23O365%20Example%3CBR%20%2F%3E%23%24siteUrl%20%3D%20%22%3CA%20href%3D%22https%3A%2F%2FYOURTENANT-admin.sharepoint.com%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2FYOURTENANT-admin.sharepoint.com%3C%2FA%3E%22%3CBR%20%2F%3E%23Connect-SPOService%20-Url%20%24siteUrl%3C%2FP%3E%3CP%3E%23%24site%20%3D%20%22%3CA%20href%3D%22https%3A%2F%2FYOURTENANT.sharepoint.com%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2FYOURTENANT.sharepoint.com%3C%2FA%3E%22%3CBR%20%2F%3E%23Set-SPOSite%20-Identity%20%24site%20-LockState%20%22NoAccess%22%3C%2FP%3E%3CP%3E%23*******************************************************************************%3C%2FP%3E%3CP%3E%23stsadm%20-o%20setsitelock%20-url%20%3CSITE-COLLECTION-URL%3E%20-lock%20NoAccess%3CBR%20%2F%3E%23Set-SPSite%20-Identity%20http%3A%2F%2Fsharepoint-sitecollection-url%20-LockState%20NoAccess%3C%2FSITE-COLLECTION-URL%3E%3C%2FP%3E%3CP%3E%23*******************************************************************************%3CBR%20%2F%3E%23*******************************************************************************%3C%2FP%3E%3CP%3E%23Select%20Web%20Application%20or%20Site%20Collection%3CBR%20%2F%3E%24ApplyToWebApp%20%3D%20Read-Host%20%22Application%20to%20Web%20Application%20(Y%2FN)%3F%22%3C%2FP%3E%3CP%3E%23*******************************************************************************%3CBR%20%2F%3E%23*%20Apply%20To%20Web%20Application%3CBR%20%2F%3E%23*******************************************************************************%3C%2FP%3E%3CP%3Eif%20(%24ApplyToWebApp%20-eq%20'Y')%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%23Set%20the%20Web%20application%20URL%3CBR%20%2F%3E%24WebAppURL%20%3D%20Read-Host%20%22Enter%20the%20Web%20Application%20Url%20%5B%3CA%20href%3D%22http%3A%2F%2Fportal.contoso.com%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fportal.contoso.com%3C%2FA%3E%5D%22%20%60n%3CBR%20%2F%3E%24lockState%20%3D%20Read-Host%20%22Select%20the%20LockState%20%5BUnlock%2CNoAdditions%2CReadOnly%2CNoAccess%5D%22%3F%3C%2FP%3E%3CP%3E%23Get%20the%20Web%20Application%3CBR%20%2F%3E%24WebApp%20%3D%20Get-SPWebApplication%20%24WebAppURL%3C%2FP%3E%3CP%3E%23Get%20all%20Site%20Collections%20from%20the%20Web%20Application%3CBR%20%2F%3E%24SitesCollection%20%3D%20%24WebApp.Sites%3C%2FP%3E%3CP%3E%23Enumerate%20all%20site%20collections%20in%20the%20web%20application%3CBR%20%2F%3EForeach(%24Site%20in%20%24SitesCollection)%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%23Get%20Site%20Collection%20URL%2C%20Owner%2C%20Content%20Database%20Details%3CBR%20%2F%3E%23Write-host%20%24Site.URL%3CBR%20%2F%3E%3CBR%20%2F%3ESet-SPSite%20-Identity%20%24Site%20-LockState%20%24lockState%3CBR%20%2F%3EWrite-Host%3CBR%20%2F%3EWrite-Host%20%22Lock%20Status%20set%20to%20%22%20%24lockState%20%22%20for%20%22%20%24Site%20-ForegroundColor%20Green%3CBR%20%2F%3EWrite-Host%3CBR%20%2F%3E%3CBR%20%2F%3E%24Site.Dispose()%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3Eelse%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%23*******************************************************************************%3CBR%20%2F%3E%23*%20Apply%20To%20Site%20Collection%3CBR%20%2F%3E%23*******************************************************************************%3C%2FP%3E%3CP%3E%23Set%20the%20Web%20application%20URL%3CBR%20%2F%3E%24SiteColURL%20%3D%20Read-Host%20%22Enter%20the%20Site%20Collection%20Url%20%5B%3CA%20href%3D%22http%3A%2F%2Fportal.contoso.com%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttp%3A%2F%2Fportal.contoso.com%3C%2FA%3E%5D%22%20%60n%3CBR%20%2F%3E%24lockState%20%3D%20Read-Host%20%22Select%20the%20LockState%20%5BUnlock%2CNoAdditions%2CReadOnly%2CNoAccess%5D%22%3F%3C%2FP%3E%3CP%3ESet-SPSite%20-Identity%20%24SiteColURL%20-LockState%20%24lockState%3CBR%20%2F%3EWrite-Host%3CBR%20%2F%3EWrite-Host%20%22Lock%20Status%20set%20to%20%22%20%24lockState%20%22%20for%20%22%20%24SiteColURL%20-ForegroundColor%20Green%3CBR%20%2F%3EWrite-Host%3CBR%20%2F%3E%7D%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

Is it possible to put all site collections in LockState NoAccess?

If yes could you please provide a PowerShell code or a GUI place where I can do that?

 

I want to kill my Sharepoint temporarily - taking away licenses didn't work, and when I took away site collection rights it helped, but I have 1000 users I do not want to change permissions manually.

 

Please help me. Thank you!

1 Reply
Best Response confirmed by F0RCE (Occasional Contributor)
Solution

@F0RCE 

 

Uncomment lines for O365

# Required for SharePoint 2010. You May need to open PowerShell and Run this first before
# Executing this script

#C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Version 2.0 -NoExit " & ' C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\CONFIG\POWERSHELL\Registration\\sharepoint.ps1 ' "

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
Write-Host "Microsoft.SharePoint.PowerShell Snap-In Added..." -ForegroundColor Green
Write-Host
#*******************************************************************************

#State has one of the following values:

#Unlock to unlock the site collection and make it available to users.
#NoAdditions to prevent users from adding new content to the site collection. Updates and deletions are still allowed.
#ReadOnly to prevent users from adding, updating, or deleting content.
#NoAccess to prevent users from accessing the site collection and its content. Users who attempt to access the site receive an error

#O365 Example
#$siteUrl = "https://YOURTENANT-admin.sharepoint.com"
#Connect-SPOService -Url $siteUrl

#$site = "https://YOURTENANT.sharepoint.com"
#Set-SPOSite -Identity $site -LockState "NoAccess"

#*******************************************************************************

#stsadm -o setsitelock -url <Site-collection-url> -lock NoAccess
#Set-SPSite -Identity http://sharepoint-sitecollection-url -LockState NoAccess

#*******************************************************************************
#*******************************************************************************

#Select Web Application or Site Collection
$ApplyToWebApp = Read-Host "Application to Web Application (Y/N)?"

#*******************************************************************************
#* Apply To Web Application
#*******************************************************************************

if ($ApplyToWebApp -eq 'Y')
{
#Set the Web application URL
$WebAppURL = Read-Host "Enter the Web Application Url [http://portal.contoso.com]" `n
$lockState = Read-Host "Select the LockState [Unlock,NoAdditions,ReadOnly,NoAccess]"?

#Get the Web Application
$WebApp = Get-SPWebApplication $WebAppURL

#Get all Site Collections from the Web Application
$SitesCollection = $WebApp.Sites

#Enumerate all site collections in the web application
Foreach($Site in $SitesCollection)
{
#Get Site Collection URL, Owner, Content Database Details
#Write-host $Site.URL

Set-SPSite -Identity $Site -LockState $lockState
Write-Host
Write-Host "Lock Status set to " $lockState " for " $Site -ForegroundColor Green
Write-Host

$Site.Dispose()
}
}
else
{
#*******************************************************************************
#* Apply To Site Collection
#*******************************************************************************

#Set the Web application URL
$SiteColURL = Read-Host "Enter the Site Collection Url [http://portal.contoso.com]" `n
$lockState = Read-Host "Select the LockState [Unlock,NoAdditions,ReadOnly,NoAccess]"?

Set-SPSite -Identity $SiteColURL -LockState $lockState
Write-Host
Write-Host "Lock Status set to " $lockState " for " $SiteColURL -ForegroundColor Green
Write-Host
}