@@ -239,18 +239,23 @@ function ConvertTo-AnnotationValues {
239239### Parsing Functions
240240
241241function ParseExceptionBody($Response) {
242- if ($Response) {
243- $Reader = New-Object System.IO.StreamReader($Response.GetResponseStream())
244- $Reader.BaseStream.Position = 0
245- $Reader.DiscardBufferedData()
246- $ResponseBody = $reader.ReadToEnd()
247- if ($ResponseBody.StartsWith('{')) {
248- $ResponseBody = $ResponseBody | ConvertFrom-Json | ConvertTo-Json
242+ if ($PSVersionTable.PSVersion.Major -lt 6) {
243+ if ($Response) {
244+ $Reader = New-Object System.IO.StreamReader($Response.GetResponseStream())
245+ $Reader.BaseStream.Position = 0
246+ $Reader.DiscardBufferedData()
247+ $ResponseBody = $reader.ReadToEnd()
248+ if ($ResponseBody.StartsWith('{')) {
249+ $ResponseBody = $ResponseBody | ConvertFrom-Json | ConvertTo-Json
250+ }
251+ return $ResponseBody
252+ }
253+ else {
254+ return $Response
249255 }
250- return $ResponseBody
251256 }
252257 else {
253- return $Response
258+ return $Error.ErrorDetails.Message
254259 }
255260}
256261
@@ -669,6 +674,26 @@ function ParseVmdks($Vmdks,$Timezone) {
669674 }
670675}
671676
677+ function ParseGenericDevices($GenericDevices,$Timezone) {
678+ foreach ($GenericDeviceInstance in $GenericDevices) {
679+ if ($GenericDeviceInstance.zones) {
680+ $GenericDeviceInstance.zones = ParseZones -Zones $GenericDeviceInstance.zones -Timezone $Timezone
681+ }
682+
683+ Write-Output $GenericDeviceInstance
684+ }
685+ }
686+
687+ function ParseZones($Zones,$Timezone) {
688+ foreach ($ZoneInstance in $Zones) {
689+ if ($ZoneInstance.zones) {
690+ $ZoneInstance.zones = ParseZones -Zones $ZoneInstance.zones -Timezone $Timezone
691+ }
692+
693+ Write-Output $ZoneInstance
694+ }
695+ }
696+
672697function ParseHosts($Hosts,$Timezone) {
673698 foreach ($HostInstance in $Hosts) {
674699 if ($HostInstance.createTime) {
@@ -8051,6 +8076,80 @@ function Global:Get-OciVmdksByDatastore {
80518076 }
80528077}
80538078
8079+ ## assets/devices ##
8080+
8081+ New-Alias -Name Remove-OciGenericDevice -Value Remove-OciDevices
8082+ <#
8083+ .SYNOPSIS
8084+ Remove inactive devices in bulk by IDs
8085+ .DESCRIPTION
8086+ Remove inactive devices in bulk by IDs
8087+ .PARAMETER Id
8088+ IDs of devices to remove
8089+ .PARAMETER expand
8090+ Expand parameter for underlying JSON object (e.g. expand=read,items)
8091+ #>
8092+ function Global:Remove-OciDevices {
8093+ [CmdletBinding()]
8094+
8095+ PARAM (
8096+ [parameter(Mandatory=$True,
8097+ Position=0,
8098+ HelpMessage="ID of generic device to retrieve",
8099+ ValueFromPipeline=$True,
8100+ ValueFromPipelineByPropertyName=$True)][Long[]]$id,
8101+ [parameter(Mandatory=$True,
8102+ Position=0,
8103+ HelpMessage="ID of generic device to retrieve",
8104+ ValueFromPipeline=$True,
8105+ ValueFromPipelineByPropertyName=$True)][Alias("self")][String[]]$Type,
8106+ [parameter(Mandatory=$False,
8107+ Position=3,
8108+ HelpMessage="Expand parameter for underlying JSON object (e.g. expand=read,items)")][String]$expand,
8109+ [parameter(Mandatory=$False,
8110+ Position=4,
8111+ HelpMessage="OnCommand Insight Server.")]$Server=$CurrentOciServer
8112+ )
8113+
8114+ Begin {
8115+ $Result = $null
8116+ if (!$Server) {
8117+ throw "Server parameter not specified and no global OCI Server available. Run Connect-OciServer first!"
8118+ }
8119+ }
8120+
8121+ Process {
8122+ $Uri = $Server.BaseUri + "/rest/v1/assets/device"
8123+
8124+ $Body = @()
8125+ foreach ($EntryNumber in 0..($Id.Count-1)) {
8126+ $Type = $Type -replace "s/[0-9]+","" -replace "/[0-9]+","" -replace ".*/",""
8127+ $Type = $Type.Substring(0,1).ToUpper() + $Type.Substring(1)
8128+ $Body += @{id=$Id[$EntryNumber];type=$Type[$EntryNumber]}
8129+ }
8130+
8131+ $Body = ConvertTo-Json -InputObject $Body
8132+
8133+ Write-Verbose "Body:`n$Body"
8134+
8135+ try {
8136+ $Result = Invoke-RestMethod -WebSession $Server.Session -TimeoutSec $Server.Timeout -Method DELETE -Uri $Uri -Headers $Server.Headers -Body $Body -ContentType 'application/json'
8137+ }
8138+ catch {
8139+ $ResponseBody = ParseExceptionBody -Response $_.Exception.Response
8140+ Write-Error "DELETE to $Uri failed with Exception $($_.Exception.Message) `n $responseBody"
8141+ }
8142+
8143+ if (([String]$Result).Trim().startsWith('{') -or ([String]$Result).toString().Trim().startsWith('[')) {
8144+ $Result = ParseJsonString -json $Result.Trim()
8145+ }
8146+
8147+ $GenericDevices = ParseGenericDevices -GenericDevices $Result -Timezone $Server.Timezone
8148+
8149+ if ($GenericDevices) { Write-Output $GenericDevices }
8150+ }
8151+ }
8152+
80548153## assets/disks ##
80558154
80568155<#
@@ -10489,6 +10588,228 @@ function Global:Get-OciTopologyByStorage {
1048910588 }
1049010589}
1049110590
10591+ ## assets/genericDevices ##
10592+
10593+ <#
10594+ .SYNOPSIS
10595+ Retrieve all generic devices
10596+ .DESCRIPTION
10597+ Retrieve all generic devices
10598+ .PARAMETER fromTime
10599+ Filter for time range, either in milliseconds or as DateTime
10600+ .PARAMETER toTime
10601+ Filter for time range, either in milliseconds or as DateTime
10602+ .PARAMETER expand
10603+ Expand parameter for underlying JSON object (e.g. expand=read,items)
10604+ #>
10605+ function Global:Get-OciGenericDevices {
10606+ [CmdletBinding()]
10607+
10608+ PARAM (
10609+ [parameter(Mandatory=$False,
10610+ Position=0,
10611+ HelpMessage="Filter for time range, either in milliseconds or as DateTime")][PSObject]$fromTime,
10612+ [parameter(Mandatory=$False,
10613+ Position=1,
10614+ HelpMessage="Filter for time range, either in milliseconds or as DateTime")][PSObject]$toTime,
10615+ [parameter(Mandatory=$False,
10616+ Position=2,
10617+ HelpMessage="Expand parameter for underlying JSON object (e.g. expand=read,items)")][String]$expand,
10618+ [parameter(Mandatory=$False,
10619+ Position=3,
10620+ HelpMessage="OnCommand Insight Server.")]$Server=$CurrentOciServer
10621+ )
10622+
10623+ Begin {
10624+ $Result = $null
10625+ if (!$Server) {
10626+ throw "Server parameter not specified and no global OCI Server available. Run Connect-OciServer first!"
10627+ }
10628+ }
10629+
10630+ Process {
10631+ $Uri = $Server.BaseUri + "/rest/v1/assets/genericDevices"
10632+
10633+ $Uri += '?'
10634+ $Separator = ''
10635+ if ($fromTime) {
10636+ $Uri += "fromTime=$($fromTime | ConvertTo-UnixTimestamp)"
10637+ $Separator = '&'
10638+ }
10639+ if ($toTime) {
10640+ $Uri += "$($Separator)toTime=$($toTime | ConvertTo-UnixTimestamp)"
10641+ $Separator = '&'
10642+ }
10643+ if ($expand) {
10644+ $Uri += "$($Separator)expand=$expand"
10645+ }
10646+
10647+ try {
10648+ $Result = Invoke-RestMethod -WebSession $Server.Session -TimeoutSec $Server.Timeout -Method GET -Uri $Uri -Headers $Server.Headers
10649+ }
10650+ catch {
10651+ $ResponseBody = ParseExceptionBody -Response $_.Exception.Response
10652+ Write-Error "GET to $Uri failed with Exception $($_.Exception.Message) `n $responseBody"
10653+ }
10654+
10655+ if (([String]$Result).Trim().startsWith('{') -or ([String]$Result).toString().Trim().startsWith('[')) {
10656+ $Result = ParseJsonString -json $Result.Trim()
10657+ }
10658+
10659+ $GenericDevices = ParseGenericDevices -GenericDevices $Result -Timezone $Server.Timezone
10660+
10661+ if ($GenericDevices) { Write-Output $GenericDevices }
10662+ }
10663+ }
10664+
10665+ <#
10666+ .SYNOPSIS
10667+ Retrieve one generic device
10668+ .DESCRIPTION
10669+ Retrieve one generic device
10670+ .PARAMETER Id
10671+ ID of generic device to retrieve
10672+ .PARAMETER fromTime
10673+ Filter for time range, either in milliseconds or as DateTime
10674+ .PARAMETER toTime
10675+ Filter for time range, either in milliseconds or as DateTime
10676+ .PARAMETER expand
10677+ Expand parameter for underlying JSON object (e.g. expand=read,items)
10678+ #>
10679+ function Global:Get-OciGenericDevice {
10680+ [CmdletBinding()]
10681+
10682+ PARAM (
10683+ [parameter(Mandatory=$True,
10684+ Position=0,
10685+ HelpMessage="ID of generic device to retrieve",
10686+ ValueFromPipeline=$True,
10687+ ValueFromPipelineByPropertyName=$True)][Long[]]$id,
10688+ [parameter(Mandatory=$False,
10689+ Position=1,
10690+ HelpMessage="Filter for time range, either in milliseconds or as DateTime")][PSObject]$fromTime,
10691+ [parameter(Mandatory=$False,
10692+ Position=2,
10693+ HelpMessage="Filter for time range, either in milliseconds or as DateTime")][PSObject]$toTime,
10694+ [parameter(Mandatory=$False,
10695+ Position=3,
10696+ HelpMessage="Expand parameter for underlying JSON object (e.g. expand=read,items)")][String]$expand,
10697+ [parameter(Mandatory=$False,
10698+ Position=4,
10699+ HelpMessage="OnCommand Insight Server.")]$Server=$CurrentOciServer
10700+ )
10701+
10702+ Begin {
10703+ $Result = $null
10704+ if (!$Server) {
10705+ throw "Server parameter not specified and no global OCI Server available. Run Connect-OciServer first!"
10706+ }
10707+ }
10708+
10709+ Process {
10710+ $Uri = $Server.BaseUri + "/rest/v1/assets/genericDevices/$Id"
10711+
10712+ $Uri += '?'
10713+ $Separator = ''
10714+ if ($fromTime) {
10715+ $Uri += "fromTime=$($fromTime | ConvertTo-UnixTimestamp)"
10716+ $Separator = '&'
10717+ }
10718+ if ($toTime) {
10719+ $Uri += "$($Separator)toTime=$($toTime | ConvertTo-UnixTimestamp)"
10720+ $Separator = '&'
10721+ }
10722+ if ($expand) {
10723+ $Uri += "$($Separator)expand=$expand"
10724+ }
10725+
10726+ try {
10727+ $Result = Invoke-RestMethod -WebSession $Server.Session -TimeoutSec $Server.Timeout -Method GET -Uri $Uri -Headers $Server.Headers
10728+ }
10729+ catch {
10730+ $ResponseBody = ParseExceptionBody -Response $_.Exception.Response
10731+ Write-Error "GET to $Uri failed with Exception $($_.Exception.Message) `n $responseBody"
10732+ }
10733+
10734+ if (([String]$Result).Trim().startsWith('{') -or ([String]$Result).toString().Trim().startsWith('[')) {
10735+ $Result = ParseJsonString -json $Result.Trim()
10736+ }
10737+
10738+ $GenericDevices = ParseGenericDevices -GenericDevices $Result -Timezone $Server.Timezone
10739+
10740+ if ($GenericDevices) { Write-Output $GenericDevices }
10741+ }
10742+ }
10743+
10744+ <#
10745+ .SYNOPSIS
10746+ Retrieve one generic device
10747+ .DESCRIPTION
10748+ Retrieve one generic device
10749+ .PARAMETER Id
10750+ ID of generic device to retrieve
10751+ .PARAMETER expand
10752+ Expand parameter for underlying JSON object (e.g. expand=read,items)
10753+ #>
10754+ function Global:Get-OciGenericDeviceZones {
10755+ [CmdletBinding()]
10756+
10757+ PARAM (
10758+ [parameter(Mandatory=$True,
10759+ Position=0,
10760+ HelpMessage="ID of generic device to retrieve",
10761+ ValueFromPipeline=$True,
10762+ ValueFromPipelineByPropertyName=$True)][Long[]]$id,
10763+ [parameter(Mandatory=$False,
10764+ Position=3,
10765+ HelpMessage="Expand parameter for underlying JSON object (e.g. expand=read,items)")][String]$expand,
10766+ [parameter(Mandatory=$False,
10767+ Position=4,
10768+ HelpMessage="OnCommand Insight Server.")]$Server=$CurrentOciServer
10769+ )
10770+
10771+ Begin {
10772+ $Result = $null
10773+ if (!$Server) {
10774+ throw "Server parameter not specified and no global OCI Server available. Run Connect-OciServer first!"
10775+ }
10776+ }
10777+
10778+ Process {
10779+ $Uri = $Server.BaseUri + "/rest/v1/assets/genericDevices/$Id/zones"
10780+
10781+ $Uri += '?'
10782+ $Separator = ''
10783+ if ($fromTime) {
10784+ $Uri += "fromTime=$($fromTime | ConvertTo-UnixTimestamp)"
10785+ $Separator = '&'
10786+ }
10787+ if ($toTime) {
10788+ $Uri += "$($Separator)toTime=$($toTime | ConvertTo-UnixTimestamp)"
10789+ $Separator = '&'
10790+ }
10791+ if ($expand) {
10792+ $Uri += "$($Separator)expand=$expand"
10793+ }
10794+
10795+ try {
10796+ $Result = Invoke-RestMethod -WebSession $Server.Session -TimeoutSec $Server.Timeout -Method GET -Uri $Uri -Headers $Server.Headers
10797+ }
10798+ catch {
10799+ $ResponseBody = ParseExceptionBody -Response $_.Exception.Response
10800+ Write-Error "GET to $Uri failed with Exception $($_.Exception.Message) `n $responseBody"
10801+ }
10802+
10803+ if (([String]$Result).Trim().startsWith('{') -or ([String]$Result).toString().Trim().startsWith('[')) {
10804+ $Result = ParseJsonString -json $Result.Trim()
10805+ }
10806+
10807+ $Zones = ParseZones -Zones $Result -Timezone $Server.Timezone
10808+
10809+ if ($Zones) { Write-Output $Zones }
10810+ }
10811+ }
10812+
1049210813## assets/hosts ##
1049310814
1049410815<#
0 commit comments