Showing posts with label 2010. Show all posts
Showing posts with label 2010. Show all posts

Sunday, 26 May 2013

Migrate Knowledge Base Articles from Service Manager 2010 to 2012

To help ease the migration between Service Manager 2010 and 2012 (or even just one management group to another!) I've created a script that will export all of the Knowledge Articles, including the Rich Text used for the Analyst and End User content.

You can find the script here on the TechNet Gallery:
http://gallery.technet.microsoft.com/Migrate-Knowledge-Base-15b81ab6

Download and extract the zip file and put the SCSMExportKB.ps1 file in a directory you have access to.

The script also relies on the SMLets from CodePlex found here which also makes this independent of which version of Service Manager you're running.

After you've installed the SMLets, launch a PowerShell session (Elevated as Admin) and ensure that the execution of scripts is allowed by typing:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted

Next navigate to the folder with the script and run it with the paramerter of where to export the KB Articles to.  If you do not specify a path it will default to exporting the KB Articles to the users temp folder.

For example I would run this to export to my downloads folder:

.\SCSMExportKB.ps1 C:\Users\SBAdmin\Downloads

The script will then start running and you will see the progress of it exporting to RTF files any Analyst or End User content and then the rest of the KB Article details.

 

Copy these exported files to the same location on the target server (or modify the csv to point to a new location) and then use the KBImport.xml provided in the zip file along with the Knowledge.csv created by the PowerShell script to import them into the target Service Manager system using the CSV Import Wizard.

N.B. Before you do the import, be sure to remove the first line of the CSV which has the headers in it!



 
And that should be that, one set of exported and imported Knowledge Articles.
 
There is one limitation however...
In this current version only the Out-Of-Box lists are supported.  I'm working on the script to handle custom list values and will update the solution when it's automated.  Until then you will need to find the enumeration ID's from your target site and replace the source ID's in the CSV file with the corresponding ones.
 
I'd also like to thank Anton Gritsenko (aka FreemanRU) for pointing me in the right direction for this script.

Wednesday, 22 May 2013

Service Manager - Exporting the Knowledge Base Analyst and End User Comments

How can I export my knowledge base articles from Service Manager?

I've heard this question asked a few times now, especially when it comes to doing a migration rather than an upgrade from 2010 to 2012.

While it's fairly straight forward to output things like the Article ID, Title, Category etc using PowerShell, getting the Analyst and EndUser comments out is slightly more tricky due to them being stored as binary data within the database (They're RTF files basically).

While I may update this post to give a script that will export every last detail I'm pushed for time at the moment so I'll just post the most complicated part.

You can use the following PowerShell script to export the comments to individual rtf files for both Internal and Analyst comments.

$OutDir = "C:\KnowledgeFolder"
Get-SCSMClass -DisplayName "Knowledge Article" | Get-SCSMClassInstance | ForEach-Object {
$KBName=$_.ArticleId
If($_.EndUserContent -ne $null)
{
$br = new-object io.binaryreader $_.EndUserContent
$al = new-object collections.generic.list[byte]
while (($i = $br.Read()) -ne -1)
{
    $al.Add($i)
}
Set-Content ("$OutDir\$KBName"+"EndUserContent.rtf") $al.ToArray() -enc byte
}
If($_.AnalystContent -ne $null)
{
$br = new-object io.binaryreader $_.AnalystContent
$al = new-object collections.generic.list[byte]
while (($i = $br.Read()) -ne -1)
{
    $al.Add($I)
}
Set-Content ("$OutDir\$KBName"+"AnalystContent.rtf") $al.ToArray() -enc byte
}
}

I've only had a quick test of this within a 2012 environment which has the native Get-SCSMClass and Get-SCSMClassInstance cmdlets whereas 2010 doesn't. 

However with the SCSM Cmdlets from CodePlex this script should be easily adaptable for the 2010 environment.

You could then use either PowerShell to import them back into a new environment, or use Anders CSV import method shown on his post here

Travis also has a useful post with the Enum GUID's that you would need when importing via CSV here

Some useful details for working with Knowledge Articles in PowerShell:

Class Details:
DisplayName - Knowledge Article
Name - System.Knowledge.Article
ManagementPackName - System.Knowledge.Library

Some of the array contents:
Abstract
AnalystContent
ArticleId
ArticleOwner
ArticleTemplate
ArticleType
AssetStatus
Category
Comments
CreatedBy
CreatedDate
DisplayName
EndUserContent
ExternalURL
ExternalURLSource
Keywords
Notes
ObjectStatus
PrimaryLocaleID
Status
Tag
Title
VendorArticleID
#Id
#Name
#Path
#FullName
#LastModified
#TimeAdded
#LastModifiedBy
EnterpriseManagementObject
RelationshipAliases