-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
131 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
function New-ServiceNowChangeTask { | ||
<# | ||
.SYNOPSIS | ||
Create a new change task | ||
.DESCRIPTION | ||
Create a new change task | ||
.PARAMETER ChangeRequest | ||
sys_id or number of parent change request | ||
.PARAMETER ShortDescription | ||
Short description of the change task | ||
.PARAMETER Description | ||
Long description of the change task | ||
.PARAMETER AssignmentGroup | ||
sys_id or name of the assignment group | ||
.PARAMETER AssignedTo | ||
sys_id or name of the assigned user | ||
.PARAMETER CustomField | ||
Other key/value pairs to create the task which are not one of the existing parameters | ||
.PARAMETER Connection | ||
Azure Automation Connection object containing username, password, and URL for the ServiceNow instance | ||
.PARAMETER PassThru | ||
Return the newly created item details | ||
.EXAMPLE | ||
New-ServiceNowChangeTask -ChangeRequest RITM0010001 -ShortDescription 'New PS change request' -Description 'This change request was created from Powershell' -AssignmentGroup ServiceDesk | ||
Create a new task | ||
.EXAMPLE | ||
New-ServiceNowChangeTask -ShortDescription 'New' -Description 'Longer description' -CustomField @{'impact'='3'} | ||
Create a new task with additional fields | ||
#> | ||
|
||
[CmdletBinding(SupportsShouldProcess)] | ||
|
||
Param( | ||
|
||
[Parameter(Mandatory)] | ||
[string] $ShortDescription, | ||
|
||
[parameter(Mandatory)] | ||
[string] $Description, | ||
|
||
[Parameter()] | ||
[string] $ChangeRequest, | ||
|
||
[Parameter()] | ||
[string] $AssignmentGroup, | ||
|
||
[Parameter()] | ||
[string] $AssignedTo, | ||
|
||
[Parameter()] | ||
[hashtable] $CustomField, | ||
|
||
[Parameter()] | ||
[Hashtable] $Connection, | ||
|
||
[Parameter()] | ||
[hashtable] $ServiceNowSession = $script:ServiceNowSession, | ||
|
||
[Parameter()] | ||
[switch] $PassThru | ||
) | ||
|
||
begin { | ||
$createValues = @{} | ||
} | ||
|
||
process { | ||
|
||
switch ($PSBoundParameters.Keys) { | ||
'ChangeRequest' { | ||
$createValues.parent = $ChangeRequest | ||
} | ||
|
||
'ShortDescription' { | ||
$createValues.short_description = $ShortDescription | ||
} | ||
|
||
'Description' { | ||
$createValues.description = $Description | ||
} | ||
|
||
'AssignmentGroup' { | ||
$createValues.assignment_group = $AssignmentGroup | ||
} | ||
|
||
'AssignedTo' { | ||
$createValues.assignment_to = $AssignmentTo | ||
} | ||
} | ||
|
||
$CustomField.GetEnumerator() | ForEach-Object { | ||
if ( $createValues.($_.Key) ) { | ||
Write-Warning ('Custom field {0} has already been added via parameter' -f $_.Key) | ||
} else { | ||
$createValues.Add($_.Key, $_.Value) | ||
} | ||
} | ||
|
||
$params = @{ | ||
Method = 'Post' | ||
Table = 'change_task' | ||
Values = $createValues | ||
Connection = $Connection | ||
ServiceNowSession = $ServiceNowSession | ||
} | ||
|
||
If ( $PSCmdlet.ShouldProcess($ShortDescription, 'Create new change task') ) { | ||
$response = Invoke-ServiceNowRestMethod @params | ||
If ( $PassThru ) { | ||
$response.PSObject.TypeNames.Insert(0, "ServiceNow.ChangeTask") | ||
$response | ||
} | ||
} | ||
} | ||
|
||
end {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters