Thursday, October 1, 2015

List all documents

Recently I had a task to create list of all documents uploaded in certain SharePoint site. Not a hard task you might think. But when you have dozens of libraries all containing hundreds of documents things are getting complicated.

So I created function called Get-Documents which helped me greatly:

function Get-Documents ()
    {
    Add-PSSnapin Microsoft.SharePoint.PowerShell
    $web = get-spweb (Read-Host "Enter Site URL")
        foreach ($list in $web.Lists)
            {
            if ($list.BaseType -eq "DocumentLibrary")
                {
                foreach ($item in $list.Items)
                    {
                    $data = @{
                
                                "Web" = $web.Url
                                "list" = $list.Title
                                "Item ID" = $item.ID
                                "Item URL" = $item.Url
                                "Item Title" = $item.Title
                                "Item Name" = $item.Name
                                "Item Created" = $item["Created"]
                                "Item Modified" = $item["Modified"]
                                "File Size" = $item.File.Length/1KB
                            }
                    New-Object PSObject -Property $data
                    }
                }
            $web.Dispose();
            }
    }

Get-Documents | Out-GridView
#Get-Documents | Export-Csv -NoTypeInformation -Path c:\temp\inventory.csv

Function takes all relevant (for me) information for each document from document libraries and put it in custom object.

Later you can take results and put it in grid view or export it to csv file.

 


by Krsto Savic via Everyone's Blog Posts - SharePoint Community

No comments:

Post a Comment