Taylohtio/_Scripts/ListFileNotFoundUrls/UpdateFileNotFoundUrls.ps1

40 lines
1.2 KiB
PowerShell

param(
[Parameter(Mandatory=$true)]
[string]$url
)
function Write-Log($msg) {
Write-Host $msg -foregroundcolor green
($msg) | Out-File "log-update-filenotfound.txt" -Append
}
function Update-FileNotFound($site) {
<#$pagesUrl = "Sivut"
if ($site.RootWeb.Language -eq 1033) {
$pagesUrl = "Pages"
}#>
if ($site.ID -eq $site.WebApplication.Sites[0].ID -or $site.Url -eq "http://intra.jarjestotalo.fi") {
#$expectedUrl = "/" + $pagesUrl + "/PageNotFoundError.aspx"
$expectedUrl = "/_layouts/15/Taloyhtio/Common/PageNotFound.aspx"
} else {
#$expectedUrl = $site.ServerRelativeUrl + "/" + $pagesUrl + "/PageNotFoundError.aspx"
$expectedUrl = $site.ServerRelativeUrl + "/_layouts/15/Taloyhtio/Common/PageNotFound.aspx"
}
#Write-Log ($expectedUrl)
if ($site.FileNotFoundUrl -ne $null -and $site.FileNotFoundUrl.ToLower() -eq $expectedUrl.ToLower()) {
return
}
Write-Log ("Update " + $site.Url + " from " + $site.FileNotFoundUrl + " to " + $expectedUrl)
$site.FileNotFoundUrl = $expectedUrl
#$site.Update()
#Write-Log ($_.Url + "`t" + $_.FileNotFoundUrl + "`t" + $expectedUrl)
}
$webApp = Get-SPWebApplication $url
$webApp.Sites | ForEach-Object { Update-FileNotFound $_ }
#$site = Get-SPSite $url
#Add-Form-Filling $site