2

I have a Powershell script that outputs data from all libraries in a site shown below:

 Add-PSSnapin Microsoft.sharepoint.powershell
$url = "http://contoso.com"
$site = New-Object Microsoft.SharePoint.SPSite($url)
$web = $site.OpenWeb()


function GetCheckedOutFiles($web)
{
Write-Host "Processing Web: $($web.Url)..."
        foreach ($list in ($web.Lists | ? {$_ -is [Microsoft.SharePoint.SPDocumentLibrary]})) {
            Write-Host "`tProcessing List: $($list.RootFolder.ServerRelativeUrl)..."
            foreach ($item in $list.CheckedOutFiles) {
                #$modifiedTime = $web.RegionalSettings.TimeZone
                if (!$item.Url.EndsWith(".aspx")) { continue }
                $data = @{
                    #"URL"=$web.Site.MakeFullUrl("$($web.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");
                     "Version" = $item["Version"]
                     "Title" = $item.Title
                     #"CheckedOut By" = $item.File.CheckedOutBy.Name
                     "#Time last Modified" = $modifiedTime.UTCToLocalTime($item.File.TimeLastModified)
                }
                New-Object PSObject -Property $data
            }
            foreach ($item in $list.Items) {

                #$modifiedTime = $web.RegionalSettings.TimeZone

                if ($item.File.CheckOutStatus -ne "None") {
                    if (($list.CheckedOutFiles | where {$_.ListItemId -eq $item.ID}) -ne $null) { continue }


                    $data = @{
                        "URL"=$web.Site.MakeFullUrl("$($web.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");
                        "Version" = $item["Version"]
                        "Library" = $item.Title
                        "Created By" = $item["Author"]
                        "Created Date" = $item["Created"]
                        "Modified By" = $item["Editor"]
                        "Modified Date" = $item["Modified"]
                        "Title" = $item.File.Name
                        "CheckedOut By" = $item.File.CheckedOutBy.Name
                        "Time last Modified" = $modifiedTime.UTCToLocalTime($item.File.TimeLastModified)
                    }
                    New-Object PSObject -Property $data
                }
            }

        }
foreach($subWeb in $web.Webs)
{
GetCheckedOutFiles($subweb)
}
        $web.Dispose()
}



#Get-DocInventory | Out-GridView
GetCheckedOutFiles($web) | Export-Csv -NoTypeInformation -Path C:\NewDocInventory.csv

In addition to outputting libraries how can I also output all lists from contoso.com? What line must I add to the script to pull lists as well? Can someone please advise?

  • the line foreach ($list in ($web.Lists | ? {$_ -is [Microsoft.SharePoint.SPDocumentLibrary]})) { is filtering out lists. Just do foreach ($list in ($web.Lists){}. – Eric Alexander Oct 15 '15 at 15:39
  • I have tried and I get error:( Sorry for the late response as I was recovering from being sick. But could you please advise? – Aspire27 Oct 19 '15 at 16:28
2

I found a much simpler script that does the trick shown below:

function Get-DocInventory([string]$siteUrl) {
  $site = New-Object Microsoft.SharePoint.SPSite $siteUrl
  $web = Get-SPWeb "http://contoso.com/sites/Depts/HTG"
  foreach ($list in $web.Lists) {

    foreach ($item in $list.Items) {
      foreach($version in $item.Versions){
        $data = @{
          "Version" = $version.VersionLabel
                        "List Name" = $list.Title
                        "Created By" = $item["Author"]
                        "Created Date" = $item["Created"]
                        "Modified By" = $item["Editor"]
                        "Modified Date" = $item["Modified"]
                        "Item Name" = $item.File.Name
                        "URL"=$web.Site.MakeFullUrl("$($web.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");
        }
        New-Object PSObject -Property $data | Select "List Name", "Item Name", "Version", "Created By", "Created Date", "Modified By", "Modified Date", "URL"
      }
    }
    $web.Dispose();
  }
}

Get-DocInventory  | Export-Csv -NoTypeInformation -Path C:\NewOutput.csv

This script will output all files and items from Libraries and Lists in a site.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.