-
Notifications
You must be signed in to change notification settings - Fork 726
/
Copy pathAdd-SCSMServiceRequestComment.ps1
79 lines (69 loc) · 2.44 KB
/
Add-SCSMServiceRequestComment.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
Function Add-SCSMServiceRequestComment {
<#
.SYNOPSIS
Function to add a comment to a Service Request
.DESCRIPTION
Function to add a comment to a Service Request
.PARAMETER SRObject
Specify the Service Request Object
.PARAMETER Comment
Specify the comment text to add
.PARAMETER EnteredBy
Specify the Author of the comment
.PARAMETER AnalystComment
Use if the comment is made by an Analyst
.PARAMETER IsPrivate
Use if the comment is private
.EXAMPLE
Add-SCSMServiceRequestComment -SRObject $SR -Comment "This is a Comment" -EnteredBy 'FX'
.LINK
https://github.com/lazywinadmin/PowerShell
#>
[CmdletBinding()]
param (
[parameter(Mandatory = $True, Position = 0)]
$SRObject,
[parameter(Mandatory = $True, Position = 1)]
$Comment,
[parameter(Mandatory = $True, Position = 2)]
$EnteredBy,
[parameter(Mandatory = $False, Position = 3)]
[switch]$AnalystComment,
[parameter(Mandatory = $False, Position = 4)]
[switch]$IsPrivate
)
# Make sure that the SR Object it passed to the function
If ($null -ne $SRObject.Id) {
If ($AnalystComment) {
$CommentClass = "System.WorkItem.TroubleTicket.AnalystCommentLog"
$CommentClassName = "AnalystCommentLog"
}
else {
$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 = $SRObject;
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!"
}
}