3

How do i get each document or file name from Shared Documents using PowerShell script.

Thanks

  • You want to download all the documents? – Anuja Feb 26 '15 at 10:39
  • No i dont want to download. But just need the names of it using loop in powershell. – Ishani Feb 26 '15 at 10:40
5

You can use below Powershell.

$spweb = get-spweb -identity "http://yourdomain/yourweb"
# Use the "pretty name" of your library below
$list = $spweb.lists["Your Library"]
$listItems = $list.Items
# For each item
foreach ($listItem in $listItems)
{ 
   $DocumentTitle = $listItem.Name
   write-host "FileTitle -> $DocumentTitle"   
}

#Clean up
$spWeb.Dispose()
6
Get-SPWeb http://sharepoint/sites/xyz|
   Select -ExpandProperty Lists |
   Where { $_.Title -eq "Shared Documents" } |
   Select -ExpandProperty Fields | Select Title, InternalName

For more informaiton:

http://sharepointpromag.com/sharepoint/windows-powershell-scripts-sharepoint-info-files-pagesweb-parts

Following code will also help you

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

Function GetFiles($Folder)
{ 
   Write-Host "+"$Folder.Name

    foreach($file in $Folder.Files)
    {   
        Write-Host "`t" $file.Name
    }
     #Loop through all subfolders and call the function recursively
     foreach ($SubFolder in $Folder.SubFolders)
        {
            if($SubFolder.Name -ne "Forms")
            {  
                Write-Host "`t" -NoNewline
                GetFiles($Subfolder)

            }
        }
 }

#Get the Site collection 
$Site= Get-SPSite "http://sharepoint.com" 
       #Loop throuh all Sub Sites
       foreach($Web in $Site.AllWebs)
       {
        Write-Host "-----------------------------------------------------"
        Write-Host "Site Name: '$($web.Title)' at $($web.URL)"
        Write-Host "-----------------------------------------------------"
        foreach($list in $Web.Lists)
        {
           #Filter Doc Libs, Eliminate Hidden ones
            if(($List.BaseType -eq "DocumentLibrary") -and ($List.Hidden -eq $false) )
               { 
                GetFiles($List.RootFolder)
               }
        }
       }
3

This is the script that will print the names of all items in a library.

$web = Get-SPWeb <web address>
$list = $web.Lists["<document library/list name>"]
$items = $list.Items
foreach($i in $items){
   Write-Host $i.Name
}

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.