I have a powershell script that display a list of files that are checked out all users in a site and exports the output as a csv file:
Add-PSSnapin Microsoft.Sharepoint.Powershell
$url = "contoso.com"
$site = New-Object Microsoft.SharePoint.SPSite($url)
$web = $site.OpenWeb()
$list = $web.Lists
function Get-DocInventory() {
$web = Get-SPWeb "http://portal.contoso.com"
foreach ($list in $web.Lists) {
if ($list.BaseType -eq "DocumentLibrary") {
$dList = [Microsoft.Sharepoint.SPDocumentLibrary]$list
$items = $dList.Items
$files = $dList.CheckedOutFiles
foreach($file in $files){
foreach($item in $items){
if($item["Checked Out To"] -ne $null){
$wuse = $file.DirName.Substring($web.ServerRelativeUrl.Length)
$modifiedTime = $web.RegionalSettings.TimeZone
$data = @{
"Version" = $item["Version"]
"library" = $wuse
"URL" = $web.Url + ('/') + $item.Url
"Title" = $file.LeafName
"CheckedOut By" = $file.CheckedOutBy.Name
"Time last Modified" = $modifiedTime.UTCToLocalTime($file.TimeLastModified)
}
}
New-Object PSObject -Property $data
}
}
}
}
$web.Dispose();
}
$site.Dispose()
}
Get-DocInventory | Export-Csv -NoTypeInformation -Path D:\Docinventory.csv
I have an example of what the script outputs as shown below:
My question is, can someone please help/tell me why for the example shown above, it duplicates the file (Orangutans.docx) multiple times? In addition, the output displays the incorrect URL. The putout should only display one URL and it should be http://contoso.com/sites/Depts3/KDS/RP1MajorVersions/Orangutans.docx.