Khaine775 Khaine775 - 1 year ago 108
PowerShell Question

Getting a list of items from document library using PowerShell in SharePoint

So if I have the URL for a Document Library, how can I get all the items (in this case, folders) from inside the library? I've tried a few different things, but I can't seem to get it.

This is what I've tried so far:

$web = Get-SPWeb($completeUrl)
$spDocumentLibrary = $completeUrl + "/DocumentLibrary"
$spSite = Get-SPSite -Identity
$website = $spSite.OpenWeb()
$listItem = $website.GetListItem($completeUrl)

And it fails with an
Exception calling "GetListItem" with "1" argument(s)...

I'm not reeaally sure where to go from here. What I'm interested in is getting all the folders I have in the document library, which I know is found at
$completeUrl + /DocumentLibrary
which would equal something like
for example. But I'm apparently going at it wrong.

Any hints?

Answer Source

I do not know your SharePoint library construction, however, from my point of view, you are missing list selection.

$spDocumentLibrary = $completeUrl + "/DocumentLibrary"
$spSite = Get-SPSite -Identity
$website = $spSite.OpenWeb()
$list = $website.Lists["List_Name_Here"]
$items = $list.GetItems()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download