0

I have a script that outputs checked out files in csv format below:

Add-PSSnapin microsoft.sharepoint.powershell
$url = "http://contoso.com/sites/Depts3/KDS"
$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 }

                    $wuse = $item.DirName.Substring($web.ServerRelativeUrl.Length)
                    $data = @{
                        "URL"=$web.Site.MakeFullUrl("$($web.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");
                        "Version" = $item["Version"]
                        "library" = $wuse
                        "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

The output of the script is as shows below enter image description here

My problem is that in the column library, I'm having trouble grabbing the document library of where these files come from. For example, the library column should display RP1MajorVersions for the output shown in the image. I have the line $wuse = $item.DirName.Substring($web.ServerRelativeUrl.Length) which should represent the Library and the line "library" = $wuse should output correctly but I have no luck. I don't need links I just need someone to show me a line of code that would work with the script I have attached.

1

Something like this in the for each library section?

$data = @{
 "URL"=$web.Site.MakeFullUrl("$($web.ServerRelativeUrl.TrimEnd('/'))/$($item.Url)");
 "Version" = $item["Version"]
 "Title" = $item.Title
 "Library" = $list.Title
 "CheckedOut By" = $item.File.CheckedOutBy.Name
 "Time last Modified" = modifiedTime.UTCToLocalTime($item.File.TimeLastModified)
}
0

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.