1
1
using module ..\..\Classes\Discovery.psm1
2
2
3
- function Update-DiscoverDevicePayload ($HostList , $DiscoveryJob , $Mode , $DiscoveryUserName , [SecureString ] $DiscoveryPassword , $Email , $Schedule , $ScheduleCron ) {
3
+ function Update-DiscoverDevicePayload ($HostList , $DiscoveryJob , $Protocol , $ Mode, $DiscoveryUserName , [SecureString ] $DiscoveryPassword , $Email , $Schedule , $ScheduleCron ) {
4
4
$DiscoveryConfigPayload = ' {
5
5
"DiscoveryConfigGroupId":11,
6
6
"DiscoveryConfigGroupName":"Server Discovery",
@@ -13,39 +13,12 @@ function Update-DiscoverDevicePayload($HostList, $DiscoveryJob, $Mode, $Discover
13
13
"AddressType": 30
14
14
}
15
15
],
16
- "ConnectionProfile":"{
17
- \"profileName\":\"\",
18
- \"profileDescription\":\"\",
19
- \"type\":\"DISCOVERY\",
20
- \"credentials\":[{
21
- \"type\":\"WSMAN\",
22
- \"authType\":\"Basic\",
23
- \"modified\":false,
24
- \"credentials\": {
25
- \"username\":\"\",
26
- \"password\":\"\",
27
- \"caCheck\":false,
28
- \"cnCheck\":false,
29
- \"port\":443,
30
- \"retries\":3,
31
- \"timeout\": 60
32
- }
33
- },
34
- {
35
- \"type\":\"REDFISH\",
36
- \"authType\":\"Basic\",
37
- \"modified\":false,
38
- \"credentials\": {
39
- \"username\":\"\",
40
- \"password\":\"\",
41
- \"caCheck\":false,
42
- \"cnCheck\":false,
43
- \"port\":443,
44
- \"retries\":3,
45
- \"timeout\": 60
46
- }
47
- }]
48
- }",
16
+ "ConnectionProfile":{
17
+ "profileName":"",
18
+ "profileDescription":"",
19
+ "type":"DISCOVERY",
20
+ "credentials":[]
21
+ },
49
22
"DeviceType":[1000]
50
23
}],
51
24
"Schedule":{
@@ -72,11 +45,37 @@ function Update-DiscoverDevicePayload($HostList, $DiscoveryJob, $Mode, $Discover
72
45
$DiscoveryConfigPayload.CommunityString = $DiscoveryJob.CommunityString
73
46
74
47
# Update credentials
75
- $ConnectionProfile = $DiscoveryConfigPayload.DiscoveryConfigModels [0 ].ConnectionProfile | ConvertFrom-Json
76
- $ConnectionProfile.credentials [0 ].credentials.' username' = $DiscoveryUserName
77
- $ConnectionProfile.credentials [0 ].credentials.' password' = $DiscoveryPasswordText
78
- $ConnectionProfile.credentials [1 ].credentials.' username' = $DiscoveryUserName
79
- $ConnectionProfile.credentials [1 ].credentials.' password' = $DiscoveryPasswordText
48
+ $ConnectionProfile = $DiscoveryConfigPayload.DiscoveryConfigModels [0 ].ConnectionProfile
49
+ if ($Protocol -eq " iDRAC" ) {
50
+ $WSManProtocolPayload = Get-DiscoveryProtocolPayload - Protocol " WSMAN"
51
+ $RedfishProtocolPayload = Get-DiscoveryProtocolPayload - Protocol " REDFISH"
52
+ $WSManProtocolPayload.credentials .' username' = $DiscoveryUserName
53
+ $WSManProtocolPayload.credentials .' password' = $DiscoveryPasswordText
54
+ $RedfishProtocolPayload.credentials .' username' = $DiscoveryUserName
55
+ $RedfishProtocolPayload.credentials .' password' = $DiscoveryPasswordText
56
+ $ConnectionProfile.credentials += $WSManProtocolPayload
57
+ $ConnectionProfile.credentials += $RedfishProtocolPayload
58
+ } elseif ($Protocol -eq " VMWARE" ) {
59
+ $VMwareProtocolPayload = Get-DiscoveryProtocolPayload - Protocol " VMWARE"
60
+ $VMwareProtocolPayload.credentials .' username' = $DiscoveryUserName
61
+ $VMwareProtocolPayload.credentials .' password' = $DiscoveryPasswordText
62
+ $ConnectionProfile.credentials += $VMwareProtocolPayload
63
+ } elseif ($Protocol -eq " SNMP" ) {
64
+ $SNMPProtocolPayload = Get-DiscoveryProtocolPayload - Protocol " SNMP"
65
+ $SNMPProtocolPayload.credentials .' username' = $DiscoveryUserName
66
+ $SNMPProtocolPayload.credentials .' password' = $DiscoveryPasswordText
67
+ $ConnectionProfile.credentials += $SNMPProtocolPayload
68
+ } elseif ($Protocol -eq " IPMI" ) {
69
+ $IPMIProtocolPayload = Get-DiscoveryProtocolPayload - Protocol " IPMI"
70
+ $IPMIProtocolPayload.credentials .' username' = $DiscoveryUserName
71
+ $IPMIProtocolPayload.credentials .' password' = $DiscoveryPasswordText
72
+ $ConnectionProfile.credentials += $IPMIProtocolPayload
73
+ } elseif ($Protocol -eq " SSH" ) {
74
+ $SSHProtocolPayload = Get-DiscoveryProtocolPayload - Protocol " SSH"
75
+ $SSHProtocolPayload.credentials .' username' = $DiscoveryUserName
76
+ $SSHProtocolPayload.credentials .' password' = $DiscoveryPasswordText
77
+ $ConnectionProfile.credentials += $SSHProtocolPayload
78
+ }
80
79
$DiscoveryConfigPayload.DiscoveryConfigModels [0 ].ConnectionProfile = $ConnectionProfile | ConvertTo-Json - Depth 6
81
80
82
81
# Update target hosts
@@ -186,6 +185,8 @@ limitations under the License.
186
185
10.35.0.*
187
186
10.36.0.0-255
188
187
10.35.0.0/255.255.255.0
188
+ . PARAMETER Protocol
189
+ Protocol to use for discovery (Default="iDRAC", "SNMP", "IPMI", "SSH", "VMWARE")
189
190
. PARAMETER DiscoveryUserName
190
191
Discovery user name. The iDRAC user for server discovery.
191
192
. PARAMETER DiscoveryPassword
@@ -238,6 +239,10 @@ param(
238
239
[parameter (Mandatory = $false )]
239
240
[String []]$Hosts ,
240
241
242
+ [Parameter (Mandatory = $false )]
243
+ [ValidateSet (" iDRAC" , " SNMP" , " IPMI" , " SSH" , " VMWARE" )]
244
+ [String ] $Protocol = " iDRAC" ,
245
+
241
246
[Parameter (Mandatory )]
242
247
[String ]$DiscoveryUserName ,
243
248
@@ -277,7 +282,7 @@ Process {
277
282
$Headers = @ {}
278
283
$Headers ." X-Auth-Token" = $SessionAuth.Token
279
284
280
- $Payload = Update-DiscoverDevicePayload - Name $Name - HostList $Hosts - Mode $Mode - DiscoveryJob $Discovery - DiscoveryUserName $DiscoveryUserName - DiscoveryPassword $DiscoveryPassword - Email $Email - Schedule $Schedule - ScheduleCron $ScheduleCron
285
+ $Payload = Update-DiscoverDevicePayload - Name $Name - HostList $Hosts - Protocol $Protocol - Mode $Mode - DiscoveryJob $Discovery - DiscoveryUserName $DiscoveryUserName - DiscoveryPassword $DiscoveryPassword - Email $Email - Schedule $Schedule - ScheduleCron $ScheduleCron
281
286
$Payload = $Payload | ConvertTo-Json - Depth 6
282
287
$DiscoveryId = $Discovery.Id
283
288
$DiscoverUrl = $BaseUri + " /api/DiscoveryConfigService/DiscoveryConfigGroups(" + $DiscoveryId + " )"
@@ -301,9 +306,7 @@ Process {
301
306
302
307
}
303
308
Catch {
304
- Write-Error ($_.ErrorDetails )
305
- Write-Error ($_.Exception | Format-List - Force | Out-String )
306
- Write-Error ($_.InvocationInfo | Format-List - Force | Out-String )
309
+ Resolve-Error $_
307
310
}
308
311
}
309
312
0 commit comments