Tue. Jun 7th, 2022
Function Add_Site_ReadOnly_Banner([String]$srcURL, [String]$dstURL, $Credentials)
    Write-Host "Adding ReadOnly Banner to Source Site homepage post migration" -ForegroundColor Yellow
        $ctx = New-Object Microsoft.SharePoint.Client.ClientContext($srcURL)
        $Ctx.Credentials = $Credentials
        Write-host "Connected to $srcURL" -ForegroundColor Green
        #Get the Web
        $rootweb = $Ctx.Web

        $SiteRelativeURL = $srcURL.Replace("https://sp.demeter.zeus.gsi.gov.uk","")
        $HomePageRelativeURL = "SitePages/home.aspx"
        $PageURL = $SiteRelativeURL + $HomePageRelativeURL
        $Page = $Ctx.Web.GetFileByServerRelativeUrl($PageURL)

        #Check if page already checked out. If so, undo check out  
        if($Page.CheckOutType -eq [Microsoft.SharePoint.Client.CheckOutType]::Online){  
            Write-Host "Undo Checkout"  
                write-host "Error in checkout.. $($_.Exception.Message)" -foregroundcolor red  
        $NewSiteURL = '<a href="' + $dstURL + '">' + $dstURL +'</a>'
        $XmlDocument = [IO.File]::ReadAllText("C:\PSScripts\Post Migration\New Site Migrated Read-Only Banner.dwp") -replace 'NewSiteLink', $NewSiteURL
        $webpartXml = [xml]$XmlDocument;
 		#Get the webpart manager from the page, to handle the webparts 
 		$webpartManager =                                                                                                                                           $page.GetLimitedWebPartManager([Microsoft.Sharepoint.Client.WebParts.PersonalizationScope]::Shared); 
		#Load and execute the query to get the data in the webparts 
 		#Import the webpart 
 		$wp = $webpartManager.ImportWebPart($webpartXml.OuterXml) 

 	        $wpZoneID = "Left" 
 	        $wpZoneOrder= 2 
 		#Add the webpart to the page 
 		$webPartToAdd = $webpartManager.AddWebPart($wp.WebPart, $wpZoneID, $wpZoneOrder) 


        Write-host "Read Only now banner added to Source Site!" -ForegroundColor Green

        write-host -f Red "Error Adding Webpage" $_.Exception.Message

This website uses cookies. By continuing to use this site, you accept our use of cookies.