forked from Snow-Shell/servicenow-powershell
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPSServiceNow-ConfigurationManagement.psm1
82 lines (70 loc) · 3.71 KB
/
PSServiceNow-ConfigurationManagement.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
81
82
function Get-ServiceNowConfigurationItem {
param(
# Machine name of the field to order by
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[string]$OrderBy='name',
# Direction of ordering (Desc/Asc)
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[ValidateSet("Desc", "Asc")]
[string]$OrderDirection='Desc',
# Maximum number of records to return
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[int]$Limit=10,
# Hashtable containing machine field names and values returned must match exactly (will be combined with AND)
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[hashtable]$MatchExact=@{},
# Hashtable containing machine field names and values returned rows must contain (will be combined with AND)
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[hashtable]$MatchContains=@{},
# Whether or not to show human readable display values instead of machine values
[parameter(mandatory=$false)]
[parameter(ParameterSetName='SpecifyConnectionFields')]
[parameter(ParameterSetName='UseConnectionObject')]
[parameter(ParameterSetName='SetGlobalAuth')]
[ValidateSet("true","false", "all")]
[string]$DisplayValues='true',
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[PSCredential]
$ServiceNowCredential,
[Parameter(ParameterSetName='SpecifyConnectionFields', Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[string]
$ServiceNowURL,
[Parameter(ParameterSetName='UseConnectionObject', Mandatory=$True)]
[ValidateNotNullOrEmpty()]
[Hashtable]
$Connection
)
$Query = New-ServiceNowQuery -OrderBy $OrderBy -OrderDirection $OrderDirection -MatchExact $MatchExact -MatchContains $MatchContains
if ($Connection -ne $null) {
$result = Get-ServiceNowTable -Table 'cmdb_ci' -Query $Query -Limit $Limit -DisplayValues $DisplayValues -Connection $Connection
}
elseif ($ServiceNowCredential -ne $null -and $ServiceNowURL -ne $null) {
$result = Get-ServiceNowTable -Table 'cmdb_ci' -Query $Query -Limit $Limit -DisplayValues $DisplayValues -ServiceNowCredential $ServiceNowCredential -ServiceNowURL $ServiceNowURL
}
else {
$result = Get-ServiceNowTable -Table 'cmdb_ci' -Query $Query -Limit $Limit -DisplayValues $DisplayValues
}
# Set the default property set for the table view
$DefaultProperties = @('name', 'category', 'subcategory')
$DefaultDisplayPropertySet = New-Object System.Management.Automation.PSPropertySet(‘DefaultDisplayPropertySet’,[string[]]$DefaultProperties)
$PSStandardMembers = [System.Management.Automation.PSMemberInfo[]]@($DefaultDisplayPropertySet)
$Result | Add-Member MemberSet PSStandardMembers $PSStandardMembers
return $result
}