質問

PowerShellスクリプトを作成しようとしています。これにより、すべてのSiteCollectionsを繰り返し、ロックダウンにあるかどうかを確認します。

毎晩バックアップ後、一部のコレクションは読み取り専用から戻ってくることがあるためです。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 を正しくロック解除する方法についてのコメントされた行のヘルプが必要です。

親切な

/編集:物事をクリアするために。問題は、テスト環境がないことではありません。問題は、今にアクセスできないです。私は私がreadOnlyプロパティをfalseに設定することができますか、あるいは-identityから$_.を取得する方法をforeachetagcodeに把握する方法を偽造して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

Source

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.

ライセンス: CC-BY-SA帰属
所属していません sharepoint.stackexchange
scroll top