forked from Snow-Shell/servicenow-powershell
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPSServiceNow.psm1
80 lines (67 loc) · 2.16 KB
/
PSServiceNow.psm1
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
74
75
76
77
78
79
80
function Test-ServiceNowAuthIsSet{
if($Global:ServiceNowCredentials){
return $true;
}else{
return $false;
}
}
function New-ServiceNowQuery{
param(
# Machine name of the field to order by
[parameter(mandatory=$true)]
[string]$OrderBy='opened_at',
# Direction of ordering (Desc/Asc)
[parameter(mandatory=$true)]
[ValidateSet("Desc", "Asc")]
[string]$OrderDirection='Desc',
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
[parameter(mandatory=$true)]
[hashtable]$MatchExact,
# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
[parameter(mandatory=$true)]
[hashtable]$MatchContains
)
# Start the query off with a order direction
$Query = '';
if($OrderDirection -eq 'Asc'){
$Query += 'ORDERBY'
}else{
$Query += 'ORDERBYDESC'
}
$Query +="$OrderBy"
# Build the exact matches into the query
if($MatchExact){
foreach($Field in $MatchExact.keys){
$Query += "^$Field="+$MatchExact.$Field
}
}
# Add the values which given fields should contain
if($MatchContains){
foreach($Field in $MatchContains.keys){
$Query += "^$($Field)LIKE"+$MatchContains.$Field
}
}
return $Query
}
function Set-ServiceNowAuth{
param(
[parameter(mandatory=$true)]
[string]$url,
[parameter(mandatory=$true)]
[System.Management.Automation.PSCredential]$Credentials
)
$Global:ServiceNowURL = 'https://' + $url
$Global:ServiceNowRESTURL = $ServiceNowURL + '/api/now/v1'
$Global:ServiceNowCredentials = $credentials
return $true;
}
<#
.SYNOPSIS
Cleans up the variables containing your authentication information from your PowerShell session
#>
function Remove-ServiceNowAuth{
Remove-Variable -Name ServiceNowURL -Scope Global
Remove-Variable -Name ServiceNowRESTURL -Scope Global
Remove-Variable -Name ServiceNowCredentials -Scope Global
return $true;
}