Tuesday, November 30, 2021

Lock Bulk sharepoint sites access to Read only.

 ## Script to set sites readonly or NoAccess##

<#

Inputs

$sourcefile = Specify the location of input TXT file containing list of sites. Simple text file containing all the site URLs -

https://site1.contoso.com

https://site2.contoso.com

https://site3.contoso.com

$LockInformation = additional information about the lock , Work order number and description

$locktype = select whether you need to select site as Readonly or NoAccess

#>

#------------Define Inputs--------------#

# Enter change number and any other text description

$LockInformation = "Description"

# List of site URLs

$sourcefile = "D:\Sitelist.txt"

# Set the below variable to Readonly or NoAccess based on your requirement

$locktype = "ReadOnly"

# Enter Log file name and path to store output

$LogFile = "D:\SiteLockUpdate.log"

#-----------Do not edit below this line-------------#

#Initiate Log File

"SiteURL|LockStatus" | Out-File $LogFile

#Load snapin

Add-PSSnapin Microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

$sites = Get-Content $sourcefile

foreach ( $site in $sites )

{

                                try

                                {

                                                $SPSite = Get-SPSite -Identity $site -ErrorAction Stop

                                                $SPSite.LockIssue = $LockInformation

                                                Set-SPSite $SPSite -LockState $locktype

                                                Write-Output "$site|Success-Set to $locktype"| %{Write-Host $_; Out-File $LogFile -InputObject $_ -Append}

                                }

                                Catch [Exception]

                                {

                                                $ErrorMessage = $_.Exception.Message

                                                Write-Output "$site|Failed - $ErrorMessage"| %{Write-Host $_; Out-File $LogFile -InputObject $_ -Append}

                                }                             

}

 

No comments:

Post a Comment