PowerShell 모든 사이트 모음의 잠금을 해제하는 방법
-
10-12-2019 - |
문제
모든 SiteCollections를 반복하는 PowerShell 스크립트를 작성하고 잠금에 있는지 확인합니다.
때로는 야간 백업 이후 일부 컬렉션이 읽기 전용에서 돌아 오지 않기 때문입니다.SC가 읽기 전용에 있으면 unlock
로 설정하고 싶습니다.
이것은 지금까지 내 코드입니다 :
$sites = get-spsite -limit all | foreach
{
write-host "Site Collection: " $_.RootWeb.Title
if ( $_.ReadOnly -eq $true)
{
write-host "Site Collection: "$_.RootWeb.Title "--- Read-only"
//How to unlock?
//Set-SPSite -identity $_.RootWeb -lockstate unlock
//$_.ReadOnly = $false
}
}
.
지금 당장 테스트 환경이 없기 때문에 잠금 해제 코드가 작동하는지 확인할 수 없습니다.$_.RootWeb
를 올바르게 잠금 해제하는 방법에 대한 설명 된 줄에 도움이 필요합니다.
종류는 에 포함됩니다
/ EDIT : 일을 분명히하기 위해서.문제는 테스트 환경이 없습니다.문제는 지금 당장 액세스 할 수 없습니다.나는 내 머리 꼭대기에서 readonly 속성을 false로 설정하거나 -identity
에서 $_.
에서 Set-SPSite
를 얻는 방법을 foreach 루프에서 작동시키는 방법을 알 수 없습니다.
해결책
The following POC code works for me:
foreach($site in Get-spsite "PORTALURL/*" -limit all)
{
Write-Host $site.RootWeb.Url
$site.ReadOnly = $true
Write-Host "Is read only:" $site.ReadOnly
$site.ReadOnly = $false
Write-Host "Is read only:" $site.ReadOnly
$site.Dispose()
}
It first successfully sets a site as Read Only, and thereafter unsets it.
다른 팁
Unfortunately, there really isn’t a one-line equivalent in PowerShell to “get” locks for site collections that I know of. If you list out the properties of the site collection object, there is no property called “Lock State” or similar. The lock values shown in the UI are actually stored across 4 different properties in the site collection object:
- ReadOnly
- ReadLocked
- WriteLocked
- LockIssue
To get the list of locked site collections, you can make use of the below powershell script.
Add-pssnapin Microsoft.SharePoint.Powershell -ErrorAction silentlycontinue
$sites = get-spsite -limit all | foreach
{
write-host "Checking lock for site collection: " $_.RootWeb.Title -foregroundcolor blue
if ($_.ReadOnly -eq $false -and $_.ReadLocked -eq $false -and $_.WriteLocked -eq $false)
{
write-host "The site lock value for the site collection"$_.RootWeb.Title "is: Unlocked" -foregroundcolor Green
}
if ($_.lockissue -ne $null)
{
write-host "The additional text was provided for the lock: " $_.LockIssue -foregroundcolor Green
}
elseif ($_.ReadOnly -eq $false -and $_.ReadLocked -eq $false -and $_.WriteLocked -eq $true)
{
write-host "The site lock value for the site collection"$_.RootWeb.Title "is: Adding Content Prevented" -foregroundcolor Green
}
elseif ($_.ReadOnly -eq $true -and $_.ReadLocked -eq $false -and $_.WriteLocked -eq $true)
{
write-host "The site lock value for the site collection"$_.RootWeb.Title "is: Read-only" -foregroundcolor Green
}
elseif ($_.ReadOnly -eq $null -and $_.ReadLocked -eq $null -and $_.WriteLocked -eq $null)
{
write-host "The site lock value for the site collection"$_.RootWeb.Title "is: No Access" -foregroundcolor Green
}
}
After running the above script you will get to know which all site collections are locked, using the below code you can unlock it, instead of setting unlock for all the site collections,
using STSADM
stsadm -o setsitelock -url <Site-collection-url> -lock Unlock
Using PowerShell
Set-SPSite -identity "<Site-collection-url>" –lockstate Unlock
According to this TechNet article for SharePoint 2010, the PowerShell code to lock or unlock a Site Collection is as follows:
Set-SPSite -Identity "<SiteCollection>" -LockState "<State>"
Where SiteCollection is the URL of the site collection that you want to lock or unlock.
And State is 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
So to unlock, the LockState should be set to Unlock
But I really advise you to set up a test-environment to try this out. Set up a SharePoint Foundation environment in a Virtual Machine.