-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Create-Incident.ps1
38 lines (37 loc) · 1.46 KB
/
Create-Incident.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Create an Incident with different properties and Affected User
Import-Module SMlets # Import SMLets module
$smdefaultserver = "SCSM1" # Define SCSM Management Server
# Define Incicent properties
$irTitle = "Test Incident by PowerShell 1"
$irDescription = "Test Description"
$irUrgency = "Medium"
$irImpact = "Medium"
$irSource = "System"
$irClassification = "Other Problems"
$irStatus = "Active"
$irTierQueue = "Tier1"
$irAffectedUser = "ppan1234"
# --------------------
$IRclass = Get-SCSMclass -name System.Workitem.Incident$ # Get SCSM Incident class object
$UserClass = Get-SCSMClass -name System.Domain.User$ # Get SCSM User class object
$relAffectedUser = Get-SCSMRelationshipClass -Name System.WorkItemAffectedUser # Get SCSM relationship Affected User
# Get Affected User
$irAffectedUserObj = Get-SCSMObject -Class $UserClass -Filter "UserName -eq $irAffectedUser"
# Prepare Incident properties
$properties = @{
Id = "IR{0}"
Title = $irTitle
Description = $irDescription
Urgency = $irUrgency
Impact = $irImpact
Source = $irSource
Status = $irStatus
Classification = $irClassification
TierQueue = $irTierQueue
}
# Create Incident object
$newIR = New-SCSMObject -Class $IRclass -PropertyHashtable $properties -PassThru
# Set Affected User
if ($irAffectedUserObj -and $newIR) {
New-SCSMRelationshipObject -RelationShip $relAffectedUser -Source $newIR -Target $irAffectedUserObj -Bulk
}