Change Hero webpart URLs with PNP PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-1782590%22%20slang%3D%22en-US%22%3EChange%20Hero%20webpart%20URLs%20with%20PNP%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1782590%22%20slang%3D%22en-US%22%3E%3CDIV%20class%3D%22bi6gxh9e%22%3E%3CDIV%20class%3D%22_1mf%20_1mj%22%3E%3CSPAN%3EHello.%20Is%20there%20a%20way%20to%20modify%20a%20URL%20in%20the%20Hero%20webpart%20via%20PnP%20PowerShell%3F%20I've%20got%20the%20properties%20changed%20in%20a%20variable%2C%20but%20can't%20find%20a%20way%20to%20put%20them%20back%2C%20because%20set-pnpclientsidewebpart%20only%20accepts%20JSON%20data%2C%20and%20the%20changed%20URL%20is%20in%20the%20HTML%20PropertiesData.%20%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%20class%3D%22bi6gxh9e%22%3E%3CDIV%20class%3D%22_1mf%20_1mj%22%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%20class%3D%22bi6gxh9e%22%3E%3CDIV%20class%3D%22_1mf%20_1mj%22%3E%3CSPAN%3EThanks%20for%20any%20idea.%20%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%20class%3D%22bi6gxh9e%22%3E%3CDIV%20class%3D%22_1mf%20_1mj%22%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FDIV%3E%3CDIV%20class%3D%22bi6gxh9e%22%3E%26nbsp%3B%3C%2FDIV%3E%3CDIV%20class%3D%22bi6gxh9e%22%3E%3CDIV%20class%3D%22_1mf%20_1mj%22%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FDIV%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-powershell%22%3E%3CCODE%3EConnect-PnPOnline%20-Url%20https%3A%2F%2Ftenant.sharepoint.com%2Fsites%2FTestRootSite%2FTestSite1%0A%26nbsp%3B%0A%24webpart%3DGet-PnPClientSideComponent%20-Page%20Home%0A%26nbsp%3B%0A%26nbsp%3B%0Aforeach(%24wp%20in%20%24webpart)%0A%7B%0Aif(%24wp.Title%20-eq%20%22Hero%22)%0A%7B%0A%24HeroInstanceId%3D%24wp.InstanceId%0A%24heroprops%3DGet-PnPClientSideComponent%20-InstanceId%20%24HeroInstanceId%20-Page%20Home%0A%24heropropsHTML%3D%24heroprops.HtmlPropertiesData%0A%24test%3D%24heropropsHTML.replace(%22https%3A%2F%2Fwww.pbnet.ro%22%2C%22https%3A%2F%2Fwww.bing.com%22)%0A%26nbsp%3B%0A%26nbsp%3B%0ASet-PnPClientSideWebPart%20-Page%20%22Home%22%20-Identity%20%24HeroInstanceId%20HtmlPropertiesData%20%24test%0ASet-PnPClientSidePage%20-Identity%20%22Home%22%20-Publish%0A%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CDIV%20class%3D%22_1mf%20_1mj%22%3E%3CSPAN%3EThanks%2C%3C%2FSPAN%3E%3C%2FDIV%3E%3CDIV%20class%3D%22_1mf%20_1mj%22%3E%3CSPAN%3EAndrei%3C%2FSPAN%3E%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1782590%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ESharePoint%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Highlighted
New Contributor
Hello. Is there a way to modify a URL in the Hero webpart via PnP PowerShell? I've got the properties changed in a variable, but can't find a way to put them back, because set-pnpclientsidewebpart only accepts JSON data, and the changed URL is in the HTML PropertiesData.
 
Thanks for any idea.
 
 
 

 

Connect-PnPOnline -Url https://tenant.sharepoint.com/sites/TestRootSite/TestSite1
 
$webpart=Get-PnPClientSideComponent -Page Home
 
 
foreach($wp in $webpart)
{
if($wp.Title -eq "Hero")
{
$HeroInstanceId=$wp.InstanceId
$heroprops=Get-PnPClientSideComponent -InstanceId $HeroInstanceId -Page Home
$heropropsHTML=$heroprops.HtmlPropertiesData
$test=$heropropsHTML.replace("https://www.pbnet.ro","https://www.bing.com")
 
 
Set-PnPClientSideWebPart -Page "Home" -Identity $HeroInstanceId HtmlPropertiesData $test
Set-PnPClientSidePage -Identity "Home" -Publish
}
}

 

Thanks,
Andrei
0 Replies