Monthly Archives: October 2014

Service Manager PowerShell examples

I have almost used service manager for 1,5 year now and over the time i have created a bunch of PowerShell scripts to do lots of different things. But i have noticed that sometime it was really hard to find some examples to the code. So here is a list of some code examples that i hope will help you.

Not all examples are completed so you need to fill in some information but the basic of how you can do it are there. Got any question just add a comment and i will answer as soon as i can.

Almost all script examples requires you to install SMlets you can find it on codeplex or here

Add an analyst comment to a Incident

This example is for adding a comment to a incident. You can use the smlets set-scsmincident -id 333 -comment “Hello” if you want but in this case we get more flexible and can set if it’s private and so on.

Add an end-user comment to incident

In this case we can use this example or look at the example below “Add an analyst comment to an incident” and modify it so the AnalystComment is set to EndUserComment instead. More like “Add an end-user comment to service request”

Add an end-user comment to Service Request

This example shows you how you can add a end-user comment to a service request. You need the $SCSMObject from a get-scsmobject.

Apply a template to an incident

This examples lets you set a template on a incident. You need to get your template ID by issue get-scsmobjecttemplate. Se example below.

Now get the Name of your template and add it to the template variable below.

Upload an attachment to a service request

This is not my own script. A college of mine wrote it. Thanks Evert. But it allows you to add attachements to a service request. All files in the $directory will be added to a id in $SCSMID

Set affected service when creating an incident

This example allows you to set a affected service on your incident. In this example not all variables are visible but you can replace the $variables with your own on the propertyHashtable. In this example we are setting the business service Gnu as affected service.

Populate AD-user class with email-address from active directory

In this example i am populating the email to the note field. Best practice would be to extend the Microsoft.AD.User class and add a field called email or something.

Hide/Show service offering based on user access on the SCSM web portal.

I often get the question from colleges if it’s possible to hide specific  service offering/requests on the web portal. This is possible we just need to create a mp, some groups and select the specific users that should view the requests. Se the guide below for more detailed information.

Step 1 – Create a request offering

Create a new request offering and select to create new management pack. This is the MP you will use on all your offerings/requests.


Enter the information you want.


Configure the text fields


Map the values, in this case we only asks for title and description so we map both values into the normal incident class fields title and description.


Publish the offering


Step 2 – Create a service offering

Create the offering and select the management pack you created before. service_offering0

Now select the request offering we just created.


Publish the offering.


Step 3 – Create catalog group

Create a new Group. Select the management pack you created in step 1.


Select the request offering and service offering you want to display.


Step 4.

Create a new user from end-user template. On the management pack select the MP you created in step 1.


Select the MP you created before.


Now provide access to only the group you created in step 2.


 Step 5 – View the result

Here is the result, i am using the Cireson web portal but this will work with the standard sharepoint/silverlight portal also.


The form


Set Anti-Affinity Group with PowerShell on Virtual Machine Manager

On a Hyper-V cluster you might want to separate some VM’s so they don’t run on the same physical machine. This is an easy task to achieve by the Gui or PowerShell. On the example below we add two or more servers to a anti-affinity group.

To this to work the servers must be named something like this ZGCTS01, ZGCTS02 and you should then only enter ZGCTS as a node-name and the two nodes will be joined in the same group so they will be kept separate.

Run the script and now you’re set. The machines will be kept apart if Virtual Machine Manager is possible to do so.