Get-OMEDeviceInventory.ps1
Function Get-OMEDeviceInventory { <# .SYNOPSIS Gets specific inventory for the device monitored by OME server. .DESCRIPTION Gets specific inventory for the device monitored by OME server. .PARAMETER Id Query inventory for the device with the specific Id. .PARAMETER Name Query inventory for the device with the specific Name. .PARAMETER AssetTag Query inventory for the device with the specific Asset Tag. .PARAMETER ServiceTag Query inventory for the device with the specific Service Tag. .PARAMETER Table Specifies table Id for the inventory (see Dell REST API User Guide). .PARAMETER Session Specifies the Session Id for the OME server. .EXAMPLE Get-OMEDeviceInventory -Session $session -Name server45.example.com -Table 3 ArrayDiskUsedSpace : 558 ArrayDiskEnclosureId : Disk.Bay.2:Enclosure.Internal.0-1:RAID.Integrated.1-1 ArrayDiskFreeSpace : 0 ArrayDiskMediaType : Hard Disk Drive ArrayDiskChannel : 0 ArrayDiskNumber : 3 ArrayDiskVendorName : SEAGATE ArrayDiskLength : 558 DeviceId : 325 ArrayDiskSerialNumber : 6DF4545FG ArrayDiskModelNumber : ST9600205SS ArrayDiskStatus : OK ArrayDiskBusType : SAS ArrayDiskTargetId : 2 ArrayDiskRevision : CS09 .NOTES Author: Mike Khar .LINK http://www.dell.com/support/home/us/en/04/product-support/product/dell-openmanage-essentials-v2.2/research https://$Server:$Port/api/OME.svc/$DeviceID/TableInventory/$Id #> [CmdletBinding(DefaultParametersetName="Id" )] Param( [parameter(Mandatory=$true,ParameterSetName="Id",ValueFromPipeline=$true)] $Id, [parameter(Mandatory=$true,ParameterSetName="Name")] [String]$Name, [parameter(Mandatory=$true,ParameterSetName="AssetTag")] [String]$AssetTag, [parameter(Mandatory=$true,ParameterSetName="ServiceTag")] [String]$ServiceTag, [parameter(Mandatory=$true)] [int]$Table, $Session="OMEConnection.DefaultOMESession" ) Begin { $CurrentSession = Get-Variable -Scope Global -Name $Session -ErrorAction SilentlyContinue -ValueOnly If (!$CurrentSession) { Write-Warning "Please use Set-OMEConnection first" Break Return } else { $BaseUri="https://"+$CurrentSession.Server+":"+$CurrentSession.Port+"/api/OME.svc" } } Process { Try { if ($Id) { if (!($Id -as [int32])) { $Id_=$Id.Id If ($Id_) { $Id=$Id_ } else { return } } } if ($Name) { $Id_=$(Get-OMEDevice -Session $Session -All | where {$_.Name -eq $Name}).Id If ($Id_) { $Id=$Id_ } else { return } } if ($AssetTag) { $Id_=$(Get-OMEDevice -Session $Session -All | where {$_.AssetTag -eq $AssetTag}).Id If ($Id_) { $Id=$Id_ } else { return } } if ($ServiceTag) { $Id_=$(Get-OMEDevice -Session $Session -All | where {$_.ServiceTag -eq $ServiceTag}).Id If ($Id_) { $Id=$Id_ } else { return } } $Info=@() $ListOfuri=@() $Id | foreach {$ListOfuri+=$BaseUri+"/Devices/$_/TableInventory/$table"} foreach ($uri in $ListOfuri) { if ($CurrentSession.Credentials) { $result = Invoke-WebRequest -Uri $uri -Credential $CurrentSession.Credentials -ContentType "application/octet-stream" } else { $result = Invoke-WebRequest -Uri $uri -UseDefaultCredentials -ContentType "application/octet-stream" } if ($result.StatusCode -ne 200) { Out-OMEException -Exception $_ return } else { Write-Debug "HTTP request: $uri HTTP status code: $($result.StatusCode)" if ($result.Content) { [xml]$xml=[System.Text.Encoding]::ASCII.GetString($result.Content) $result=$xml.DocumentElement } else { return } } if ($result) {$Info+=$result} } $PropertyName=$($result | Get-Member -MemberType Properties).Name return Convert-XMLtoPSObject -xml $Info.$PropertyName -ObjectType "OME.$PropertyName" } Catch { Out-OMEException -Exception $_ } } End{} } #aliases for table functions function Get-OMEDeviceDisks { <# .SYNOPSIS Gets information about the device disks. .DESCRIPTION Gets information about the device disks. Alias for the Get-OMEDeviceInventory -Table 3 .PARAMETER Id Query inventory for the device with the specific Id. .PARAMETER Name Query inventory for the device with the specific Name. .PARAMETER AssetTag Query inventory for the device with the specific Asset Tag. .PARAMETER ServiceTag Query inventory for the device with the specific Service Tag. .PARAMETER Session Specifies the Session Id for the OME server. .EXAMPLE Get-OMEDeviceDisks -Session $session -Name server45.example.com ArrayDiskUsedSpace : 558 ArrayDiskEnclosureId : Disk.Bay.2:Enclosure.Internal.0-1:RAID.Integrated.1-1 ArrayDiskFreeSpace : 0 ArrayDiskMediaType : Hard Disk Drive ArrayDiskChannel : 0 ArrayDiskNumber : 3 ArrayDiskVendorName : SEAGATE ArrayDiskLength : 558 DeviceId : 325 ArrayDiskSerialNumber : 6DF4545FG ArrayDiskModelNumber : ST9600205SS ArrayDiskStatus : OK ArrayDiskBusType : SAS ArrayDiskTargetId : 2 ArrayDiskRevision : CS09 .NOTES Author: Mike Khar .LINK http://www.dell.com/support/home/us/en/04/product-support/product/dell-openmanage-essentials-v2.2/research https://$Server:$Port/api/OME.svc/$DeviceID/TableInventory/3 #> [CmdletBinding(DefaultParametersetName="Id" )] Param( [parameter(Mandatory=$true,ParameterSetName="Id",ValueFromPipeline=$true)] $Id, [parameter(Mandatory=$true,ParameterSetName="Name")] [String]$Name, [parameter(Mandatory=$true,ParameterSetName="AssetTag")] [String]$AssetTag, [parameter(Mandatory=$true,ParameterSetName="ServiceTag")] [String]$ServiceTag, $Session="OMEConnection.DefaultOMESession" ) Begin { $CurrentSession = Get-Variable -Scope Global -Name $Session -ErrorAction SilentlyContinue -ValueOnly If (!$CurrentSession) { Write-Warning "Please use Set-OMEConnection first" Break Return } else { $BaseUri="https://"+$CurrentSession.Server+":"+$CurrentSession.Port+"/api/OME.svc" } } Process { $string="Get-OMEDeviceInventory -Session $Session -Table 3" if ($Id) { $string+=' -Id $Id' } if ($Name) { $string+=' -Name $Name' } if ($AssetTag) { $string+=' -AssetTag $AssetTag' } if ($ServiceTag) { $string+=' -ServiceTag $ServiceTag' } if ($Credentials) { $string+=' -Credentials $Credentials' } return Invoke-Expression $string } End{} } function Get-OMEDeviceRAM { <# .SYNOPSIS Gets information about the device RAM. .DESCRIPTION Gets information about the device RAM. Alias for the Get-OMEDeviceInventory -Table 16 .PARAMETER Id Query inventory for the device with the specific Id. .PARAMETER Name Query inventory for the device with the specific Name. .PARAMETER AssetTag Query inventory for the device with the specific Asset Tag. .PARAMETER ServiceTag Query inventory for the device with the specific Service Tag. .PARAMETER Session Specifies the Session Id for the OME server. .EXAMPLE Get-OMEDeviceRAM -Session $session -Name server45.example.com MemoryDeviceBankName : A MemoryDeviceSize : 8192 MemoryDevicePartNumberName : 36KD59G2PZ-28DL MemoryDeviceIndex : 2 MemoryDeviceType : DDR3 MemoryDeviceSerialNumberName : XJ48F45 MemoryDeviceTypeDetails : DDR3 DIMM MemoryDeviceName : DIMM.Socket.A2 MemoryDeviceStatus : 0 MemoryDeviceManufacturerName : Micron Technology DeviceId : 325 MemoryDeviceChassisIndex : 1 .NOTES Author: Mike Khar .LINK http://www.dell.com/support/home/us/en/04/product-support/product/dell-openmanage-essentials-v2.2/research https://$Server:$Port/api/OME.svc/$DeviceID/TableInventory/3 #> [CmdletBinding(DefaultParametersetName="Id" )] Param( [parameter(Mandatory=$true,ParameterSetName="Id",ValueFromPipeline=$true)] $Id, [parameter(Mandatory=$true,ParameterSetName="Name")] [String]$Name, [parameter(Mandatory=$true,ParameterSetName="AssetTag")] [String]$AssetTag, [parameter(Mandatory=$true,ParameterSetName="ServiceTag")] [String]$ServiceTag, $Session="OMEConnection.DefaultOMESession" ) Begin { $CurrentSession = Get-Variable -Scope Global -Name $Session -ErrorAction SilentlyContinue -ValueOnly If (!$CurrentSession) { Write-Warning "Please use Set-OMEConnection first" Break Return } else { $BaseUri="https://"+$CurrentSession.Server+":"+$CurrentSession.Port+"/api/OME.svc" } } Process { $string="Get-OMEDeviceInventory -Session $Session -Table 16" if ($Id) { $string+=' -Id $Id' } if ($Name) { $string+=' -Name $Name' } if ($AssetTag) { $string+=' -AssetTag $AssetTag' } if ($ServiceTag) { $string+=' -ServiceTag $ServiceTag' } if ($Credentials) { $string+=' -Credentials $Credentials' } return Invoke-Expression $string } End{} } |