forked from lazywinadmin/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAdd-SCSMSRComment.ps1
126 lines (109 loc) · 2.82 KB
/
Add-SCSMSRComment.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
Function Add-SRComment
{
<#
.SYNOPSIS
Function to add a comment inside a Service Request
.DESCRIPTION
Function to add a comment inside a Service Request
You need to have SMlets installed and permission to write inside
the service request.
.PARAMETER ServiceRequestObject
Specifies the ServiceRequest where the comment will be added
.PARAMETER Comment
Specifies the comment to add.
.PARAMETER CommentType
Specifies the comment type.
You need to specify 'User' or 'Analyst'.
.PARAMETER EnteredBy
Specifies your name.
.PARAMETER IsPrivate
Specifies if the switch is private
.EXAMPLE
PS C:\> Add-SRComment -ServiceRequestObject $SR -Comment "Task Completed" -CommentType Analyst -EnteredBy 'Francois-Xavier Cat'
.EXAMPLE
PS C:\> Add-SRComment -ServiceRequestObject $SR -Comment "Task Completed" -CommentType Analyst -EnteredBy 'Francois-Xavier Cat' -IsPrivate
.NOTES
Francois-Xavier Cat
www.lazywinadmin.com
@lazywinadm
Script inspired from http://www.scsm.se/?p=1423 by Anders Asp
#>
[CmdletBinding()]
PARAM (
[Alias("SRObject")]
[parameter(Mandatory = $true)]
[System.WorkItem.ServiceRequest]$ServiceRequestObject,
[parameter(Mandatory = $True)]
[String]$Comment,
[ValidateSet("User", "Analyst")]
[parameter(Mandatory = $True)]
[System.WorkItem.TroubleTicket]
[String]$CommentType,
[parameter(Mandatory = $True)]
[String]$EnteredBy,
[Switch]$IsPrivate
)
BEGIN
{
TRY
{
if (-not (Get-Module -Name Smlets))
{
Import-Module -Name Smlets -ErrorAction 'Stop'
}
}
CATCH
{
$Error[0]
}
}
PROCESS
{
TRY
{
# Make sure that the SR Object it passed to the function
If ($ServiceRequestObject.Id -ne $NULL)
{
Switch ($CommentType)
{
"Analyst" {
$CommentClass = "System.WorkItem.TroubleTicket.AnalystCommentLog"
$CommentClassName = "AnalystCommentLog"
}
"User" {
$CommentClass = "System.WorkItem.TroubleTicket.UserCommentLog"
$CommentClassName = "EndUserCommentLog"
}
}
# Generate a new GUID for the comment
$NewGUID = ([guid]::NewGuid()).ToString()
# Create the object projection with properties
$Projection = @{
__CLASS = "System.WorkItem.ServiceRequest";
__SEED = $ServiceRequestObject;
EndUserCommentLog = @{
__CLASS = $CommentClass;
__OBJECT = @{
Id = $NewGUID;
DisplayName = $NewGUID;
Comment = $Comment;
EnteredBy = $EnteredBy;
EnteredDate = (Get-Date).ToUniversalTime();
IsPrivate = $IsPrivate.ToBool();
}
}
}
# Create the actual comment
New-SCSMObjectProjection -Type "System.WorkItem.ServiceRequestProjection" -Projection $Projection
}
else
{
Throw "Invalid Service Request Object!"
}
}
CATCH
{
$Error[0]
} #CATCH
} #PROCESS
} # Function