1

I'm trying to get a list, more precisely the Document Library with PowerShell, but I get the following exception and I'm stuck on what I should change:

Exception calling "GetList" with "1" argument(s)
+spDocLib = $spWeb.GetList("Dokumenter")

This is my script code:

function GetDocumentLibrary($completeUrl) {

    $web = Get-SPWeb($completeUrl)

    $DocumentLibrary = $completeUrl + "/Documentlibrary"

    $spSite = Get-SPSite -Identity http://url.com

    $spWeb = $spSite.OpenWeb()  

    $spDocLib = $spWeb.GetList("Dokumenter")
}

Maybe I'm going the wrong way to get to the document library?

1 Answer 1

2

Check below solution :

$spSite = Get-SpSite "Your URL";
$List = $spSite.RootWeb.Lists["List or library Name"];

You can use below method also .

public SPList TryGetList(
    string listTitle
)

It gives null if list is not exist.

You want to use getList() methos than you have to pass guid of the list.

public SPList GetList(
    Guid uniqueId,
    bool fetchMetadata
)

Tell me if have any query: :)

2
  • Thanks for your reply. When I try to get $spSite.RootWeb.Lists["listname"], $List is empty. Any ideas?
    – Khaine775
    Aug 18, 2016 at 6:15
  • You have to pass "Title " of the list as value
    – Dipen Shah
    Aug 19, 2016 at 8:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.