Forum Discussion

F0RCE's avatar
F0RCE
Copper Contributor
Jan 18, 2021

LockState NoAccess for all

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!

  • 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
    }

  • Anton1941's avatar
    Anton1941
    Copper Contributor

    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
    }

Resources