Friday 13 January 2017

Update Redirect Page

A powershell script to update a redirect page

param($web_app_url=$(read-host "Please provide web app url of the list to be delete (EG:'http://SSRAP1'):"))

$SubsiteName = $(read-host "Please Provide the Name of the subsite (EG:'For-Residents')")
$RedirectPage = $(read-host "Please Provide the reletive path of the of the RedirectPage (EG:'Pages/default.aspx')")

$RedirectURL = $(read-host "Please Provide the redirect path and title seporated by a comma (EG:', Google')")

function LoadSharePointPowerShellEnviroment
                write-host "Setting up Powershell enviroment for Sharepoint" -foregroundcolor Blue
                Add-PSSnapin "Microsoft.Sharepoint.PowerShell" -ErrorAction SilentlyContinue
                Write-host "Sharepoint PowerShell Snapin loaded." -foregroundcolor Green

$site = new-object Microsoft.SharePoint.SPSite(web_app_url)
$spWeb = $site.OpenWeb($SubsiteName)
$spFile = $spWeb.GetFile($RedirectPage)

write-host "Current redirect link: " + $spFile.Properties["RedirectURL"] -foregroundcolor Blue

$spFile.Properties["RedirectURL"] = $RedirectURL
$spFile.CheckIn("Update page redirect via PowerShell",[Microsoft.SharePoint.SPCheckinType]::MajorCheckIn)

write-host "New redirect link: " + $spFile.Properties["RedirectURL"]-foregroundcolor Green