-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.share.ps1
142 lines (130 loc) · 4.76 KB
/
functions.share.ps1
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
function get-ConfigItemId {
<#
.SYNOPSIS
OTRS SOAP Action for search id ConfigItem from otrs db
.DESCRIPTION
You have to set Name OR NK property(if you have this)
NK must be INTEGER!!!
For use this functions you have to create SOAP Webservice with named operation.
Webservice yaml files, modules and more detail: https://github/daniloveb/otrs_ps
.PARAMETER Class
ITSM::ConfigItem::Class. Example Computer, Hardware...
.PARAMETER NK
ConfigItem Name or CI Number field
.EXAMPLE
get-ConfigItemId Computer 3456 or get-ConfigItemId Computer arm-3456
get-ConfigItemId Printer 1227
.LINK
https://github/daniloveb/otrs_ps
#>
[CmdletBinding()]
param (
[Parameter( Mandatory = $true )] [string] $Class,
$NK
)
. "$PSScriptRoot\functions.SOAP.ps1"
. "$PSScriptRoot\Set-GlobalVars.ps1"
Write-Debug "$($MyInvocation.MyCommand.Name) $($MyInvocation.BoundParameters.Values[0])"
#$Logger.AddInfoRecord("$($MyInvocation.MyCommand.Name) $($MyInvocation.BoundParameters.Values[0]) ")
$WebServiceName = "WS_CI"
$OperationName = "Operation_CI_Search"
#check parameter type
if ($NK -is [int]){
#search on NK field
$XMLData = @"
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tic="$SoapNameSpace">
<soapenv:Body>
<tic:$OperationName>
<UserLogin>$UserLogin</UserLogin>
<Password>$Password</Password>
<ConfigItem>
<Class>$Class</Class>
<CIXMLData><NK>$NK</NK></CIXMLData>
</ConfigItem>
</tic:$OperationName>
</soapenv:Body>
</soapenv:Envelope>
"@
}
else {
$XMLData = @"
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tic="$SoapNameSpace">
<soapenv:Body>
<tic:$OperationName>
<UserLogin>$UserLogin</UserLogin>
<Password>$Password</Password>
<ConfigItem>
<Class>$Class</Class>
<Name>$NK</Name>
</ConfigItem>
</tic:$OperationName>
</soapenv:Body>
</soapenv:Envelope>
"@
}
$data = request-SOAP $WebServiceName $OperationName $XMLData
$id = ([xml]$data).Envelope.Body.Operation_CI_SearchResponse.ConfigItemIDs
if ($id -eq ""){
$id = $null
}
return $id
}
function get-ConfigItem {
<#
.SYNOPSIS
OTRS SOAP Action for get ConfigItem object from otrs db
.DESCRIPTION
Return hash table properties
"Class"
"CurDeplState"
"CurDeplStateType"
"CurInciState"
"CurInciStateType"
"Name"
"VersionID"
For use this functions you have to create SOAP Webservice with named operation.
Webservice yaml files, modules and more detail: https://github/daniloveb/otrs_ps
.PARAMETER ConfigItemID
ITSM::ConfigItem::Id
.EXAMPLE
get-ConfigItem 4839
$Name=(get-ConfigItem 4839)['Name']
$Class=(get-ConfigItem 4839)['Class']
.LINK
https://github/daniloveb/otrs_ps
#>
[CmdletBinding()]
param (
[Parameter( Mandatory = $true, ValueFromPipeline = $true )] [string] $ConfigItemID
)
. "$PSScriptRoot\functions.SOAP.ps1"
. "$PSScriptRoot\Set-GlobalVars.ps1"
Write-Debug "$($MyInvocation.MyCommand.Name) $($MyInvocation.BoundParameters.Values[0])"
#$Logger.AddInfoRecord("$($MyInvocation.MyCommand.Name) $($MyInvocation.BoundParameters.Values[0]) ")
$WebServiceName = "WS_CI"
$OperationName = "Operation_CI_Get"
$XMLData = @"
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tic="$SoapNameSpace">
<soapenv:Body>
<tic:$OperationName>
<UserLogin>$UserLogin</UserLogin>
<Password>$Password</Password>
<ConfigItemID>$ConfigItemID</ConfigItemID>
</tic:$OperationName>
</soapenv:Body>
</soapenv:Envelope>
"@
$data = request-SOAP $WebServiceName $OperationName $XMLData
$result = @{}
$result.add("Class",([xml]$data).Envelope.Body.Operation_CI_GetResponse.ConfigItem.Class)
$result.add("CurDeplState",([xml]$data).Envelope.Body.Operation_CI_GetResponse.ConfigItem.CurDeplState)
$result.add("CurDeplStateType",([xml]$data).Envelope.Body.Operation_CI_GetResponse.ConfigItem.CurDeplStateType)
$result.add("CurInciState",([xml]$data).Envelope.Body.Operation_CI_GetResponse.ConfigItem.CurInciState)
$result.add("CurInciStateType", ([xml]$data).Envelope.Body.Operation_CI_GetResponse.ConfigItem.CurInciStateType)
$result.add("Name",([xml]$data).Envelope.Body.Operation_CI_GetResponse.ConfigItem.Name)
$result.add("VersionID",([xml]$data).Envelope.Body.Operation_CI_GetResponse.ConfigItem.VersionID)
return $result
}