Replace Image in sharepoint Template (.xml) in Powershell

I have a problem about “Replace Image in sharepoint Template (.xml)”.
I have saved a SPO Team-Website Template (.xml) in my computer through powershell (in below code The name of this Template is:Site1-Template.xml and it includes: Image, Text, .. .).
Then I want to replace my selected newImage(Redicon) to OldImage(Blueicon) in this .xml Template file.
I found any Code and I changed it but it doesn’t work. can you please help me.

p.n: Sorry for my bad english and thank you in advance for your help.

#Get the Web and get it's Template content
$webs = connect-pnponline "" | get-content -Path C:UsersTMPLSite1-Template.xml

#Iterate through webs
foreach ($web in $webs)

 #Get All Images from site's Root into $AllPages Array
  $AllPages = @($web.Files | Where-Object {$_.Name -match ".aspx"})

  #Iterate through all pages
   foreach($Page in $AllPages)
       #Web Part Manager to get all web parts from the page
        $webPartManager = $web.GetLimitedWebPartManager($Page.ServerRelativeUrl, (System.Web.UI.WebControls.WebParts.PersonalizationScope)::Shared)

       #Iterate through each web part
       foreach($webPart in $WebPartManager.WebParts)
            #Get the Content web part with specific Image
            if($webPart.Image -like "SiteAssets/SitePages/Site1-Template/Blueicon.jpg")
                  #Replace the Old Image
                  $webPart.Image = $webPart.Image.Replace("SiteAssets/SitePages/Site1-Template/Blueicon.jpg", " C:UsersTMPLSite1-TemplateRedicon.jpg")
                  #Save the changes
                  write-host "Updated '$($OldImage)' on $($web.URL)$($Page.ServerRelativeUrl)"


Connect-PnPOnline -Url Other Website
Apply-PnPProvisioningTemplate -Path C:UsersTMPLSite1-Template.xml