SharePoint 2013 - Update Web Title and Description with Powershell in other cultures than English

No comments
To update Web.Title or Description is pretty easy if your SharePoint-installation is in English, i.e:

$web = Get-SPWeb "http://sp2013"
$web.Title = "My title"
$web.Description="My site description"
$web.Update()

We are using Norwegian, and setting web.Title and web.Description gives no errors, but you will not see any changes either.
The problem is that this only changes the default english Title and Description.

There was little SharePoint-related information regarding this, but using this little gem from this answer on StackOverflow solves this nicely:



function Using-Culture (
   [System.Globalization.CultureInfo]   $culture = (throw "USAGE: Using-Culture -Culture culture -Script {…}"),
   [ScriptBlock] $script = (throw "USAGE: Using-Culture -Culture culture -Script {…}"))
   {
     $OldCulture = [Threading.Thread]::CurrentThread.CurrentCulture
     $OldUICulture = [Threading.Thread]::CurrentThread.CurrentUICulture
         try {
                 [Threading.Thread]::CurrentThread.CurrentCulture = $culture
                 [Threading.Thread]::CurrentThread.CurrentUICulture = $culture
                 Invoke-Command $script
         }
         finally {
                 [Threading.Thread]::CurrentThread.CurrentCulture = $OldCulture
                 [Threading.Thread]::CurrentThread.CurrentUICulture = $OldUICulture
         }
}

$desc="This website's description"
$web = Get-SPWeb "http://sp2013"
Using-Culture nb-no { $web.Description=$desc; $web.Update() }

No comments :

Post a Comment