Вопрос

Я пытаюсь построить скрипт 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

Добрые С уважением

/ Редактировать: чтобы сделать все возможное.Проблема не в том, что у меня нет испытательных сред.Проблема в том, что я не могу получить доступ к ним прямо сейчас.Я не могу выяснить из вершины головы, как я могу установить Healonly Property в 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

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