Showing posts with label Powershell. Show all posts

Sync SharePoint Managed metadata field with database table using Powershell

No comments

Or: How to add terms to a termset from Powershell :)

In this case we are collecting project numbers from a SQL Server table, the Job table in a Navision instance to be exact.

When we have got the records all fine and happy we connect to SharePoint and asks it gently if it could please let us in to the Managed Metadata Service.
Once inside we rush to the term group Projects, demands it to show us it's term set Project numbers and then convinces it to accept all new numbers or else:



The term set Project number and Term group Projects already have lived a while in the Term Store. If your Term Store are missing out and wants a visit you could introduce them the usual way: Intro to Term store GUI

After getting on equal terms with Projects we settle down, release the site back to SharePoint with a polite Dispose() and retreat happily into the sun again.

As we both feel this was important we arrange a regular appointment using Scheduled Tasks  and promise to call.

Hope it helps,
Henri

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() }