0

I have a script that displays multiple columns and outputs to CSV file 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()
}




GetCheckedOutFiles($web) | Export-Csv -NoTypeInformation -Path C:\NewDocInventory.csv

Below is the part of the output and I'm mainly concerned with the Version column:

enter image description here

The Version column displays the current version of a file. Does anyone know how to get, in addition to the current version, all previous versions of the file. For example, FileA's current version is 12. I need to display version 12 all the way down to version 1 for this file. Can someone assist? I don't need links as I have been looking and no luck. Please advise with code.

0

I have found that adding foreach($version in $item.Versions) under foreach($item in $list.Item) and then adding "Version" = $version.VersionLabel under $data = @{ does the trick.

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.