-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetstorageSystem.ps1
71 lines (67 loc) · 2.48 KB
/
getstorageSystem.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
function Invoke-DSCCRestMethod {
Param ( $UriAdd,
$Body = '',
$Method = 'Get',
$WhatIfBoolean = $false
)
Process {
Invoke-DSCCAutoReconnect
$MyURI = $BaseURI + $UriAdd
Clear-Variable -Name InvokeReturnData -ErrorAction SilentlyContinue
if ( $WhatIfBoolean ) {
invoke-RestMethodWhatIf -Uri $MyUri -Method $Method -Headers $MyHeaders -Body $Body -ContentType 'application/json'
}
else {
Write-Verbose "About to make rest call to URL $MyUri."
try {
$InvokeReturnData = Invoke-RestMethod -Uri $MyUri -Method $Method -Headers $MyHeaders -Body $Body -ContentType 'application/json'
}
catch {
ThrowHTTPError -ErrorResponse $_
return
}
if (($InvokeReturnData).items) {
$InvokeReturnData = ($InvokeReturnData).items
}
if (($InvokeReturnData).Total -eq 0) {
Write-Verbose 'The call succeeded however zero items were returned'
$InvokeReturnData = ''
}
}
return $InvokeReturnData
}
}
function Get-DsccStorageSystem {
[CmdletBinding(DefaultParameterSetName = 'BySystemId')]
param (
[Parameter(ParameterSetName = 'BySystemId')]
[alias('id')]
[string]$SystemId,
[parameter(helpMessage = 'The acceptable values are device-type1, device-type2, device-type4.')]
[validateset('device-type1', 'device-type2', 'device-type4')]
[string]$DeviceType
)
begin {
}
process {
if ( $DeviceType ) {
$DevType = $DeviceType
}
else {
$DevType = @( 'device-type1', 'device-type2', "device-type4")
}
$SystemCollection = @()
foreach ( $ThisDeviceType in $DevType ) {
$UriAdd = "storage-systems/$ThisDeviceType"
$Response = Invoke-DsccRestMethod -UriAdd $UriAdd -method Get -WhatIf:$WhatIfPreference
if ($PSBoundParameters.ContainsKey('SystemId') -or $PSBoundParameters.ContainsKey('SystemName')) {
$Response = $Response | Where-Object id -In $SystemId
}
$Returndata = Invoke-RepackageObjectWithType -RawObject $Response -ObjectName 'StorageSystem.Combined'
$SystemCollection += $Returndata
}
Write-Output $SystemCollection
} #end process
end {}
}
Get-DsccStorageSystem