Skip to content

Commit 22eedc4

Browse files
committed
Updated function formatting. Added splatting.
1 parent e37cdf2 commit 22eedc4

File tree

1 file changed

+20
-16
lines changed

1 file changed

+20
-16
lines changed

ServiceNow/Public/Update-ServiceNowIncident.ps1

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,36 @@ function Update-ServiceNowIncident {
1414
# Credential used to authenticate to ServiceNow
1515
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
1616
[ValidateNotNullOrEmpty()]
17-
[PSCredential]
18-
$ServiceNowCredential,
17+
[PSCredential]$ServiceNowCredential,
1918

2019
# The URL for the ServiceNow instance being used (eg: instancename.service-now.com)
2120
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
2221
[ValidateNotNullOrEmpty()]
23-
[string]
24-
$ServiceNowURL,
22+
[string]$ServiceNowURL,
2523

2624
#Azure Automation Connection object containing username, password, and URL for the ServiceNow instance
2725
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
2826
[ValidateNotNullOrEmpty()]
29-
[Hashtable]
30-
$Connection
27+
[Hashtable]$Connection
3128
)
3229

33-
if ($Connection -ne $null)
34-
{
35-
Update-ServiceNowTableEntry -Table 'incident' -Values $Values -Connection $Connection -SysId $SysId
30+
$updateServiceNowTableEntrySplat = @{
31+
SysId = $SysId
32+
Table = 'incident'
33+
Values = $Values
3634
}
37-
elseif ($ServiceNowCredential -ne $null -and $ServiceNowURL -ne $null)
38-
{
39-
Update-ServiceNowTableEntry -Table 'incident' -Values $Values -ServiceNowCredential $ServiceNowCredential -ServiceNowURL $ServiceNowURL -SysId $SysId
35+
36+
# Update the splat if the parameters have values
37+
if ($null -ne $PSBoundParameters.Connection)
38+
{
39+
$updateServiceNowTableEntrySplat.Add('Connection',$Connection)
4040
}
41-
else
41+
elseif ($null -ne $PSBoundParameters.ServiceNowCredential -and $null -ne $PSBoundParameters.ServiceNowURL)
4242
{
43-
Update-ServiceNowTableEntry -Table 'incident' -Values $Values -SysId $SysId
44-
}
45-
}
43+
$updateServiceNowTableEntrySplat.Add('ServiceNowCredential',$ServiceNowCredential)
44+
$updateServiceNowTableEntrySplat.Add('ServiceNowURL',$ServiceNowURL)
45+
}
46+
47+
Update-ServiceNowTableEntry @updateServiceNowTableEntrySplat
48+
}
49+

0 commit comments

Comments
 (0)