Enum all quicklaunch and replace url

Nel codice seguente ho enumerato tutti gli oggetti SPWeb partendo da un site e per ciascuno ho fatto accesso all'oggetto Navigation per sostituire delle URL assolute provenienti da una migrazione, portandole in URL relative:

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$Web = 'http://mywebapp'
$FindString = 'https://sourceurltofind' 
$ReplaceString = ''

$SPSite = Get-SPSite $Web
$SPWeb = Get-SPWeb $Web

$SPSite.AllWebs | ForEach-Object {
    write-host "Work with <"$_.Title"> <"$_.ServerRelativeUrl">"

    $_.Navigation.QuickLaunch | ForEach-Object {

        if($_.Url -match $FindString){
            $linkUrl = $_.Url
            Write-Host "Updating $linkUrl with new URL"
            $_.Url = $_.Url.Replace($FindString,$ReplaceString)
            $_.Update()
        }
        $_.Children | ForEach-Object {
            if($_.Url -match $FindString){
                $linkUrl = $_.Url
                Write-Host "Updating $linkUrl with new URL"
                $_.Url = $_.Url.Replace($FindString,$ReplaceString)
                $_.Update()
            }
        }
    }
    $_.Dispose()

}

Month List