When you create your own Views and Folders, Service Manager uses Default Icons. This is fine, but for a better presentation and recognition of views it makes sense to use custom Icons – especially when you have created custom Classes for managing objects. For this we have to dig a little deeper into the XML-Structure of the Management Pack.
After you have created the views in the Service Manager Console you have to export the Management Pack. Then open it using your favorite XML-Editor. In the “Presentation”-Section you will find another Section called “ImageReferences”. This is where the Images are connected to Views and Folders. When you have created Views and Folders in the Service Manager Console you will see IDs that you cannot interpret. You must check the IDs in the “Languages”-Section of the Management Pack to see what Image Reference belongs to a specific View or Folder.
When you know what ID represents a specific Class, you can change the ImageID-Value from Default to a meaningful ID. In this example I have two views, one for displaying Monitor Objects and one for monitoring Workplace Objects. Is use IDs “Workplace20x20” and “Monitor20x20” (20×20 stands for the dimension of the Icons).
Now we have to map the ImageIDs to Image-Files. For this, we have to add a new Section to the Management Pack called “Resources”. This is placed at the very end. In this example I map “Monitor20x20” to a file called “Monitor20x20.png” and “Workspace20x20” to a file called “Workspace20x20.png”. 20×20 is the perfect size for View and Folder Icons.
Now save the Management Pack. Before we can import the new Management Pack we have to put all components, the XML-File and the two Image files, together in a Management Pack Bundle-File (.mpb-file). For this procedure you must place all files in the same directory together with a Powershell-Script that will do the bundling for us. You can find the Powershell-Script-Code at the end of this Article.
Start the Powershell-Script with two Parameters. The first is the Management Pack (XML), the second the name of the Bundle file (.mpb) that you want to create. The Script will look for the needed Image files that are referenced in the Management Pack and add them automatically to the Bundle file.
Check if the Bundle file has been created.
Now it’s time to import the Bundle file into Service Manager. Use the regular Import process but make sure that you import the .mpb-File, not the xml-file.
Eventually you have to restart the Service Manager Console. Then you should be able to see the Icons.
I f you repeat this procedure for the Folders it looks even better. If you use the same Icons multiple times in the Management Pack, you do not have to add more References in the “Resources”-Section. Images only have to be declared once in the “Resources”-Section and can then be used multiple times. Therefore you must only change the ImageID in the “ImageReferences”-Section for the folders – that’s it.
Have fun!
Regards Marcel
********Powershell for Creating MPB-Files********
# New-MPBFile.ps1
# this takes files (.mp or .xml) and creates a .mpb file
param (
$mpFile = $( throw “Must have mpfile” ),
[string]$mpbname = “testmpb”,
$computername = “localhost”
)
# VARIABLES NEEDED BY SCRIPT
$VerbosePreference = “continue”
$SMDLL = “Microsoft.EnterpriseManagement.Core”
$SMPKG = “Microsoft.EnterpriseManagement.Packaging”
$MPTYPE = “Microsoft.EnterpriseManagement.Configuration.ManagementPack”
$MRESTYPE = “Microsoft.EnterpriseManagement.Configuration.ManagementPackResource”
$SIGTYPE = “Microsoft.EnterpriseManagement.Packaging.ManagementPackBundleStreamSignature”
$FACTYPE = “Microsoft.EnterpriseManagement.Packaging.ManagementPackBundleFactory”
$EMGTYPE = “Microsoft.EnterpriseManagement.EnterpriseManagementGroup”
$OPEN = [System.IO.FileMode]”Open”
$READ = [System.IO.FileAccess]”Read”
# make sure the appropriate assemblies are loaded and retrieve the needed types.
$SMCORE = [reflection.assembly]::LoadWithPartialName($SMDLL)
$SMPACKAGING = [reflection.assembly]::LoadWithPartialName($SMPKG)
$EMPTY = $SMCORE.GetType($SIGTYPE)::Empty
$TYPEOFMP = $SMCORE.GetType($MPTYPE)
$TYPEOFMPR = $SMCORE.GetType($MRESTYPE)
$BFACTORY = $SMPACKAGING.GetType($FACTYPE)
# Functions
# Invoke-GenericMethod
# allows scripts to call generic methods.
# arguments
# mytype – the type inspect for the needed method
# mymethod – the method name
# typearguments – an array of types used by MakeGenericMethod
# object – the object against which invoke is called
# parameters – any parameters needed by invoke
# it returns whatever is returned by invoke
function Invoke-GenericMethod
{
param (
[type]$mytype,
[string]$mymethod,
$TypeArguments,
$object,
[object[]]$parameters = $null
)
$Method = $mytype.GetMethod($mymethod)
$genericMethod = $Method.MakeGenericMethod($TypeArguments)
$genericMethod.Invoke($object,$parameters)
}
# Get-Resources
# this function retrieves resources from the MP. Because our GetResources API
# uses generics, it’s a bit tricky to call
# it returns a hash table of the stream, and the name for each resource
# it takes a Management Pack object
function Get-Resources
{
param ( $mpObject )
invoke-GenericMethod $TYPEOFMP “GetResources” $TYPEOFMPR $mpObject | %{
# check to see if we could find the file
$fullname = (resolve-path $_.FileName -ea SilentlyContinue).path
if ( ! $fullname )
{
write-host -for red ”
WARNING:
(‘Cannot find resource: ‘ + $_.FileName)
Skipping this resource, your MPB will probably not import
Make sure that the resources are in the same directory as the MP”
}
else
{
$stream = new-object io.filestream $fullname,$OPEN,$READ
@{ Stream = $stream; Name = $_.Name }
}
}
}
# Start
# Collect all the mps to add to the mpb!
$mpfileArray = @()
foreach ( $file in $mpFile )
{
foreach ( $item in resolve-path $file )
{
if ( $item.path )
{
$mpfileArray += $item.path
}
else
{
Write-Host -for red “ERROR: Cannot find file $item, skipping”
}
}
}
# Check to see if we have any management packs, if not, exit.
if ( $mpFileArray.Count -eq 0 )
{
Write-Host -for red “Error: No files to add”
exit
}
# we need a connection to the server when we start creating
# the management pack objects
$EMG = new-object $EMGTYPE $computername
# In order to create .mpb, we need to create one
# we’ll use the BundleFactory for this
$BUNDLE = $BFACTORY::CreateBundle()
# we’ll keep a collection of all the resources that we open
$AllResources = @()
foreach($mpfilepath in $mpfileArray)
{
# This should handle creating mpb from a local file store.
# For now, just create the mp object using the EnterpriseManagementGroup
$theMP = new-object $MPTYPE $mpfilepath,$EMG
Write-Verbose (“Adding MP: ” + $theMP.Name)
$BUNDLE.AddManagementPack($theMP)
# Add the resources if any are associated with the MP
$Resources = Get-Resources $theMP
# Add the resources for this MP to the collection
$AllResources += $Resources
if ( $Resources )
{
$Resources | %{
Write-Verbose (“Adding stream: ” + $_.Name)
$BUNDLE.AddResourceStream($theMP,$_.Name,$_.Stream,$EMPTY)
}
}
}
# WRITE THE mpb
# First we need a BundleWriter
$bundleWriter = $BFACTORY::CreateBundleWriter(${PWD})
# then we can write out the .mpb
$mpbfullpath = $bundleWriter.Write($BUNDLE,$mpbname)
write-verbose “wrote mpb: $mpbfullpath”
# Cleanup the resources
if ( $AllResources )
{
$AllResources | %{ if ( $_.Stream ) { $_.Stream.Close(); $_.Stream.Dispose() } }
}
***************End****************
Pingback: System Center Service Manager information(blog) overview - System Center Service Manager
Pingback: System Center Service Manager information(blog) overview - System Center Service Manager
Pingback: Service Request mgmt pack (Codeplex) update - System Center Service Manager
Pingback: System Center Service Manager information(blog) overview … | The People Search System
Where could I find/obtain a list of all the default Image IDs if I intended on using those for custom tasks i’m creating?
Hey
Meybe this blog post from Anton (SCCDM MVP) helps you out –> http://blog.scsmsolutions.com/2011/08/list-of-images-available-in-scsm-2010-sp1/
regards
Marcel
That is exactly what i was looking for. Thanks much!
what about the possibility to have dynamic number next to each folder in a way to reflect the number of items inside each folder (same way as your inbox shows how many unread emails )
Cheers
Hey
Cool idea, indeed! This is definitely not possible with OOB functions. Maybe with some dev work. Try it out and let me know afterwards 🙂
regards
Marcel
Hey, I’ve posted a question on technet regarding an issue I’m having in SCSM 2012 with the custom icons for views and folder, http://social.technet.microsoft.com/Forums/en-US/dwreportingdashboards/thread/44878758-792f-46b4-a44e-4241671acc5d
Pingback: Introduce Mobile Device Management in Service Manager #sysctr | System Management