Skip to content

Commit f84667d

Browse files
committed
old get function cleanup
1 parent 7201854 commit f84667d

20 files changed

+79
-725
lines changed

ServiceNow/Private/Get-ServiceNowAuth.ps1

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,48 @@ function Get-ServiceNowAuth {
1818

1919
[Parameter()]
2020
[Alias('S')]
21-
[hashtable] $ServiceNowSession = $script:ServiceNowSession
21+
[hashtable] $ServiceNowSession
2222
)
2323

24-
$hashOut = @{}
24+
begin {
25+
$hashOut = @{}
26+
}
2527

26-
# Get credential and ServiceNow REST URL
27-
if ( $ServiceNowSession.Count -gt 0 ) {
28-
$hashOut.Uri = $ServiceNowSession.BaseUri
29-
if ( $ServiceNowSession.AccessToken ) {
30-
$hashOut.Headers = @{
31-
'Authorization' = 'Bearer {0}' -f $ServiceNowSession.AccessToken.GetNetworkCredential().password
32-
}
33-
}
34-
else {
35-
$hashOut.Credential = $ServiceNowSession.Credential
36-
}
28+
process {
3729

38-
if ( $ServiceNowSession.Proxy ) {
39-
$hashOut.Proxy = $ServiceNowSession.Proxy
40-
if ( $ServiceNowSession.ProxyCredential ) {
41-
$hashOut.ProxyCredential = $ServiceNowSession.ProxyCredential
30+
if ( $ServiceNowSession.Count -gt 0 ) {
31+
$hashOut.Uri = $ServiceNowSession.BaseUri
32+
if ( $ServiceNowSession.AccessToken ) {
33+
$hashOut.Headers = @{
34+
'Authorization' = 'Bearer {0}' -f $ServiceNowSession.AccessToken.GetNetworkCredential().password
35+
}
4236
}
4337
else {
44-
$hashOut.ProxyUseDefaultCredentials = $true
38+
$hashOut.Credential = $ServiceNowSession.Credential
39+
}
40+
41+
if ( $ServiceNowSession.Proxy ) {
42+
$hashOut.Proxy = $ServiceNowSession.Proxy
43+
if ( $ServiceNowSession.ProxyCredential ) {
44+
$hashOut.ProxyCredential = $ServiceNowSession.ProxyCredential
45+
}
46+
else {
47+
$hashOut.ProxyUseDefaultCredentials = $true
48+
}
4549
}
4650
}
47-
51+
elseif ( $Connection ) {
52+
Write-Verbose 'connection'
53+
$SecurePassword = ConvertTo-SecureString $Connection.Password -AsPlainText -Force
54+
$Credential = New-Object System.Management.Automation.PSCredential ($Connection.Username, $SecurePassword)
55+
$hashOut.Credential = $Credential
56+
$hashOut.Uri = 'https://{0}/api/now/v1' -f $Connection.ServiceNowUri
57+
} else {
58+
throw "You must authenticate by either calling the New-ServiceNowSession cmdlet or passing in an Azure Automation connection object"
59+
}
4860
}
49-
elseif ( $Connection ) {
50-
$SecurePassword = ConvertTo-SecureString $Connection.Password -AsPlainText -Force
51-
$Credential = New-Object System.Management.Automation.PSCredential ($Connection.Username, $SecurePassword)
52-
$hashOut.Credential = $Credential
53-
$hashOut.Uri = 'https://{0}/api/now/v1' -f $Connection.ServiceNowUri
5461

62+
end {
63+
$hashOut
5564
}
56-
else {
57-
throw "You must authenticate by either calling the New-ServiceNowSession cmdlet or passing in an Azure Automation connection object"
58-
}
59-
60-
$hashOut
6165
}

ServiceNow/Private/Invoke-ServiceNowRestMethod.ps1

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ function Invoke-ServiceNowRestMethod {
4747
[System.Collections.ArrayList] $Sort = @('opened_at', 'desc'),
4848

4949
# sysparm_query param in the format of a ServiceNow encoded query string (see http://wiki.servicenow.com/index.php?title=Encoded_Query_Strings)
50-
[Parameter()]
51-
[string] $Query,
50+
# [Parameter()]
51+
# [string] $Query,
5252

5353
# Fields to return
5454
[Parameter()]
@@ -69,7 +69,7 @@ function Invoke-ServiceNowRestMethod {
6969
)
7070

7171
# get header/body auth values
72-
$params = Get-ServiceNowAuth -C $Connection -S ServiceNowSession
72+
$params = Get-ServiceNowAuth -C $Connection -S $ServiceNowSession
7373

7474
$params.Method = $Method
7575
$params.ContentType = 'application/json'
@@ -115,9 +115,9 @@ function Invoke-ServiceNowRestMethod {
115115
$Body['sysparm_offset'] = $PSCmdlet.PagingParameters.Skip
116116
}
117117

118-
if ($Query) {
119-
$Body.sysparm_query = $Query
120-
}
118+
# if ($Query) {
119+
# $Body.sysparm_query = $Query
120+
# }
121121

122122
if ($Property) {
123123
$Body.sysparm_fields = ($Property -join ',').ToLower()

ServiceNow/Public/Add-ServiceNowAttachment.ps1

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,18 @@ Function Add-ServiceNowAttachment {
4545
# Table containing the entry
4646
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
4747
[Alias('sys_class_name')]
48-
[string]$Table,
48+
[string] $Table,
4949

50-
# Object number
51-
[Parameter(Mandatory, ValueFromPipelineByPropertyName)]
50+
[Parameter(ParameterSetName = 'AutomationSysId', Mandatory, ValueFromPipelineByPropertyName)]
51+
[Parameter(ParameterSetName = 'SessionSysId', Mandatory, ValueFromPipelineByPropertyName)]
52+
[Alias('sys_id')]
53+
[string] $SysId,
54+
55+
[Parameter(ParameterSetName = 'AutomationNumber', Mandatory)]
56+
[Parameter(ParameterSetName = 'SessionNumber', Mandatory)]
5257
[string] $Number,
5358

54-
# Filter results by file name
55-
[parameter(Mandatory)]
59+
[Parameter(Mandatory)]
5660
[ValidateScript( {
5761
Test-Path $_
5862
})]
@@ -62,25 +66,14 @@ Function Add-ServiceNowAttachment {
6266
[Parameter()]
6367
[string] $ContentType,
6468

65-
# Credential used to authenticate to ServiceNow
66-
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory)]
67-
[ValidateNotNullOrEmpty()]
68-
[Alias('ServiceNowCredential')]
69-
[PSCredential] $Credential,
70-
71-
# The URL for the ServiceNow instance being used
72-
[Parameter(ParameterSetName = 'SpecifyConnectionFields', Mandatory)]
73-
[ValidateScript( { $_ | Test-ServiceNowURL })]
74-
[ValidateNotNullOrEmpty()]
75-
[Alias('Url')]
76-
[string] $ServiceNowURL,
77-
7869
# Azure Automation Connection object containing username, password, and URL for the ServiceNow instance
79-
[Parameter(ParameterSetName = 'UseConnectionObject', Mandatory)]
70+
[Parameter(ParameterSetName = 'AutomationSysId', Mandatory)]
71+
[Parameter(ParameterSetName = 'AutomationNumber', Mandatory)]
8072
[ValidateNotNullOrEmpty()]
8173
[Hashtable] $Connection,
8274

83-
[Parameter(ParameterSetName = 'Session')]
75+
[Parameter(ParameterSetName = 'SessionSysId')]
76+
[Parameter(ParameterSetName = 'SessionNumber')]
8477
[ValidateNotNullOrEmpty()]
8578
[hashtable] $ServiceNowSession = $script:ServiceNowSession,
8679

@@ -93,9 +86,10 @@ Function Add-ServiceNowAttachment {
9386

9487
process {
9588

89+
9690
$getSysIdParams = @{
9791
Table = $Table
98-
Query = (New-ServiceNowQuery -Filter @('number', '-eq', $number))
92+
Filter = @('number', '-eq', $number)
9993
Properties = 'sys_id'
10094
Connection = $Connection
10195
ServiceNowSession = $ServiceNowSession

ServiceNow/Public/Get-ServiceNowAttachment.ps1

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ Function Get-ServiceNowAttachment {
7373
if ( $PSCmdlet.ParameterSetName -eq 'ByNumber' ) {
7474
$getSysIdParams = @{
7575
Table = $Table
76-
Query = (New-ServiceNowQuery -Filter @('number', '-eq', $number))
76+
Filter = @('number', '-eq', $number)
7777
Properties = 'sys_id'
7878
Connection = $Connection
7979
ServiceNowSession = $ServiceNowSession
@@ -85,12 +85,10 @@ Function Get-ServiceNowAttachment {
8585

8686
$params = @{
8787
Uri = '/attachment'
88-
Query = (
89-
New-ServiceNowQuery -Filter @(
90-
@('table_name', '-eq', $Table),
91-
'and',
92-
@('table_sys_id', '-eq', $sysId)
93-
)
88+
Filter = @(
89+
@('table_name', '-eq', $Table),
90+
'and',
91+
@('table_sys_id', '-eq', $sysId)
9492
)
9593
Connection = $Connection
9694
ServiceNowSession = $ServiceNowSession

ServiceNow/Public/Get-ServiceNowChangeRequest.ps1

Lines changed: 0 additions & 57 deletions
This file was deleted.

ServiceNow/Public/Get-ServiceNowConfigurationItem.ps1

Lines changed: 0 additions & 57 deletions
This file was deleted.

ServiceNow/Public/Get-ServiceNowIncident.ps1

Lines changed: 0 additions & 57 deletions
This file was deleted.

ServiceNow/Public/Get-ServiceNowRecord.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ function Get-ServiceNowRecord {
185185
}
186186
else {
187187

188+
# format the results
188189
if ( -not $Property ) {
189190
$type = $script:ServiceNowTable | Where-Object { $_.Name -eq $Table -or $_.ClassName -eq $Table } | Select-Object -ExpandProperty Type
190191
if ($type) {

0 commit comments

Comments
 (0)