Exception calling "GetList" with "1" argument
23,195
Solution 1
Try:
$spSite = Get-SPSite $mySiteUrl
$spWeb = $spSite.OpenWeb("people")
$cvDocumentLibrary = $spWeb.GetList("/people/User Resumes")
Solution 2
SPWeb.GetList() expects the Server Relative URL to a list. So in your example, it would be:
$spSite = Get-SPSite -Identity $mySite;
$spWeb = $spSite.OpenWeb();
$myList = $spWeb.GetList($spWeb.ServerRelativeUrl + "/Lists/MyList");
Solution 3
I ran into this same error message too. I discovered when I try to open a list from the parent/top level site using a relative URL, I encountered the error because of too many forward slashes returned. Example of the issue using Adam's code: If $mySite = "https://site.com", then ($spWeb.ServerRelativeURL + "/Lists/MyList") returns "//Lists/MyList". This isn't a valid relative URL. Remove the forward slash in front of Lists and the code below works for me.
$spSite = Get-SPSite -Identity $mySite;
$spWeb = $spSite.OpenWeb();
$myList = $spWeb.GetList($spWeb.ServerRelativeUrl + "Lists/MyList");
Author by
Admin
Updated on July 09, 2022Comments
-
Admin almost 2 years
I am getting the following exception when I tried to GetList:
Exception calling "GetList" with "1" argument(s): "<nativehr>0x80070002</nativehr><nativestack></nativestack>" At C:\Scripts\teaCvProfileUpdate\uploadTeaCvsToSharepoint.ps1:37 char:36 + $cvDocumentLibrary = $spWeb.GetList <<<< ("/people/User Resumes/Forms/") + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
These are the relavent 3 lines of code (powershell):
$spSite = Get-SPSite $mySiteUrl $spWeb = $spSite.OpenWeb("/") $cvDocumentLibrary = $spWeb.GetList("/people/User Resumes/Forms/")
Can somebody tell me why this is happening?
Thanks. :)