Get a collection of items in document library/list

六月ゝ 毕业季﹏ 提交于 2019-12-23 03:48:13

问题


I'm new to Powershell. What I'm trying to do is get a list of all the documents in a document library. I have an absolute URL of the document library I want to process, for example.

Essentially what I want is a reference to the document library so I can send some CAML queries to it.

http://sharepoint2013/sites/superdupersite/shared%20documents

Add-PSSnapin Microsoft.SharePoint.Powershell

$items = Get-SPList "http://sharepoint2013/sites/superdupersite/shared%20documents"

foreach ($item in $item) {
       #process
}

But it doesn't seem to work. How can I do this in powershell?


回答1:


In your code will return "$items" will contain an SPList object if it works in the expected manner. Try this:

Add-PSSnapin Microsoft.SharePoint.Powershell

$site =  Get-SPSite "http://sharepoint2013/sites/superdupersite/"
$web = $site.OpenWeb()
$list = $web.Lists[Shared Documents] <Title of the list goes here>
$items = $list.GetItems()

foreach ($item in $items) {
   #process
}

Happy scripting =)



来源:https://stackoverflow.com/questions/31843222/get-a-collection-of-items-in-document-library-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!