locked
Update specific webparts RRS feed

  • Question

  • moved a Farm to new domain by building new farm and attached the Content DB  - changed the Site collection admin and converted all users with the move-spuser cmdlet

    However there's a lot of contact details webparts that aren't "updated" - so e.g. in the contact details webpart are set: 
    contoso\userinitials  

    it should be fabrikam\userinitials

    How can I update all this webparts or is it a manual process, or is a matter of time before the webpart are updated due to the move-sp-user? 

    Found this script - but don't know the syntax for changing the contoso with fabrikam

    #Get All Webs (sites)
    $webs = Get-SPWebApplication "http://sharepoint.Crescent.com" | Get-SPSite -Limit All | Get-SPWeb -Limit All
      
     #Iterate through webs
     foreach ($web in $webs)
     {
      #Get All Pages from site's Root into $AllPages Array
      $AllPages = @($web.Files | Where-Object {$_.Name -match ".aspx"})
      
      #Search All Folders for Pages
      foreach ($folder in $web.Folders)
          {
              #Add the pages to $AllPages Array
              $AllPages += @($folder.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)
              {
                $OldTitle=$webPart.title
                #Get the Content Editor web part with specific Title
                if($webPart.title -like "*Crescent Inc*")
                 {
                      #Replace the Old Title
                      $webPart.title = $webPart.title.Replace("Crescent Inc.", "Lunar Inc.")
            
                      #Same method goes to update any other custom properties.
                      #E.g. To update Page viewer web part's link property:
                      #$webPart.ContentLink = "http://www.sharepointdiary.com"
                      #To set built-it properties, E.g. To set Set the Chrome type programmatically use:
                      #$webPart.ChromeType = [System.Web.UI.WebControls.WebParts.PartChromeType]::TitleAndBorder
                       
                      #Save the changes
                      $webPartManager.SaveChanges($webPart)
                     
                      write-host "Updated '$($OldTitle)' on $($web.URL)$($Page.ServerRelativeUrl)"
                 }
             }
          }
      }
    





    • Edited by JmATK Wednesday, July 4, 2018 3:42 PM
    Wednesday, July 4, 2018 3:27 PM

All replies

  • Hi JmATK,

    You can use the following commands to change the Contact property of Contact Details web part:

    #Get All Webs (sites)
    $webs = Get-SPWebApplication "<your web application url>" | Get-SPSite -Limit All | Get-SPWeb -Limit All
      
     #Iterate through webs
     foreach ($web in $webs)
     {
      #Get All Pages from site's Root into $AllPages Array
      $AllPages = @($web.Files | Where-Object {$_.Name -match ".aspx"})
      
      #Search All Folders for Pages
      foreach ($folder in $web.Folders)
          {
              #Add the pages to $AllPages Array
              $AllPages += @($folder.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 Editor web part with specific Title
                if($webPart.title -like "*Contact Details*")
                 {
                      #$webPart.ContactLoginName
                      $webPart.ContactLoginName = $webPart.ContactLoginName.Replace("oldDomain", "newDomain")
                         
                      #Save the changes
                      $webPartManager.SaveChanges($webPart)
                     
                      #write-host "Updated '$($OldTitle)' on $($web.URL)$($Page.ServerRelativeUrl)"
                 }
             }
          }
      }

    Thanks,

    Wendy


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Thursday, July 5, 2018 7:13 AM
  • Hi Wendy 

    Thanks - but I'm getting "error/exception" -> You need to check out the file

    • Edited by JmATK Thursday, July 5, 2018 3:02 PM
    Thursday, July 5, 2018 2:49 PM
  • Hi JmATK,

    This error occurs because you are using Publishing page. 

    I changed my commands as the following, please have a try:

    #Get All Webs (sites)
    $webs = Get-SPWebApplication "http://sp10" | Get-SPSite -Limit All | Get-SPWeb -Limit All
    
    #Iterate through webs
    foreach ($web in $webs)
    {
        #Get All Pages from site's Root into $AllPages Array
        $AllPages = @($web.Files | Where-Object {$_.Name -match ".aspx"})
      
        #Search All Folders for Pages
        foreach ($folder in $web.Folders)
        {
            #Add the pages to $AllPages Array
            $AllPages += @($folder.Files | Where-Object {$_.Name -match ".aspx"})
        }
     
        #Iterate through all pages
        foreach($Page in $AllPages)
        {
            if($Page.CheckOutType -eq "None")
            {
                $Page.CheckOut()
                $Page.CheckOutType
                #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)
                {
                    $OldTitle=$webPart.title
                    #Get the Content Editor web part with specific Title
                    if($webPart.title -like "*Contact Details*")
                    {
                    
                        #$webPart.ContactLoginName
                        write-host "Page'$($Page)' CheckOut"
                        $webPart.ContactLoginName = $webPart.ContactLoginName.Replace("Crescent Inc.", "Lunar Inc.")
                       
                        #Save the changes
                        $webPartManager.SaveChanges($webPart)
    
                    }
                }
                $Page.CheckIn("")
            }
            else
            {
                $webPartManager = $web.GetLimitedWebPartManager($Page.ServerRelativeUrl, [System.Web.UI.WebControls.WebParts.PersonalizationScope]::Shared)
     
                #Iterate through each web part
                foreach($webPart in $WebPartManager.WebParts)
                {
                    $OldTitle=$webPart.title
                    #Get the Content Editor web part with specific Title
                    if($webPart.title -like "*Contact Details*")
                    {
                    
                        #$webPart.ContactLoginName
                        $webPart.ContactLoginName = $webPart.ContactLoginName.Replace("oldDomain", "newDomain")
                       
                        #Save the changes
                        $webPartManager.SaveChanges($webPart)
                    
                    }
                }
            }
        }
    }

    Thanks,

    Wendy


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.


    Friday, July 6, 2018 3:31 AM
  • Thanks Wendy ! 

    It runs - and shows "online" - but it doesn't update the user inside the webpart   - the title in the webpart are like this: 

    "page author box" which I've put in the -like  both places

    If I manual opens and hover over the old domain\user which are displayed inside - rightclick on username - SP resolves the user with the correct user (done a move-spuser) - if I then accept - the users picture are shown 

    am I doing something wrong? 

    Friday, July 6, 2018 8:05 AM
  • Hi JmATK,

    "Online" is the value of $Page.CheckOutType which just returns the CheckOut status to check if the page is checked out, you can comment the line if you don't want it. If you change other properties of the web part like Title, does the change update the web part?

    In addition, please run a user profile full sync, after that, check again.

    Thanks,

    Wendy


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Friday, July 6, 2018 8:51 AM
  • Hi Wendy 

    Tried to change the title - doesn't update the webpart after all 

    The 'run a user profile full sync' - - do you mean the Sync in the UPSA ? (that isn't provisioned)  

    Wednesday, July 11, 2018 6:32 AM
  • Hi JmATK,

    Yes, please run full sync in User Profile Service Application.

    If you don't have USPA, you need to create it.

    Please have a try and let's know the result.

    Thanks,

    Wendy


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.


    Click here to learn more. Visit the dedicated forum to share, explore and talk to experts about Microsoft Teams.

    Wednesday, July 11, 2018 6:36 AM
  • Hi 

    I have a UPSA - but it won't start the service - even tried to create a new UPSA - without luck ... (next thing to resolve) 

    After I've run your script - the yellow ribbon are visible on every page: 

    "Status: Checked in and viewable by authorized users"

    So the pages are not published after the script ran... and the contact webpart are not updated ... :( 


    • Edited by JmATK Wednesday, July 11, 2018 8:13 AM
    Wednesday, July 11, 2018 7:33 AM