问题
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