I have used the below code for change the web part properties.how to change the web part zone index in existing web part in the page? My code is :

 $pagePath = "Pages/default.aspx"
    $pageUrl = $SiteURL + $pagePath
    $web = Get-SPWeb $SiteURL
    $PublishingWeb=[Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
    $Page = $PublishingWeb.GetPublishingPages()

    $Page.CheckOut()
    $spWebPartManager = $web.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

    foreach ($webpart in ($spWebPartManager.WebParts | Where-Object {$_.Title -eq "Sample Name"}))
    {
     $spWebPartManager.SaveChanges($webpart);  
     break;
    }
$Page.CheckIn("checkin")

Suggest any idea.

share|improve this question

Use SPLimitedWebPartManager.MoveWebPart to move the webpart to new zone or index. Example:

$zoneId = "5"
$zoneIndex = "NewOrOldZone"
$spWebPartManager.MoveWebPart($webpart, zoneId, zoneIndex);
$spWebPartManager.SaveChanges($webpart);  
share|improve this answer

Try below code:

$pagePath = "Pages/default.aspx"
$pageUrl = $SiteURL + $pagePath
$web = Get-SPWeb $SiteURL
$PublishingWeb=[Microsoft.SharePoint.Publishing.PublishingWeb]::GetPublishingWeb($web)
$Page = $PublishingWeb.GetPublishingPages()

$Page.CheckOut()
$spWebPartManager = $web.GetLimitedWebPartManager($pageUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)

$wp = $spWebPartManager.WebParts | Where-Object { $_.Title -eq "Sample Name" }
#change the zone according to that in your layout
$wp.ZoneID = "MiddleZone" 
$spWebPartManager.SaveChanges($wp)
$Page.CheckIn("checkin",[Microsoft.SharePoint.SPCheckinType]::MajorCheckIn)
$web.Close()
share|improve this answer

Your Answer

 
discard

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.