Permalink
Browse files

Add SCSM WI Comment functions

  • Loading branch information...
lazywinadmin committed Jan 28, 2016
1 parent 570c4a1 commit f6b808f7f2662c63259c1c7feecfca909d6c744f
@@ -0,0 +1,63 @@
Function Add-SCSMServiceRequestComment
{
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 ($SRObject.Id -ne $NULL)
{
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!"
}
}
@@ -0,0 +1,76 @@
function Get-SCSMIncidentRequestComment
{
<#
.SYNOPSIS
Function to retrieve the comments from a Incident Request WorkItem
.DESCRIPTION
Function to retrieve the comments from a Incident Request WorkItem
.PARAMETER DateTime
Specifies from when (DateTime) the search need to look
.PARAMETER GUID
Specifies the GUID of the Service Request or Incident Request
.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
www.LazyWinAdmin.com
@lazywinadm
#>
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.incidentrequest$) -Filter "CreatedDate -gt '$DateTime'" #| Where-Object { $_.AssignedTo -eq $NULL }
}
$Tickets |
ForEach-Object {
$CurrentTicket = $_
$relatedObjects = Get-scsmrelatedobject -SMObject $CurrentTicket
Foreach ($Comment in ($relatedObjects | Where-Object { $_.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()
TicketTierQueue = $CurrentTicket.TierQueue
TicketSupportGroup = $CurrentTicket.SupportGroup
TicketAssignedTo = $CurrentTicket.AssignedTo
TicketCreatedDate = $CurrentTicket.CreatedDate
Comment = $Comment.Comment
CommentEnteredBy = $Comment.EnteredBy
CommentEnteredDate = $Comment.EnteredDate
CommentClassName = $Comment.ClassName
}
}
}
}

0 comments on commit f6b808f

Please sign in to comment.