I have a PowerShell script that outputs to a CSV file all items from all Lists and all files from all Document Libraries in a Site shown below:
function Get-DocInventory([string]$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
Below is a sample of what this script outputs:
In the output shown above Arc Items, Archived Stuff, and Boats are the names of Lists. On the other hand, Content Affiliate and Cross References are the names of Document Libraries. My problem is that the script outputs only Item Names from Document Libraries and not Lists. What line should I add in order to output Item Names from Lists as well? In other words, how can I display the names of items contained in a List? Can someone please assist?