-
Notifications
You must be signed in to change notification settings - Fork 2
/
DRAC.psm1
373 lines (356 loc) · 11.5 KB
/
DRAC.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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
<#
cd wsman:\localhost
Set-Item .\MaxBatchItems –Value 100
cd wsman:\localhost\Client
Set-Item AllowUnencrypted –Value True
Set-Item TrustedHosts –Value *
cd wsman:\localhost\Client\Auth
Set-Item Basic –Value True
#>
#Import-Module -Prefix DRAC
[System.Collections.ArrayList]$CimSession = @()
function Invoke-CIM {
param(
[Parameter(Mandatory,ValueFromPipeline)]
[string[]] $ComputerName,
[Parameter(Mandatory)]
[pscredential] $Credential,
[Parameter(ParameterSetName='Class')]
[string] $CimClass,
[Parameter(ParameterSetName='Class')]
[string] $Filter,
[Parameter(Mandatory,ParameterSetName='Query')]
[string] $Query,
[Parameter(Mandatory,ParameterSetName='Query')]
[ValidateSet('WQL','CQL')]
[string] $QueryDialect = 'CQL',
[string] $MethodName,
[hashtable] $MethodParameters,
[switch] $KeepSession,
[switch] $CMC
)
Process {
foreach ($CN in $ComputerName) {
$CimSession = $Script:CimSession.Where({$_.ComputerName -eq $CN})[0]
if (-not $CimSession) {
$CimOptions = New-CimSessionOption -SkipCACheck -SkipCNCheck -SkipRevocationCheck -Encoding Utf8 -UseSsl
$CimSession = New-CimSession -ComputerName $CN -Port 443 -Credential $Credential -Authentication Basic -SessionOption $CimOptions
}
#$BaseUri = 'http://schemas.dell.com/wbem/wscim/1/cim-schema/2'
#-ResourceUri "$BaseUri/$CimClass"
$Param = @{
CimSession = $CimSession
Namespace = if ($CMC) {
'root/dell/cmc'
} else {
'root/dcim'
}
ClassName = $CimClass
}
$CimInstance = switch ($PSCmdlet.ParameterSetName) {
Class {
if ($Filter) {
$Param.Filter = $Filter
}
Get-CimInstance @Param
}
Query {
Get-CimInstance @Param -Query $Query -QueryDialect $QueryDialect
}
}
if ($MethodName) {
$Job = $CimInstance | Invoke-CimMethod -CimSession $CimSession -MethodName $MethodName -Arguments $MethodParameters
?? { $Job.Job.EndpointReference.InstanceID } { $Job }
} else {
$CimInstance
}
if ($KeepSession.IsPresent) {
if ($CimOptions) {
# was created
[void]$Script:CimSession.Add($CimSession)
}
} else {
$CimSession | Remove-CimSession
[void]$Script:CimSession.Remove($CimSession)
}
}
}
}
function Get-FwInfo {
param(
[Parameter(Mandatory)]
[string] $ComputerName,
[Parameter(Mandatory)]
[pscredential] $Credential,
[switch] $KeepSession
)
Invoke-CIM @PSBoundParameters -CimClass DCIM_SoftwareIdentity
}
function Get-SystemInfo {
param(
[Parameter(Mandatory)]
[string] $ComputerName,
[Parameter(Mandatory)]
[pscredential] $Credential,
[switch] $KeepSession
)
Invoke-CIM @PSBoundParameters -CimClass DCIM_SystemView
}
function Get-FcWwn {
param(
[Parameter(Mandatory)]
[string] $ComputerName,
[Parameter(Mandatory)]
[pscredential] $Credential,
[switch] $KeepSession
)
Invoke-CIM @PSBoundParameters -CimClass DCIM_FCView
}
function Get-SEL {
param(
[Parameter(Mandatory)]
[string] $ComputerName,
[Parameter(Mandatory)]
[pscredential] $Credential,
[switch] $KeepSession
)
Invoke-CIM @PSBoundParameters -CimClass DCIM_SELLogEntry
}
function Set-EmbeddedNic {
param(
[Parameter(Mandatory)]
[string] $ComputerName,
[Parameter(Mandatory)]
[pscredential] $Credential,
[Parameter(Mandatory,ParameterSetName='Enable')]
[switch] $Enabled,
[Parameter(Mandatory,ParameterSetName='Disable')]
[switch] $Disabled,
[switch] $KeepSession
)
$MethodParam = @{
Target = 'BIOS.Setup.1-1'
AttributeName = 'EmbNic1Nic2','EmbNic3Nic4'
}
if ($Enabled.IsPresent) {
$MethodParam.AttributeValue = 'Enabled','Enabled'
} else {
$MethodParam.AttributeValue = 'DisabledOs','DisabledOs'
}
$Param = @{
ComputerName = $ComputerName
Credential = $Credential
CimClass = 'DCIM_BIOSService'
}
Invoke-CIM @Param -MethodName SetAttributes -MethodParameters $MethodParam
Invoke-CIM @Param -MethodName CreateTargetedConfigJob -MethodParameters @{
Target = 'BIOS.Setup.1-1'
RebootJobType = 2
#1 - PowerCycle
#2 - Graceful Reboot without forced shutdown
#3 - Graceful Reboot with forced shutdown
ScheduledStartTime = 'TIME_NOW'
#UntilTime = 'TIME_NOW'
}
}
function Update-Fw {
param(
[Parameter(Mandatory)]
[string] $ComputerName,
[Parameter(Mandatory)]
[pscredential] $Credential,
[Parameter(Mandatory)]
[uri] $Url
)
# detect DC -> NFS node, protocol, file based on server generation
$PSBoundParameters.Remove('Url')
$DracFw = Invoke-CIM @PSBoundParameters -CimClass DCIM_SoftwareIdentity -KeepSession |
? { $_.Status -eq 'Installed' -and $_.ElementName -match 'iDRAC' }
$Job = Invoke-CIM @PSBoundParameters -CimClass DCIM_SoftwareInstallationService -KeepSession -MethodName InstallFromURI -MethodParameters @{
URI = $Url
Target = [ref]$DracFw
}
# monitor job
Invoke-CIM @PSBoundParameters -CimClass DCIM_SoftwareInstallationService -MethodName CreateRebootJob -MethodParameters @{
RebootStartTime = 'TIME_NOW'
RebootJobType = 2
#1 - PowerCycle
#2 - Graceful Reboot without forced shutdown
#3 - Graceful Reboot with forced shutdown
}
}
function Reboot-Device {
param(
[Parameter(Mandatory)]
[string] $ComputerName,
[Parameter(Mandatory)]
[pscredential] $Credential,
[switch] $KeepSession
)
#DCIM_JobControlService, only RebootJobType
#DCIM_LifecycleJob
Invoke-CIM @PSBoundParameters -CimClass DCIM_JobControlService -MethodName CreateRebootJob -MethodParameters @{
#RebootStartTime = 'TIME_NOW'
RebootJobType = 2
#1 - PowerCycle
#2 - Graceful Reboot without forced shutdown
#3 - Graceful Reboot with forced shutdown
}
}
function Get-Job {
param(
[Parameter(Mandatory)]
[string] $ComputerName,
[Parameter(Mandatory)]
[pscredential] $Credential,
[string] $InstanceID,
[switch] $KeepSession
)
$Param = @{
ComputerName = $ComputerName
Credential = $Credential
CimClass = 'DCIM_LifecycleJob'
}
if ($Filter) {
$Param.Filter = "InstanceID = '$InstanceID'"
}
Invoke-CIM @Param -KeepSession:$KeepSession.IsPresent
}
function Mount-Image {
[CmdletBinding()]
param(
[Parameter(Mandatory)]
[string] $ComputerName,
[Parameter(Mandatory)]
[pscredential] $Credential,
[Parameter(Mandatory)]
[uri] $Unc, # NFS host:/mount/point/image.iso or CIFS \\host\share\image.iso
[pscredential] $UncCredential # for CIFS only
)
if ($Unc.IsUnc) {
# CIFS
$MethodParam = @{
IPAddress = $Unc.Host
ShareName = $Unc.Segments[1].Trim('/')
ImageName = $Unc.Segments[-1]
ShareType = 2
}
if ($UncCredential) {
$MethodParam.UserName = $UncCredential.UserName
$MethodParam.Password = $UncCredential.GetNetworkCredential().Password
}
} else {
# NFS
$ParsedUnc = $Unc -split '/'
$MethodParam = @{
IPAddress = $ParsedUnc[0].TrimEnd(':')
ShareName = '/' + ($ParsedUnc[1..($ParsedUnc.Count - 2)] -join '/')
ImageName = $ParsedUnc[-1]
ShareType = 0
}
}
# REF returned to started CIM_ConcreteJob
$Param = @{
ComputerName = $ComputerName
Credential = $Credential
CimClass = 'DCIM_OSDeploymentService'
MethodName = 'ConnectNetworkISOImage'
MethodParameters = $MethodParam
}
Invoke-CIM @Param -KeepSession
}
function Dismount-Image {
param(
[Parameter(Mandatory)]
[string] $ComputerName,
[Parameter(Mandatory)]
[pscredential] $Credential,
[switch] $KeepSession
)
Invoke-CIM @PSBoundParameters -CimClass DCIM_OSDeploymentService -MethodName DisconnectNetworkISOImage
}
# boot to Virtual Floppy in UEFI mode
function BootTo-Device {
param(
[Parameter(Mandatory)]
[string] $ComputerName,
[Parameter(Mandatory)]
[pscredential] $Credential,
[Parameter(Mandatory)]
#[ValidateSet()]
[string] $Device,
[ValidateSet('BIOS','UEFI')]
[string] $BootMode,
[switch] $KeepSession
)
$Param = @{
ComputerName = $ComputerName
Credential = $Credential
CimClass = 'DCIM_BootConfigSetting'
}
if ($BootMode) {
Invoke-CIM @Param -MethodName SetAttribute -MethodParameters @{
AttributeName = 'BootMode'
AttributeValue = $BootMode
}
}
Invoke-CIM @Param -MethodName ChangeBootOrderByInstanceID -MethodParameters @{
EnabledState = 'BIOS.Setup.1-1'
Source = #UEFI:Disk.USBFront.2-1:3156051d1529b8f4f88c99f54b895350 (boot source belongs to UEFI bootlist) array of DCIM_BootSourceSetting.InstanceID
#1 - PowerCycle
#2 - Graceful Reboot without forced shutdown
#3 - Graceful Reboot with forced shutdown
ScheduledStartTime = 'TIME_NOW'
#UntilTime = 'TIME_NOW'
}
Invoke-CIM @Param -MethodName ChangeBootOrderByInstanceID -MethodParameters @{
# UEFI
#InstanceID = 'OneTime'
Source = 'UEFI'
}
}
# DCIM_BIOSEnumeration
function Set-TpmModule {
param(
[Parameter(Mandatory)]
[string] $ComputerName,
[Parameter(Mandatory)]
[pscredential] $Credential,
[Parameter(Mandatory,ParameterSetName='Enable')]
[switch] $Enabled,
[Parameter(Mandatory,ParameterSetName='Disable')]
[switch] $Disabled,
[switch] $KeepSession
)
$TpmSecurity = @{
Target = 'BIOS.Setup.1-1'
AttributeName = 'TpmSecurity'
}
$TpmCommand = @{
Target = 'BIOS.Setup.1-1'
AttributeName = 'TpmCommand'
}
if ($Enabled.IsPresent) {
$TpmSecurity.AttributeValue = 'OnPbm'
$TpmCommand.AttributeValue = 'Activate'
} else {
$TpmSecurity.AttributeValue = 'Off'
$TpmCommand.AttributeValue = 'Deactivate'
}
$Param = @{
ComputerName = $ComputerName
Credential = $Credential
CimClass = 'DCIM_BIOSService'
}
Invoke-CIM @Param -MethodName SetAttributes -MethodParameters $TpmSecurity
Invoke-CIM @Param -MethodName SetAttributes -MethodParameters $TpmCommand
Invoke-CIM @Param -MethodName CreateTargetedConfigJob -MethodParameters @{
Target = 'BIOS.Setup.1-1'
RebootJobType = 2
#1 - PowerCycle
#2 - Graceful Reboot without forced shutdown
#3 - Graceful Reboot with forced shutdown
ScheduledStartTime = 'TIME_NOW'
#UntilTime = 'TIME_NOW'
}
}