3

I wan to change the page name with Power shell script. When I had run the script I was given an spexception error:

Exception calling "CheckOut" with "0" argument(s): "The URL 'en/articles/kbarticles/Pages/R2-1_articles_Testing.aspx' is invalid. It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web." At line:1 char:1 + $spFile.CheckOut() + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SPException

The below script was used for update the name of the page:

$spWeb = Get-SPWeb("here i am given the web url")
$spFile = $spWeb.GetFile("full url with page name")
$spFile.CheckOut("Online",$null)    ////here i am getting the error(spexception)
$spFile.Properties["Name"] = "Pages/R2-1_articles_Testing_New"
$spFile.Update()
$spFile.CheckIn("Update page layout via PowerShell",[Microsoft.SharePoint.SPCheckinType]::MajorCheckIn)
$spWeb.Dispose()
5
  • Thanks for your replay, but i am run the script same as your updates.Still i am getting the same error(Spexception) Commented Jan 3, 2014 at 10:36
  • Exception calling "CheckOut" with "0" argument(s): "The URL 'en/articles/kbarticles/Pages/R2-1_articles_Testing.aspx' is invalid. It may refer to a nonexistent file or folder, or refer to a valid file or folder that is not in the current Web." At line:1 char:1 + $spFile.CheckOut() + ~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : SPException Commented Jan 3, 2014 at 12:19
  • the above exception was i am facing Commented Jan 3, 2014 at 12:20
  • when i had run the script by power shell $spFile.CheckOut() Commented Jan 3, 2014 at 12:21
  • Please see my updated answer below Commented Jan 3, 2014 at 12:24

1 Answer 1

3

Get-SPWeb does not need to have "(" and ")" around the parameters. Try:

$spWeb = Get-SPWeb "web url"

also, use $spFile.CheckOut() without any parameters.

Full script:

$spWeb = Get-SPWeb "here i am given the web url"
$spFile = $spWeb.GetFile("full url with page name")
$spFile.CheckOut()
$spFile.Properties["Name"] = "Pages/R2-1_articles_Testing_New"
$spFile.Update()
$spFile.CheckIn("Update page layout via PowerShell",[Microsoft.SharePoint.SPCheckinType]::MajorCheckIn)
$spWeb.Dispose()

Also, take a look at this similar question, specifically the part about checking if the page is in a state that allows it to be checked out (Pseudo code cited from a comment on that question):

$fooWeb = Get-SPWeb("FooWebURL");
$fooFile = $fooWeb.GetFile("FooFile");

if($fooFile.CheckOutType -eq "None" -And $fooFile.LockType -eq "None")
{ 
    $fooFile.CheckOut()
    Write-Host $fooFile.Name Checked out 6.
} 
else 
{ 
    Write-Host $fooFile.Name already Checked out or locked 
} 

$fooWeb.Dispose()

Update after Error message was posted

To use the $spWeb.GetFile() you must specify a FULL, existing URL to the file, which you are not providing right now!

It should look something like http://siteadress/possiblysubweb/Pages/R2-1_articles_Testing.aspx, so you are missing part of the url.

4
  • $spFile.CheckOut() should do the trick. Commented Jan 3, 2014 at 10:10
  • Yepp, that feels like the real error :) Commented Jan 3, 2014 at 10:11
  • $spFile = $spWeb.GetFile("collabsl-sp13:2009/en/articles/kbarticles/Pages/…) this is the full URL i am given Commented Jan 3, 2014 at 12:43
  • seems you are missing the http:// or https:// part? Also what URL are you using in Get-SPWeb? Should be http(s)://collabsl-sp13:2009/en/articles/kbarticles Commented Jan 3, 2014 at 12:45

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.