我收到了无法找到包含以下内容的SPSite ...错误

问题描述 投票:1回答:1

我在下面有一个PowerShell脚本,它输出一个站点的项目和文件列表:

 Add-PSSnapin Microsoft.SharePoint.PowerShell

    function Get-DocInventory([string]$siteUrl) {

    $web = Get-SPWeb "http://contoso.com/sites/Test10"

    foreach ($list in $web.Lists) {

    if($excludeLists -notcontains $list.Title){

    foreach ($item in $list.Items) {

    foreach($version in $item.Versions){



    $personField = $item.Fields.GetField("Author");

    $authorObject = $personField.GetFieldValue($item["Author"]);

    $authorName = $authorObject.LookupValue;



    $userField = $version.Fields.GetField("Editor");

    $editorObject = $userField.GetFieldValue($version["Editor"]);

    $editorName = $editorObject.LookupValue;



    $localOffset = +5;

    $modified = $version["Modified"] -as [datetime];

    if($modified.IsDaylightSavingTime()){$localOffset += 1;}

    $modifiedLocal = $modified.addHours(-$localOffset);



    $data = @{

    "Version" = $version.VersionLabel

    "List Name" = $list.Title

    "Created By" = $authorName

    "Created Date" = $item["Created"]

    "Modified By" = $editorName

    "Modified Date" = ($modifiedLocal -as
    [datetime]).DateTime

    "Item Name" = $item.Name

    }

    New-Object PSObject -Property $data | Select "List Name", "Item Name",
    "Version", "Created By", "Created Date", "Modified By", "Modified Date"

    }

    }

    $web.Dispose();

    }

    }

    }
Get-DocInventory | Expport-Csv -NoTypeInformation -Path C:\TestOutput.csv

我的问题是,当我运行脚本时,我收到一个错误:

"Cannot find an SPSite object that contains the following Id or Url: http://contoso.com/sites/Test10".

这没有意义,因为当我使用像http://contoso/sites/Departments/FRP这样的不同Url时,脚本可以工作。

我试过这些变化:

但我仍然得到前面提到的相同错误。有人能告诉我脚本有什么问题吗?如果http://contoso.com/sites/Test10被认为是SPSite,如果我使用第二个变体,它会不会起作用?

powershell url sharepoint-2010
1个回答
0
投票

您可以检查一些问题:

  1. 您使用的用户名具有SQL Server的管理权限。
  2. 您已经以管理员身份运行Windows PowerShell ISE。
  3. 您正在从安装了共享点的应用程序服务器运行该脚本。
© www.soinside.com 2019 - 2024. All rights reserved.