我在下面有一个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,那么如果我使用了第二种变体,它是否会起作用?
答案 0 :(得分:0)
您可以检查一些问题: