I have a PowerShell script below:
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
My problem is that when I run the script I get an error
"Cannot find an SPSite object that contains the following Id or Url:
http://contoso.com/sites/Test10
".
It doesn't make sense because when I use a different Url like http://contoso/sites/Departments/FRP
the script works.
I have tried these variations:
$web = Get-SPWebApplication "http://contoso.com/sites/Test10"
$web = Get-SPSite "http://contoso.com/sites/Test10"
$web = Get-SPWeb "http://contoso.com/sites/Test10"
But I still get the same error mentioned previously. Can someone tell me what is wrong with the script?