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?

4 Answers 4


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.

  • +1 nice, i didn't look beyond the error message
    – djeeg
    Commented Apr 19, 2011 at 7:36

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.


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"]



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

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.