0

I have a webpart applied on a sample page: http://mysite/page/registration

I need to change the TYPE property of the webpart on this page.

1

i found 1 way

$site = new-object Microsoft.SharePoint.SPSite("http://server/")
$web = $site.OpenWeb("/")
$resultsPath = "Paginas/default.aspx"
$page = $web.GetFile($resultsPath)
$page.CheckOut()
$wpm = $web.GetLimitedWebPartManager($resultsPath, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
$wpm.WebParts | ft Title, StorageKey 
$refinerManager = $wpm.WebParts | Where-Object {$_.Title -eq "WP_IntegracaoLumis"}
Write-Host $refinerManager
$refinerManager.Tipo= "DEFAULT 2"
$wpm.SaveChanges($refinerManager)  #ERROR
write-Host 
Write-Host "WebPart em $resultsPath Alterada"

$page.CheckIn("Test")
$page.Publish("Test")
$web.Close()
$site.Close()
| improve this answer | |
0

Following are the steps with powershell commands to update the webpart property

  1. Get the site
  2. Since we have to throughout the site collection, among all the web we will go through all the webs
  3. Now, we need to read welcome page of every web
  4. Once we got the welcome page, get the file and checkout it
  5. Now from welcome page we will get webpart manager
  6. Now we have webpartmanager from the page, we can traverse through all webparts and check for the webpart for which we need to set/update the property
  7. Check in and Publish the file - #more details – SPFile.CheckIn()
  8. Finally dispose the site object

Below the complete powershell script

$site = Get-SPSite "SiteCollectionURL"
$webcoll = $site.AllWebs
 #Step through each web in site collection
foreach ($web in $webcoll) {
#Get the root folder
$folder = $web.RootFolder
#Get the welcome page
$welcomepage = $folder.WelcomePage
$file = $web.GetFile("$welcomepage")
$file.CheckOut()
$wpm = $web.GetLimitedWebPartManager("$welcomepage", [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
foreach($webpart in $wpm.WebParts){
            if($webpart.MyUniqueProperty){
if(!$webpart. MyUniqueProperty){
$webpart. MyUniqueProperty = $ MyUniquePropertyValue(Value which need to be Set/Update)
                                    $wpm.SaveChanges($webpart)
}#First If
}#Second If
}#Foreach
$file.CheckIn("Updated/Set property of webpart",1)
            $file.Publish("Updated/Set property of webpart")
            $site.Dispose()           
}#foreach
| improve this answer | |

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.