-
Notifications
You must be signed in to change notification settings - Fork 726
/
Copy pathGet-SCSMServiceRequestComment.ps1
73 lines (62 loc) · 2.73 KB
/
Get-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
function Get-SCSMServiceRequestComment {
<#
.SYNOPSIS
Function to retrieve the comments from a Service Request WorkItem
.DESCRIPTION
Function to retrieve the comments from a Service Request WorkItem
.PARAMETER DateTime
Specifies from when (DateTime) the search need to look
.PARAMETER GUID
Specifies the GUID of the Service Request or Incident
.EXAMPLE
Get-SCSMServiceRequestComment -DateTime $((Get-Date).AddHours(-15))
.EXAMPLE
Get-SCSMServiceRequestComment -DateTime "2016/01/01"
.EXAMPLE
Get-SCSMServiceRequestComment -GUID 221dbd07-b480-ee33-fc25-6077406e83ad
.NOTES
Francois-Xavier Cat
lazywinadmin.com
@lazywinadmin
.LINK
https://github.com/lazywinadmin/PowerShell
#>
PARAM
(
[Parameter(ParameterSetName = 'General',
Mandatory = $true)]
$DateTime = $((Get-Date).AddHours(-24)),
[Parameter(ParameterSetName = 'GUID')]
$GUID
)
IF ($PSBoundParameters['GUID']) {
$Tickets = Get-SCSMObject -id $GUID
}
ELSE {
if ($DateTime -is [String]) { $DateTime = Get-Date $DateTime }
$DateTime = $DateTime.ToString(“yyy-MM-dd HH:mm:ss”)
$Tickets = Get-SCSMObject -Class (Get-SCSMClass System.WorkItem.servicerequest$) -Filter "CreatedDate -gt '$DateTime'" #| Where-Object { $_.AssignedTo -eq $NULL }
}
$Tickets |
ForEach-Object -Process {
$CurrentTicket = $_
$relatedObjects = Get-scsmrelatedobject -SMObject $CurrentTicket
Foreach ($Comment in ($relatedObjects | Where-Object -FilterScript { $_.classname -eq 'System.WorkItem.TroubleTicket.UserCommentLog' -or $_.classname -eq 'System.WorkItem.TroubleTicket.AnalystCommentLog' -or $_.classname -eq 'System.WorkItem.TroubleTicket.AuditCommentLog' })) {
# Output the information
[pscustomobject][ordered] @{
TicketName = $CurrentTicket.Name
TicketClassName = $CurrentTicket.Classname
TicketDisplayName = $CurrentTicket.DisplayName
TicketID = $CurrentTicket.ID
TicketGUID = $CurrentTicket.get_id()
TicketSupportGroup = $CurrentTicket.SupportGroup.displayname
TicketAssignedTo = $CurrentTicket.AssignedTo
TicketCreatedDate = $CurrentTicket.CreatedDate
Comment = $Comment.Comment
CommentEnteredBy = $Comment.EnteredBy
CommentEnteredDate = $Comment.EnteredDate
CommentClassName = $Comment.ClassName
}
}
}
}