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
New-Object PSObject -Property $data | Select "List Name", "Item Name", "Version", "Created By", "Created Date", "Modified By", "Modified Date", "URL"

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

Below is a sample of what this script outputs:

enter image description here

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?

  • A list item isn't going to have an $item.File.Name. For a list, you'd probably want to do $item["Title"] or $item["ID"] – Eric Alexander Oct 20 '15 at 16:52
  • I'm assuming with that being done it will return item names from Lists but then return blank Item Names for Document Libraries right? How can I display Item Names for both Lists and Libraries? – Aspire27 Oct 20 '15 at 16:59

Thanks Eric Alexander as I have figured it out with some direction from you. I have found also that by changing this line:

"Item Name" = $item.File.Name


"Item Name" = $item.Name

That it returns both list names and file names from Doc Libraries as well. I tried what you posted but some Item Names returned blank. Not sure of what the reason was.

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.