Skip to content

Instantly share code, notes, and snippets.

@hemache
Created September 12, 2015 23:21
Show Gist options
  • Save hemache/e4778af051fcf425a465 to your computer and use it in GitHub Desktop.
Save hemache/e4778af051fcf425a465 to your computer and use it in GitHub Desktop.
[cmdletbinding(SupportsShouldProcess=$true,ConfirmImpact="High")]
Param(
[parameter(Mandatory=$True,Position=1)]
[String]
$currentWebApplicationURL,
[parameter(Mandatory=$True,Position=2)]
[String]
$oldWebApplicationURL
)
PROCESS {
[bool]$do = $pscmdlet.ShouldProcess($currentWebApplicationURL);
if((Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null){
$ver = $host | select version
if ($ver.Version.Major -gt 1) {$Host.Runspace.ThreadOptions = "ReuseThread"}
Add-PsSnapin Microsoft.SharePoint.PowerShell
Set-location $home
}
if($do){
write-host "Updating CalendarSettings..."
$gc = Start-SPAssignment
$views = $gc | get-spwebapplication $currentWebApplicationURL | get-spsite -limit all | get-spweb -limit all | % { $_.Lists | % { $_.Views | ? { $_.CalendarSettings -ne $null -and $_.CalendarSettings -like '*'+$oldWebApplicationURL+'*' } }}
$views | % { $_.CalendarSettings = $_.CalendarSettings.Replace($oldWebApplicationURL, $currentWebApplicationURL); $_.Update() }
write-host $views.Count "views updated.";
Stop-SPAssignment -SemiGlobal $gc
} else {
write-host "Operation cancelled."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment