1

Is there a way to get the items that are present in a particular view of a sharepoint library? Actually my library has multiple levels of folders like this:

Level1 Document set
Level2 Folders and some Items
Level3 Folders and some items ...so on

what I am trying to do is I will select the "Show all Items without folders" option in view and try to access all the items using powershell, since that will be easier. How can I do it? Here is my script as requested:

Add-PSSnapin Microsoft.SharePoint.PowerShell
$web = Get-SPWeb "http://MySite"
$library = $web.Lists["Test"]
$view = $library.Views["All Documents"]
foreach($item in $list.GetItems($view))
{
 write-host $item["Name"]
}

Actual content of All documents view Actual content of All documents view :

Content After Filter: Content After Filter :

The ouput is : A B C while it should be only A right?

  • Please share the result of your powershell script. Thanks. – KhalilG Mar 11 '15 at 10:50
  • @KGahbiche I have written the output. Don't have permission to take screenshot from server. – nayakasu Mar 11 '15 at 10:59
5

You need to use SPList.GetItems(SPView) method to get items from the view. Example:

$web = Get-SPWeb http://aissp2013
$list = $web.Lists["YourList"]
$view = $list.Views["ViewName"]
$items = $list.GetItems($view)
foreach($item in $items)
{
 #Play with item
}

UPDATE

Scrrenshot: enter image description here

  • I have tried that @Nadeem Yousuf but it returns all the items in original list not that particular view. I edited the 'All Documents' view and tried this it didn't work. – nayakasu Mar 11 '15 at 9:54
  • @Asu, not sure why this isn't working for you. see the results of my test run in attached screenshot. – Nadeem Yousuf Mar 11 '15 at 10:04
  • I added a filter saying 'Name = A' but after running script all the folders(A,B,C) were shown. I even tried the option "Show all items without folders" but in script output I got all folders. I can see the change in SP site but not in script output.. am I doing something wrong? – nayakasu Mar 11 '15 at 10:18
  • Tested that as well and working properly. Perhaps try editing the question. Add some screenshots and the script so that we can check what the issue is. – Nadeem Yousuf Mar 11 '15 at 10:31
  • I have edited the question.. – nayakasu Mar 11 '15 at 10:42

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.