Posts Tagged ‘Assignedto’

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.



Just recently I was looking for a way to notify users about Inactive incidents as I have some departments that tend to ignore their work items and an e-mail about their “untouched” incidents seems to motivate them. So after some searching I found this script from Andreas Baumgarten

Please note : I only modified this script to extend its use to other Statuses to be monitored. All credit for the script goes entirely to Andreas Baumgarten

Code is below

# Configure Last Modified Days Before
$ModifiedBefore = 3

#Configure Incident Status
$IncidentStatus = 'Active'

# Configure your mail server, the recipient and the sender of the mail
# $smtphost=”mailserver.yourdomain.local”
# $from=”mail@yourdomain.local”


# Send-Mail function
function Send-Mail
$smtp = new-object$smtphost)
$mail = new-object System.Net.Mail.MailMessage
$mail.from= $From
$mail.subject= $Subject
$mail.body= $Body

# Some other variables
$BeforeDate = (Get-Date).AddDays(-$ModifiedBefore).ToString("MM/dd/yyy HH:mm:ss")
$Status = Get-SCSMEnumeration IncidentStatusEnum.$IncidentStatus$
$AssignedUserObjectRelClass = Get-SCSMRelationshipClass System.WorkItemAssignedToUser
$IncidentClass = Get-SCSMClass -name System.WorkItem.Incident$

#Get all incidents last modfied xy days before
$Incidents= @(Get-SCSMObject -Class $IncidentClass | Where {($_.Status -eq $Status -AND $_.LastModified -lt $BeforeDate)})

If ($Incidents.count -gt 0)

#Get all assigned incidents from list
foreach ($Incident in $Incidents)
# Get AssignedToUser
$AssignedUser = Get-SCSMRelatedObject -SMObject $Incident -Relationship $AssignedUserObjectRelClass

# Incidents AssignedTo is not NULL
If ($AssignedUser.Displayname -ne $NULL)
#Get email adress of AssignedToUser
$EndPoint = Get-SCSMRelatedObject -SMObject $assignedUser -Relationship $UserPref|?{$_.ChannelName -like '*SMTP'}
$Sendto = $Endpoint.Targetaddress

#Create Output
$Output = 'This Incident has been inactive for ' + $ModifiedBefore + ' day(s): <br>' + $Incident.ID + ' - ' + $Incident.Title + ' - Last Modified: ' + $Incident.Lastmodified
#Send email
$To = $Sendto
$Subject = 'Inactive incident for ' + $ModifiedBefore + ' day(s): ' + $Incident.Id + ' ' + $Incident.Title
$Body = $Output
Send-Mail $From $to $Subject $Body

Remove-Module SMlets -force 

Okay, so now that the code is there, I had to make some modifications in order for the Code to work with “NON-DEFAULT” Incident Statuses. I have created some additional Pending statuses.

The key line in this code is

Configure Incident Status
$IncidentStatus = 'Active'


$Status = Get-SCSMEnumeration IncidentStatusEnum.$IncidentStatus$

This allows you specify the Status. However if you use additional “NON-DEFAULT” statuses, this would need to be modified to suit your needs. You would need to modify the line of code to read as follows.

$IncidentStatus = 'Enum.847741a452db4d529741005ea73aead8'


$Status = Get-SCSMEnumeration $IncidentStatus$

You will notice the change of $IncidentStatus to a “ENUM” Value as this is a “NON-DEFAULT” value, you need to use the ENUM value. This can be gotten by using the following with SMLets

Get-SCSMEnumeration | Format-list | out-file

Below, is a screenshot to help illustrate this further.


Once you have a list of all your Enumerations, then search for the required value, for example “Pending – Waiting for 3rd Party”, you will then see a “Name” value and that whole string is your ENUM value.

You will also see that the $Status line has been changed to cater for the ENUM value.

Modify to meet your needs and create a workflow if you want to.

Follow me.