0

I'm quite new to SharePoint and powershell scripting. I need some assistance in getting document details of the below from Mysite.

It currently has several user profiles storing both their Personal and Shared docs. I need to get the below details across both libraries:

  • Document names
  • Usernames
  • Date modified

So far I've tried using the below script which comes close to what I'm looking for, but info is quite limited.

It gets the user's profile URL (so that covers the usernames bit) and the number of documents, but not the other details stated above.

Please help on how I can get the extra info. I suspect I'll have to query more in the 'Select-Object' line, but I'm unsure as to what the keywords might be?

    Add-PSSnapin Microsoft.SharePoint.PowerShell

Start-SPAssignment -Global

$OutputFile = "C:\temp\MysiteDocsProd.csv"

$results = @()


$webApps = Get-SPWebApplication https://mysite.sharepoint.com
foreach($webApp in $webApps)
{
    foreach($siteColl in $webApp.Sites)
    {
        foreach($web in $siteColl.AllWebs)
        {
            $webUrl = $web.url
            $docLibs = $web.Lists | Where-Object {$_.baseType -eq "DocumentLibrary"}
            $docLibs | Add-Member -MemberType ScriptProperty -Name WebUrl -Value {$webUrl}
            $results += ($docLibs | Select-Object -Property WebUrl, Title, ItemCount)
        }
    }
}

$results | Export-Csv -Path $OutputFile -NoTypeInformation


Stop-SPAssignment -Global

Thanking you in advance.

1 Answer 1

0

In order to get the all file name details, you need to loop through the items collection object.

Below is the document library inventory function where you just need to pass your mysite URL.

    #Original Code provided by Gary Lapoint
    # http://blog.falchionconsulting.com

    [void]   [System.Reflection.Assembly]::LoadWithPartialName(“Microsoft.SharePoint”)
    function Get-DocumentLibraryInventory([string]$siteUrl) {
     $site = New-Object Microsoft.SharePoint.SPSite $siteUrl
    foreach ($web in $site.AllWebs) {
    foreach ($list in $web.Lists) {
    if ($list.BaseType -ne “DocumentLibrary”) {
       continue
      }
    foreach ($item in $list.Items) {
    $data = @{
     “Site” = $site.Url
     “Web” = $web.Url
     “list” = $list.Title
      “Item ID” = $item.ID
      “Item URL” = $item.Url
       “Item Title” = $item.Title
       “Item Created” = $item[“Created”]
        “Item Modified” = $item[“Modified”]
       “File Size” = $item.File.Length/1KB
     }
        New-Object PSObject -Property     $data
    }
             }
              $web.Dispose();
                }
                $site.Dispose()
                }
                 $sitecollection = read-host     “Enter Site Collection Url”

#Get- DocumentLibraryInventory    “http://sp2007” | Out-GridView
Get-DocumentLibraryInventory $sitecollection  | Export-Csv -NoTypeInformation -Path Report_SC_Docs.csv

Reference URL :

GET A LIST OF ALL DOCUMENTS AND ITEMS IN DOCUMENT LIBRARIES WITH POWERSHELL

1
  • Thanks for that SP Expert. I tried the above and it gave me URL details of pages within the site. It didnt bring up details of the subsites created for each user profile. Apologies if i wasn't clear to begin with.
    – adrianjc
    Commented Feb 27, 2020 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.