我正在尝试构建一个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$_. 以获得 Set-SPSite 在foreach循环中工作。

有帮助吗?

解决方案

下面的POC代码适用于我:

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()
}

它首先成功地将站点设置为只读,然后将其取消设置。

其他提示

不幸的是,在PowerShell中真的没有一行等价物来"获取"我所知道的网站集的锁。如果列出网站集对象的属性,则没有称为"锁定状态"或类似的属性。UI中显示的锁定值实际上存储在网站集对象中的4个不同属性中:

  • 阅读,阅读
  • 重新锁定
  • 已写入
  • 锁,锁

要获取锁定网站集的列表,您可以使用下面的powershell脚本。

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
    }
}

运行上述脚本后,您将了解哪些所有网站集都被锁定,使用下面的代码,您可以解锁它,而不是为所有网站集设置解锁,

使用STSADM stsadm -o setsitelock -url <Site-collection-url> -lock Unlock

使用PowerShell Set-SPSite -identity "<Site-collection-url>" –lockstate Unlock

资料来源

根据 这篇TechNet文章 对于SharePoint2010,用于锁定或解锁网站集的PowerShell代码如下所示:

Set-SPSite -Identity "<SiteCollection>" -LockState "<State>"

哪里 网站收藏 是要锁定或解锁的网站集的URL。

国家 是下列值之一:

  • 解锁 解锁网站集并使其可供用户使用。
  • 无附加条件 以防止用户向网站集添加新内容。仍然允许更新和删除。
  • 阅读,阅读 防止用户添加、更新或删除内容。
  • N.无障碍,无障碍 以防止用户访问网站集及其内容。尝试访问站点的用户会收到错误

所以要解锁,LockState应该设置为 解锁

但我真的建议你建立一个测试环境来尝试这个。在虚拟机中设置SharePoint Foundation环境。

许可以下: CC-BY-SA归因
scroll top