-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetChannelDetailsfromPI.ps1
166 lines (145 loc) · 6.95 KB
/
GetChannelDetailsfromPI.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
Get-ChildItem -Path ".\functions" -Filter *.ps1 | ForEach-Object {
. $_.FullName
}
$channelObjList = @()
$fileChannels = @()
$jdbcChannels = @()
$restChannels = @()
$soapChannels = @()
$sftpChannels = @()
$idocChannels = @()
$otherChannels = @()
$properties = Get-Content .\Properties.json | ConvertFrom-Json
$url = $properties.pi_system_url
if ( $null -ne $properties.file_name) {
$outputpath = $properties.file_name
}
else {
$outputpath = $outputpath = join-path -Path $env:USERPROFILE -ChildPath "desktop\PIPOChannelDetails.xlsx"
}
$download_channel_xml = $properties.download_channel_xml
[Xml] $SOAPRequest = Get-Content .\ChannelQueryRequest.xml
[Xml] $SOAPReadChannelRequest = Get-Content .\ChannelReadRequest.xml
# Request for credentials to autheticate the PI channel service
$credential = Get-Credential
$bytes = [System.Text.Encoding]::UTF8.GetBytes(
('{0}:{1}' -f $credential.UserName, $credential.GetNetworkCredential().Password)
)
$authorization = 'Basic {0}' -f ([Convert]::ToBase64String($bytes))
Write-Host 'Reading Channel Names.....'
# Call the web-service to read all the channels
$ReturnXml = CallPIChannelService $SOAPRequest $authorization $url
foreach ($channel in $ReturnXml.GetElementsByTagName('rn3:CommunicationChannelID')) {
$channelObj = New-Object -TypeName PSObject
# Write-Output $channel.ChannelID
Add-Member -InputObject $channelObj -MemberType 'NoteProperty' -Name 'PartyID' -Value $channel.PartyID
Add-Member -InputObject $channelObj -MemberType 'NoteProperty' -Name 'ComponentID' -Value $channel.ComponentID
Add-Member -InputObject $channelObj -MemberType 'NoteProperty' -Name 'ChannelID' -Value $channel.ChannelID
$channelObjList += $channelObj
}
$channelXmlFilePath = '.\Channels'
Write-Host 'Reading Channel XML configuration.....'
foreach ( $channel in $channelObjList ) {
$request = [Xml] $SOAPReadChannelRequest.OuterXml.Replace("{{PartyID}}", $channel.PartyID).Replace("{{ComponentID}}", $channel.ComponentID).Replace("{{ChannelID}}", $channel.ChannelID)
$ReturnXml = CallPIChannelService $request $authorization $url
if($download_channel_xml){
if($channel.PartyID){
$fileName = "{0}\{1}_{2}_{3}.{4}" -f $channelXmlFilePath, $channel.PartyID, $channel.ComponentID, $channel.ChannelID, 'xml'
} else {
$fileName = "{0}\{1}_{2}.{3}" -f $channelXmlFilePath, $channel.ComponentID, $channel.ChannelID, 'xml'
}
$ReturnXml.OuterXml | Out-File $fileName
}
$direction = $ReturnXml.GetElementsByTagName('rn3:CommunicationChannel').Direction
$adapterEngine = $ReturnXml.GetElementsByTagName('rn3:CommunicationChannel').AdapterEngineName
$adapterType = $ReturnXml.GetElementsByTagName('rn3:AdapterMetadata').name
$channelObj = New-Object -TypeName PSObject
Add-Member -InputObject $channelObj -MemberType 'NoteProperty' -Name 'PartyID' -Value $channel.PartyID
Add-Member -InputObject $channelObj -MemberType 'NoteProperty' -Name 'ComponentID' -Value $channel.ComponentID
Add-Member -InputObject $channelObj -MemberType 'NoteProperty' -Name 'ChannelID' -Value $channel.ChannelID
Add-Member -InputObject $channelObj -MemberType 'NoteProperty' -Name 'Direction' -Value $direction
Add-Member -InputObject $channelObj -MemberType 'NoteProperty' -Name 'AdapterType' -Value $adapterType
Add-Member -InputObject $channelObj -MemberType 'NoteProperty' -Name 'AdapterEngine' -Value $adapterEngine
switch ($adapterType) {
'File' {
$channelObj = ProcessFileAdapterParameters $ReturnXml.GetElementsByTagName('rn3:AdapterSpecificAttribute') $channelObj
$fileChannels += $channelObj
}
'JDBC' {
$channelObj = ProcessJdbcAdapterParameters $ReturnXml.GetElementsByTagName('rn3:AdapterSpecificAttribute') $channelObj
$jdbcChannels += $channelObj
}
'REST' {
$channelObj = ProcessRestAdapterParameters $ReturnXml.GetElementsByTagName('rn3:AdapterSpecificAttribute') $channelObj
$restChannels += $channelObj
}
'SFTP' {
$channelObj = ProcessSftpAdapterParameters $ReturnXml.GetElementsByTagName('rn3:AdapterSpecificAttribute') $channelObj
$sftpChannels += $channelObj
}
'SOAP' {
$channelObj = ProcessSoapAdapterParameters $ReturnXml.GetElementsByTagName('rn3:AdapterSpecificAttribute') $channelObj
$soapChannels += $channelObj
}
'IDoc_AAE' {
$channelObj = ProcessIdocAdapterParameters $ReturnXml.GetElementsByTagName('rn3:AdapterSpecificAttribute') $channelObj
$idocChannels += $channelObj
}
Default {
$channelObj = ProcessOtherAdapterTypesParameters $ReturnXml.GetElementsByTagName('rn3:AdapterSpecificAttribute') $channelObj
$otherChannels += $channelObj
}
}
}
Write-Host 'Preparing Excel Output...'
#open excell
$excel = New-Object -ComObject excel.application
$excel.visible = $false
$workbook = $excel.Workbooks.Add()
if ($otherChannels) {
#give the remaining worksheet a name
$otherChannelsSheet = $workbook.Worksheets.Item(1)
$otherChannelsSheet.name = 'Other Channels'
$otherChannelsSheet = OtherAdapterChannelsToExcel $otherChannels $otherChannelsSheet
#adjusting the column width so all data's properly visible
$otherChannelsSheet.UsedRange.EntireColumn.AutoFit() | Out-Null
}
if ($idocChannels) {
$idocChannelsSheet = $workbook.Worksheets.add()
$idocChannelsSheet.name = 'Idoc Channels'
$idocChannelsSheet = IdocChannelToExcel $idocChannels $idocChannelsSheet
$idocChannelsSheet.UsedRange.EntireColumn.AutoFit() | Out-Null
}
if($restChannels){
$restChannelsSheet = $workbook.Worksheets.add()
$restChannelsSheet.name = 'REST Channels'
$restChannelsSheet = RestChannelToExcel $restChannels $restChannelsSheet
$restChannelsSheet.UsedRange.EntireColumn.AutoFit() | Out-Null
}
if($soapChannels){
$soapChannelsSheet = $workbook.Worksheets.add()
$soapChannelsSheet.name = 'SOAP Channels'
$soapChannelsSheet = SoapChannelToExcel $soapChannels $soapChannelsSheet
$soapChannelsSheet.UsedRange.EntireColumn.AutoFit() | Out-Null
}
if($sftpChannels){
$sftpChannelSheet = $workbook.Worksheets.add()
$sftpChannelSheet.name = 'SFTP Channels'
$sftpChannelSheet = SftpChannelToExcel $sftpChannels $sftpChannelSheet
$sftpChannelSheet.UsedRange.EntireColumn.AutoFit() | Out-Null
}
if($fileChannels){
$fileChannelSheet = $workbook.Worksheets.add()
$fileChannelSheet.Name = 'File Channels'
$fileChannelSheet = FileChannelToExcel $fileChannels $fileChannelSheet
$fileChannelSheet.UsedRange.EntireColumn.AutoFit() | Out-Null
}
if($jdbcChannels){
$jdbcChannelSheet = $workbook.Worksheets.add()
$jdbcChannelSheet.name = 'JDBC Channels'
$jdbcChannelSheet = JdbcChannelToExcel $jdbcChannels $jdbcChannelSheet
$jdbcChannelSheet.UsedRange.EntireColumn.AutoFit() | Out-Null
}
#saving & closing the file
$workbook.SaveAs($outputpath)
$excel.Quit()