0

i have export/import a publishing site collection as a subsite. but i read that the page layout links inside publishing pages are hard coded. and to update all the page layout links i found the following power-shell command:-

 function LoadSharePointPowerShellEnvironment
    {
        write-host
        write-host "Setting up PowerShell environment for SharePoint" -foregroundcolor Yellow
        write-host
        Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue
        write-host "SharePoint PowerShell Snapin loaded." -foregroundcolor Green
    }

    write-host
    LoadSharePointPowerShellEnvironment

    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
    [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Publishing")

    $web = Get-SPWeb -Identity "http://gvstg01/wikilibrary/test";

    $spPubWeb = [Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
    $pages = $spPubWeb.PagesList

    foreach($item in $pages.Items)
    {
      $pubPage = [Microsoft.SharePoint.Publishing.PublishingPage]::GetPublishingPage($item)

      $url = new-object Microsoft.SharePoint.SPFieldUrlValue($pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout].ToString())
      if($url -ne $null)
      {   
      $ss =$url.Url
        if($ss -match'TreeWikiLayout')
      {  
      $newurl = new-object Microsoft.SharePoint.SPFieldUrlValue("http://gvstg01/wikilibrary/test/_catalogs/masterpage/TreeWikiLayout.aspx, Enterprise Wiki Layout with Tree")
      $pubPage.Name
      $pubPage.CheckOut()
      $pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout] = $newurl
      $pubPage.ListItem.UpdateOverwriteVersion()

      $pubPage.ListItem.File.CheckIn("Fixed URL to page layout.", [Microsoft.SharePoint.SPCheckinType]::MajorCheckIn);
      }
        elseif($ss -match'EnterpriseWiki')
      {
      $newurl = new-object Microsoft.SharePoint.SPFieldUrlValue("http://gvstg01/wikilibrary/test/_catalogs/masterpage/EnterpriseWiki.aspx, Basic Page")
      $pubPage.Name
      $pubPage.CheckOut()
      $pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout] = $newurl
      $pubPage.ListItem.UpdateOverwriteVersion()

      $pubPage.ListItem.File.CheckIn("Fixed URL to page layout.", [Microsoft.SharePoint.SPCheckinType]::MajorCheckIn);

      }
      }

    }

but when i run the powershell command i got the following errors :-

PS C:\Windows\system32> powershell -noexit -file "C:\Users***\Deskto p\rr.ps1" Windows PowerShell Copyright (C) 2012 Microsoft Corporation. All rights reserved.

Setting up PowerShell environment for SharePoint

SharePoint PowerShell Snapin loaded.

GAC Version Location --- ------- -------- True v4.0.30319 C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.S... True
v4.0.30319
C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.S... Customer Service KB.aspx Value cannot be null. At C:\Users\admin\Desktop\rr.ps1:44 char:7 + $pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout] = ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : OperationStopped: (:) [], ArgumentNullException + FullyQualifiedErrorId : System.ArgumentNullException

test.aspx Value cannot be null. At C:\Users\admin\Desktop\rr.ps1:44 char:7 + $pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout] = ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : OperationStopped: (:) [], ArgumentNullException + FullyQualifiedErrorId : System.ArgumentNullException

test2.aspx Value cannot be null. At C:\Users\admin\Desktop\rr.ps1:44 char:7 + $pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout] = ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : OperationStopped: (:) [], ArgumentNullException + FullyQualifiedErrorId : System.ArgumentNullException

sd.aspx Value cannot be null. At C:\Users\admin\Desktop\rr.ps1:44 char:7 + $pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout] = ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : OperationStopped: (:) [], ArgumentNullException + FullyQualifiedErrorId : System.ArgumentNullException

test3.aspx Value cannot be null. At C:\Users\admin\Desktop\rr.ps1:44 char:7 + $pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout] = ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : OperationStopped: (:) [], ArgumentNullException + FullyQualifiedErrorId : System.ArgumentNullException

1.aspx Value cannot be null. At C:\Users\admin\Desktop\rr.ps1:44 char:7 + $pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout] = ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : OperationStopped: (:) [], ArgumentNullException + FullyQualifiedErrorId : System.ArgumentNullException

a.aspx Value cannot be null. At C:\Users\admin\Desktop\rr.ps1:44 char:7 + $pubPage.ListItem[[Microsoft.SharePoint.Publishing.FieldId]::PageLayout] = ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~ + CategoryInfo : OperationStopped: (:) [], ArgumentNullException + FullyQualifiedErrorId : System.ArgumentNullException

can anyone advice why my power shell script is raising errors?

Thanks

1

I am not sure about the script why it is throwing the error, I would rather recommend you to post his Blog may be he will give you answer why it is failing.

Did you check these commands from Gary. http://www.falchionconsulting.com/PowerShellViewer/Default.aspx

I would also recommend you to use the 3rd party tools which have the atleaset 14 days trail. If this is your only site collection then you can just download it and use for 14 days and move your sites.

I used ShareGate and Metalogix both good.

  • thanks for the reply, so will using these third party tools fix the layout problem ? i mean did u use them before to do such a task ? – john Gu Aug 26 '14 at 0:31
  • I used the ShareGate and its work like a charm for us. moving site collection to subsite etc... – Waqas Sarwar MVP Aug 26 '14 at 1:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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