首先,如果这是一个明显的问题,我首先搜索了很多问题,但找不到解决方案。

当我打开一个 spsite 在这样的Powershell中:

 $spsite = Get-SPSite "https://adress"

然后我尝试将所有网络如此

 $spsite.allwebs

我收到以下错误:

$spsite.allwebs : Exception has been thrown by the target of an invocation
+ CategoryInfo          : NotSpecified: (:) [], TargetInvocationExcept
+ FullyQualifiedErrorId : System.Reflection.TargetInvocationException

我不明白我在做什么错,在我的另一台SP服务器上这很好。

提前致谢,

编辑 更明确我的问题,我将在这里发布2个屏幕截图,您可以看到我已登录为 sp_admin 我是网站集合中的主要管理员。

enter image description here

在这里,您可以看到我执行的命令和我收到的错误。

enter image description here

编辑2 $spsite.gettype 输出:

PS C:\Users\sp_admin> $spsite.GetType()

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    SPSite                                   System.Object
有帮助吗?

解决方案

我认为这是一个直接的权限问题。 Get-Spsite将允许您检索Spsite对象(...至少一个部分),而无需对该站点收集的权限。但是,当您尝试访问allwebs集合时,它会引发错误。

为了验证这一点,我创建了一个新的站点集合,并使我以外的其他人成为主要和辅助站点集合管理员。然后,我对该站点集合进行了get-spsite,然后返回Spsite对象,但是当我访问allwebs集合时,它与您在上面看到的完全相同。

其他提示

纠正此错误所需的所有权限:

  • SPSITE的站点收集管理员(无论是通过中央管理员还是站点设置提供)
  • Powershell脚本管理: add-spshelladmin domain\username
  • 内容数据库上的PowerShell脚本管理员: get-spcontentdatabase | add-spshelladmin domain\username

请注意,PowerShell命令必须由农场帐户(或已经拥有这些权限的其他人)运行

语法是正确的。您是否可以与正在执行PowerShell提示的用户访问网站集合中的所有站点?可能是其中一个网站上拒绝的访问权限...

这个代码对我有用!

[Microsoft.SharePoint.SPSecurity]::RunWithElevatedPrivileges({
$Site = Get-SPSite $siteUrl
Foreach ($web in $Site.AllWebs)
{
#do something..
$web.Dispose()
}   
$Site.Dispose()
});  

https://stackoverflow.com/questions/13142327/cannot-get-basic-sharepoint-powershell-script-script-to-run

我发现这种方法非常可靠,因为错误消息也可能是由中央管理锁定的站点引起的。在这种情况下,提升权限仍然会产生错误。这是对我有用的原因。

try{
  $allWebs = ($site | Select-Object -ExpandProperty AllWebs)
  foreach($web in $allWebs){
    # do something
  }
} catch {
 if($_.Exception.Message -match "Access to this Web site has been blocked."){
    Write-Warning "`nSite Collection Locked: '{0}'`n" -f $site.Url
  } else {
    # something else is needed like script access to db or site collection full control
  }
}
许可以下: CC-BY-SA归因
scroll top