Posts Tagged ‘SMLets’

So recently I got an e-mail to my newly setup e-mail address, for just this reason Smile,  from someone asking if I knew a way to do the following.


“I was trying to find a way to find all Incidents related to a specific person (assigned  to or affected user) using PowerShell”

So, I decided the best to answer this with a blog post as maybe there are other people out there asking the same question. This is a quick solution using


At this moment in time, this will address ONLY incidents. I will work on some code using


to reference work items. I will add the pieces of code as I go and explain the code.

First lets start by importing the required module, SMLets can be downloaded here

import-module smlets

I am running these commands on a computer that is NOT the Management Server. So I need to specify a computer name when I am running these commands. So, in the next line I create a


variable to make my life easier. If you are running these commands on the Management Server, you can remove the

-computername $computername

piece of code. Below is how I created this, please use the name of your Management Server

$computername = “name of your Management Server"

Ok, so now lets get all active incidents. I will run a PowerShell Command to get all Incidents that are NOT EQUAL to “Resolved” or “Closed”. This allows us to cover all other incident statuses you may have created. Notice the –ne operator.

$allincidents = Get-SCSMIncident -ComputerName $computername | Where-Object {$_.Status -ne "resolved" -and $_.status -ne "closed"}

So now we have all the incidents in an object, now what????

Personally, I choose to sort the information, enter


with Powershell. So, to elaborate a little further you can use


orGM” for short and “pipe” your variable to “GM” / Get-member

$allincidents | gm 


$allincidents | get-member 


Now you have a list of all the properties you can use. You can also go deeper into the ‘Members’ of the object. You can do the following as well

$allincidents.affecteduser | gm 

It is simply a case of playing around and digging a little bit.

So now back to the


. I wanted to sort by AssignedTo user, this can be easily changed by changing the


field of the


I also chose for this example to display the information in a useful grid. This too can be changed as needed.

$allincidents | Sort-Object -Property Assignedto | Select-Object -Property ID, Displayname, AffectedUser, Assignedto | Out-GridView

You will get some results like the below.


You can also limit the results by “Assigned To” user like such using either




operators. Examples below

-like operator. The example is finding all calls assigned to a user where the name is like “Kok*”. This time without the “out-gridview”

$allincidents | Where-Object {$_.assignedto.displayname -like "kok*"} 


-eq operator. This example finds all incidents assigned to a user with a specific name. In my example I am using “Desmond Hilton”

$allincidents | Where-Object {$_.assignedto.displayname -eq "Desmond Hilton"}


The PowerShell code can be easily adapted to meet the requirements for the “Affected User”. We simply change the value to use with the current object like such. I use


on “Affecteduser”


. Again you can use the





$allincidents | Where-Object {$_.assignedto.displayname -like "kok*"} 

-like operator. In this example I am using the Name “like” Roland

$allincidents | Where-Object {$_.affecteduser.DisplayName -like "Roland*"}


-eq operator. In this example I am using the “Affected User” name of “Andre Botes”

$allincidents | Where-Object {$_.affecteduser.DisplayName -eq "andre Botes"}


This should help you to make more in-depth queries and enjoy using PowerShell and SMLets to get valuable information from System Center Service Manager.

I have also setup an new e-mail address to help with Service Manger queries. you can e-mail me at systemcenterguyza ”at” live ”dot” com  ( and I will assist as much as I can.

I have also setup a new Twitter account to focus the Information around the System Center Suite.



Follow me.




Would you like a nice graphical breakdown of all calls logged in (x) days and there status?

I know I would. So, of course I have been working on such a script using smlets v3.

So far, this is what the script does.

  1. Takes the current date and time and subtracts 7 days and presents you with a nice HTML output which is mailed to the user. (Both the date and time and who to mail the output to is configurable.)
  2. Uses the same date and time as configured above and creates a breakdown of all calls/cases created after said time. Provides a breakdown of these calls in terms of open, closed, resolved and all other statuses.

I am currently working on a way to automate this more and provide a breakdown of calls per user for the above timeframe as well.

Working with get-scsmincident and get-scsmclass is tricky and I am also looking for any ideas on how to achieve this. More to come as soon as possible.

Anyways, code below.

Import-Module smlets

$startdate = $(Get-Date).AddDays(-7)

#buillding folder path
$dir = $env:userprofile
$date = ((Get-Date).toString('yyyMMdd'))
$filepath = $dir.tostring() + "\" +$date + "\"
New-Item -path $filepath -ItemType Directory -ErrorAction "SilentlyContinue"

#building html style
$htmlstyle = "<style>"
$htmlstyle = $htmlstyle + "BODY{background-color:Green;}"
$htmlstyle = $htmlstyle + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
$htmlstyle = $htmlstyle + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:GreenYellow}"
$htmlstyle = $htmlstyle + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:palegoldenrod}"
$htmlstyle = $htmlstyle + "</style>"

#specifying file to attach to e-mail later
$filename = $filepath + "allinc.html"

#building the file and contents of all calls and piping this out a html which will be later added to the e-mail
$createdincidentsfull = Get-SCSMIncident -CreatedAfter $startdate -ComputerName <nameoripofservicemanagerserver> |
Select-Object -Property AffectedUser, ID, Status, AssignedTo |
Sort-Object -Property Status |
ConvertTo-Html -Head $htmlstyle | Out-File $filename

#getting the information from Service Manager to supply a count of respective calls.
$createdincidents = Get-SCSMIncident -CreatedAfter $startdate -ComputerName <nameoripofservicemanagerserver>
$resolvedincidents = Get-SCSMIncident -CreatedAfter $startdate -ComputerName <nameoripofservicemanagerserver> -Status "Resolved"
$closedincidents = Get-SCSMIncident -CreatedAfter $startdate -ComputerName <nameoripofservicemanagerserver> -Status "Closed"
$countresolved = $resolvedincidents.count
$countclosed = $closedincidents.count
$countpending = $countcreated - $countresolved - $countclosed

#building message content
$line1 = "Number of calls created after" + " " + $startdate + " " + "is: " + $createdincidents.count
$line2 = "Number of calls resolved created after" + " " + $startdate + " " + "is:" + $resolvedincidents.count
$line3 = "Number of calls closed after" + " " +  $startdate + " " + "is:" + $closedincidents.count
$line4 = "Number of calls remaining open after" + " " + $startdate + " " + "is:" + $countpending

$messagecontent = @"
$line1 `r`n
$line2 `r`n
$line3 `r`n
$line4 `r`n

$smtpserver = "enter IP address here"
$to = "enter recipient here"
$from = "enter sending e-mail here"
Send-MailMessage -To $to -From $from -Body $messagecontent -SmtpServer $smtpserver -Attachments $filename -Subject "Call breakdown"

File can be found here

Anyone who is interested in playing with get-scsmclass (incidents in particular).

The below might be interesting.

Get-SCSMObject -Computername "<nameoripofservicemanagerserver>" –Class (Get-SCSMClass -ComputerName <nameoripofservicemanagerserver> -Name System.WorkItem.Incident$) | gm | Format-Table -AutoSize -Wrap |Out-File <path>


Hope this helps,

Follow me

facebook-small32222 twitter-small32222

Using SMLets practically

Posted: May 17, 2011 in Technology
Tags: , ,

In my previous post, SCSM And Powershell, I mentioned that I am now starting to play with get-scsmobject. In this post I also created a script. That script has now been evolved into a proper get-scsmobject script.

Import-Module smlets

$Now = (get-date).AddDays(-7)

$CId = (Get-SCSMEnumeration -ComputerName "ms-ec-hdm01" IncidentStatusEnum.Closed$).id

$RId = (Get-SCSMEnumeration -ComputerName "ms-ec-hdm01" IncidentStatusEnum.Resolved$).id

$Class = Get-SCSMClass -ComputerName "ms-ec-hdm01" System.WorkItem.Incident$

$cType = "Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectCriteria"

#$cString = "Status != '$CId' and Status != '$RId' and TargetResolutionTime < '$Now' and TargetResolutionTime Is Not Null"
$cStringClosed = "Status = '$CId'and CreatedDate >'$Now'"
$cStringResolved = "Status = '$RId'and CreatedDate >'$Now'"
$cStringAll = "CreatedDate >'$Now'"

$critClosed = new-object $cType $cStringClosed,$Class
$critResolved = new-object $cType $cStringResolved,$Class
$critAll = new-object $cType $cStringOther,$Class

$closed = Get-SCSMObject -ComputerName "ms-ec-hdm01" -Criteria $critClosed 

$resolved = Get-SCSMObject -ComputerName "ms-ec-hdm01" -Criteria $critResolved 

$all = Get-SCSMObject -ComputerName "ms-ec-hdm01" -Criteria $critAll 

#$all = Get-SCSMObject -ComputerName "ms-ec-hdm01" -Class (Get-SCSMClass -ComputerName "ms-ec-hdm01" System.WorkItem.Incident$)

$closedcount = $closed.count
$resolvedcount = $resolved.count
$allcount = $all.count
$othercount = $allcount - $closedcount - $resolvedcount
write-host "all calls:"  $allcount
Write-host "closed calls:" $closedcount
write-host "resolved calls:" $resolvedcount
write-host "other calls:" $othercount

The updated file can also be found here E-Mail breakdown of calls using get-scsmobject, this makes the execution far quicker.

Some handy Active Directory powershell scripts to follow

SCSM and Powershell

Posted: May 10, 2011 in Powershell
Tags: , ,

Hi all,

i have been playing with SMLets3 and get-scsmobject and using information from the post by Travis Wright, Using SMLets Beta 3 Post #1 – Using Get-SCSMObject, Get-SCSMClass to Dump Data from SCSM. This is an amazing post and I have been able to create a script that queries all Cases created after a certain date. It then gives you the breakdown of Open, Closed, Resolved and other status cases, which is then e-mailed to you. I will continue to play with this and post more as I am able to create more scripts. My first script can be found here, SCSMCallBreakDownWithEMail. As I update the scripts and create more, I will let everyone know.

I am also starting to focus on Active Directory again, and I am working on some handy scripts.

Until Then,



The “crisis” week

Posted: May 3, 2011 in Technology
Tags: , ,

Hi All,

The last two weeks have been a little nutty for me. I have however, learnt to appreciate a few more things in life.

1. No matter how good your planning for DR, there is always that one thing that catches you. We have a generator, which is great Smile. Now, when we cutover from generator power to mains power and then the main building power trips, life becomes interesting. It is especially interesting when you have a UPS and it takes the load after your building has tripped. So now your enclosure is running on UPS power and then the UPS fails Confused smile

2. DPM has once again proved itself to me. I was able to restore and recover the VHD and get my Cluster up and running again with NUMEROUS VMs.

3. I am sure that everyone knows this, but DAMN, a hard shutdown (see point 1) of a cluster hurts. Thanks goodness our SAN was not hurt as well. The correct RAID config which allows for 3 failed drives. Especially when you loose 1 drive due to the shutdown.

4. SCVMM does not really like a hard shutdown of a cluster (see point 1 again) and machines being in a “saved”, for us, this was especially tricky.

More to come on SCSM 2010, now starting to play with Get-SCSMObject with smlets and get-scsmobject, the SCSM Engineering Team Blog is a fantastic resources and many thanks go out to the people who run and maintain this site, it is a gold mine.

Related sites,

A few great people to follow on twitter, all of them (that I know of, still finding more al the time), are a fountain of knowledge.