SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to delete a field (site column bound to managed metadata) in a view with the following powershell script:

$spWeb = Get-SPWeb -identity http://servernamehere/docs/test/sitename
$spView = $spWeb.GetListFromUrl("/EMails/Forms/AllItems.aspx")
$spField = $spView.Fields["Document Author"]
$spView.ViewFields.Delete($spField["Document Author"])

I get this error on line2: v Exception calling "GetListFromUrl" with "1" argument(s): "Cannot complete this action.

Please try again." At line:1 char:32 + $spView = $spWeb.GetListFromUrl <<<< ("/EMails/Forms/AllItems.aspx") + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException

What am I doing wrong?

share|improve this question

You have several mistakes here:

  1. As djeeg mentioned, you need to use server relative url when calling GetListFromUrl, or (simplier) do not pass leading slash to GetListFromUrl, i.e. GetListFromUrl("Emails/Forms/AllItems.aspx"), I tested this code and it works for me.
  2. You are using GetListFromUrl, which returns SPList, but you assign it to $spView. So probably you have a mistake here.
  3. Fields indexer uses field internal name, which cannot contain white spaces, so you need to write smth like Fields["Document_x0020_Author"]
  4. You don't need to fetch the SPField, you can use it's name to delete from ViewFields, for example, $spView.ViewFields.Delete("Document_x0020_Author")

Whole script will be:

$spWeb = Get-SPWeb http://servernamehere/docs/test/sitename
$spList = $spWeb.GetListFromUrl("EMails/Forms/AllItems.aspx")
$spView = $spList.DefaultView

This script worked for me without any errors.

share|improve this answer
+1 nice, i didn't look beyond the error message – djeeg Apr 19 '11 at 7:36
:) thanks, djeeg! – Andrey Markeev Apr 19 '11 at 8:28

A third alternative is to use the new TryGetList() method in SP2010:

$spWeb = Get-SPWeb http://servernamehere/docs/test/sitename$spList = $spWeb.GetListFromUrl("EMails/Forms/AllItems.aspx")
$list = $spWeb.Lists.TryGetList('my list title')
if ( $list )
    # do something intelligent here

This will get the list from title without any nullreference exceptions if the list isnt there.

More info here.

share|improve this answer

GetListFromUrl says to use GetListFromWebPartPageUrl

And the url probably needs to be server relative

SPList list = web.GetListFromWebPartPageUrl("/docs/test/sitename/EMails/Forms/AllItems.aspx");

Or have you tried $spWeb.Lists["EMails"]

share|improve this answer

Do you have any other webpart added to the AllItems.aspx page.. if so it will throw this error. can be checked by appending "?contents=1" to the url


  • you can use "/EMails/Forms/AllItems.aspx" or "http://servernamehere/docs/test/sitename/EMails/Forms/AllItems.aspx" as parameter to GetListFromUrl

  • you can use "Document Author", because 2010 accepts both displayname as well as internal name.. first it will try to resolve using internal name and then display name

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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