How do i get each document or file name from Shared Documents using PowerShell script.
Thanks
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityYou 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()
Get-SPWeb http://sharepoint/sites/xyz|
Select -ExpandProperty Lists |
Where { $_.Title -eq "Shared Documents" } |
Select -ExpandProperty Fields | Select Title, InternalName
For more informaiton:
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)
}
}
}
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
}