There are various situations where a site collection administrator has to make changes to the lock status of a/multiple site collections. It could be because you are migrating, or you want to execute some auditing and so on. Below is a script which can help you do the same. We can change the Lock state of a site collection to any of the available one. You can also add multiple site collections in the $sitelist parameter.
Hope it helps :) !
$sitelist = @("https://yoursitecollectionURL",)
foreach($site in $sitelist){
$s = get-spsite $site
$s.LockIssue = "Any text you want to add for logging purpose"
//Set-SPSite -Identity $site -LockState [NoAccess|UnLock|ReadOnly]
Set-SPSite -Identity $site -LockState NoAccess
}
Thanks for Script. Its great help.
ReplyDeleteJust update littlebit,
Get-SPSite http://mysitedev/* -LIMIT ALL | Set-SPSite -LockState NoAccess
this will reduce some effort to add site collection URL.
Appreciate your help. Yes, this saves a lot of effort, when you want to lock ALL site collections within that web app. I have had site migration on every weekend, where it helped us to lock what we wanted.
DeleteThank you.
PowerShell script for changing the lock state of a SharePoint 2013 site collection, based on your request. This script can be used to modify the lock state of one or multiple site collections:
ReplyDeletepowershell
Copy
Edit
# Define the list of site collections to modify
$sitelist = @("https://yoursitecollectionURL",)
# Loop through each site in the list
foreach($site in $sitelist){
# Get the site collection object
$s = Get-SPSite $site
# Add any custom text for logging or issue tracking
$s.LockIssue = "Any text you want to add for logging purpose"
# Change the lock state (Choose from NoAccess, Unlock, or ReadOnly)
Set-SPSite -Identity $site -LockState NoAccess # Options: NoAccess, Unlock, ReadOnly
}
Explanation:
$sitelist: This is the array where you can list multiple site collection URLs.
Get-SPSite $site: This command retrieves the site collection object.
LockIssue: This property allows you to add a custom issue or text related to the lock state.
Set-SPSite -LockState: This changes the lock state of the site collection. You can set it to:
NoAccess: Restricts all access to the site collection.
Unlock: Unlocks the site collection, making it accessible.
ReadOnly: Makes the site collection read-only, allowing no changes but still permitting viewing.
Just replace https://yoursitecollectionURL with the actual URLs of the site collections you want to modify, and the script will iterate over them, applying the specified lock state.
For more interesting insights on nature, check out this article about ants being the doctors of nature.
You can also explore Daily Sabas BD for more engaging and informative content on a variety of topics!