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 http://url.com
$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 http://url.com/../../DocumentLibrary
for example. But I'm apparently going at it wrong.
Any hints?
UPDATE 1:
So with a little inspiration from John below, I've modified my script:
$web = Get-SPWeb($completeUrl)
$spDocumentLibrary = $completeUrl + "/DocumentLibrary"
$site = New-Object Microsoft.SharePoint.SPSite($spDocumentLibrary)
$website = $site.OpenWeb()
$list = $website.GetList($spDocumentLibray)
This gets me the wanted document library, now I'm going for all the items inside it.
UPDATE 2:
foreach($item in $list) {
write-host "listItem: " $item.Title
}
This just gets me the same as $list
. Any ideas to what I'm doing wrong?
UPDATE 3:
It seems I also had to include the following to be able to do the foreach above:
$items = $list.GetItems()