SeraGS
Contributor
Contributor

Issue getting Properties invoking ssacli commands in PowerCLI

Hello,
I am very new in PowerShell and PowerCLI. Appreciate your help in advance!
Need to get only few properties from HPE ssacli ESXi commands.
My Script:
$Folder = "DC1"
$VICENTERNAME = Read-Host "Please enter your vcenter"
$SERVERNAME = "esxprod09"
$defUSERNAME = "administrator@vsphere.local"
$USERNAME = Read-Host -Prompt "Enter your username [$defUSERNAME]"
$PASSWORD = Read-Host -assecurestring "Enter your password"
$PASSWORD = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto([System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password))
Connect-VIServer -Server $VICENTERNAME -User $USERNAME -Password $PASSWORD -Force
$hostsrc=Get-VMHost -Server * -Location $Folder | Sort Name | where {$_.Name -match $SERVERNAME}
Write-Host "Servidor: $hostsrc ####"
$esxcli = get-esxcli -vmhost $hostsrc -V2
$ssacliargs1 = $esxcli.ssacli.cmd.createargs()
$ssacliargs1.cmdopts = "ctrl all show status"
$esxcli.ssacli.cmd.invoke($ssacliargs1)
# LD Logical Disk
$ssacliargs2 = $esxcli.ssacli.cmd.createargs()
$ssacliargs2.cmdopts = "ctrl slot=0 ld all show status"
$esxcli.ssacli.cmd.invoke($ssacliargs2)
# PD Physical Disks
$ssacliargs3 = $esxcli.ssacli.cmd.createargs()
$ssacliargs3.cmdopts = "ctrl slot=0 pd all show detail"
$esxcli.ssacli.cmd.invoke($ssacliargs3)
Write-Host "####################"

Would like to get similar to that:
Server,SmartArray,Status,LD,PD1,PD1-Size,PD2,PD2-Size
esxprod09,Smart Array P244br in Slot 0,OK,1,OK,300 GB,OK,300 GB

But result is:
Server: esxprod09 ####
Smart Array P244br in Slot 0 (Embedded)
Controller Status: OK
Cache Status: OK
Battery/Capacitor Status: OK
logicaldrive 1 (279.37 GB, RAID 1): OK
Smart Array P244br in Slot 0 (Embedded)

Array A

physicaldrive 1I:1:1
Port: 1I
Box: 1
Bay: 1
Status: OK
Drive Type: Data Drive
Interface Type: SAS
Size: 300 GB
Drive exposed to OS: False
Logical/Physical Block Size: 512/512
Rotational Speed: 10500
Firmware Revision: HPD5
Serial Number: 02V1JL2H
WWID: 5000CCA03502CA7D
Model: HP EG0300JEHLV
Current Temperature (C): 26
Maximum Temperature (C): 48
PHY Count: 2
PHY Transfer Rate: 12.0Gbps, Unknown
PHY Physical Link Rate: Unknown, Unknown
PHY Maximum Link Rate: Unknown, Unknown
Drive Authentication Status: OK
Carrier Application Version: 11
Carrier Bootloader Version: 6
Sanitize Erase Supported: True
Sanitize Estimated Max Erase Time: 0 hour(s), 42 minute(s)
Unrestricted Sanitize Supported: False
Shingled Magnetic Recording Support: None

physicaldrive 1I:1:2
Port: 1I
Box: 1
Bay: 2
Status: OK
Drive Type: Data Drive
Interface Type: SAS
Size: 300 GB
Drive exposed to OS: False
Logical/Physical Block Size: 512/512
Rotational Speed: 10500
Firmware Revision: HPD5
Serial Number: 02V1LYKE
WWID: 5000CCA03502EE15
Model: HP EG0300JEHLV
Current Temperature (C): 26
Maximum Temperature (C): 48
PHY Count: 2
PHY Transfer Rate: 12.0Gbps, Unknown
PHY Physical Link Rate: Unknown, Unknown
PHY Maximum Link Rate: Unknown, Unknown
Drive Authentication Status: OK
Carrier Application Version: 11
Carrier Bootloader Version: 6
Sanitize Erase Supported: True
Sanitize Estimated Max Erase Time: 0 hour(s), 42 minute(s)
Unrestricted Sanitize Supported: False
Shingled Magnetic Recording Support: None
####################

Thanks

0 Kudos
5 Replies
LucD
Leadership
Leadership

Did you try with a Select-Object and then the names of the properties you like to see

$esxcli.ssacli.cmd.invoke($ssacliargs3) | Select-Object -Property Server, 'Smart Array', ....


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
SeraGS
Contributor
Contributor

Than you LuCD
Yes,

$esxcli.ssacli.cmd.invoke($ssacliargs1) | Select-Object -Property Server, 'Smart Array', 'Cache Status','Battery/Capacitor Status',Name,Status,State | ft

Server Smart Array Cache Status Battery/Capacitor Status Name Status State
------ ----------- ------------ ------------------------ ---- ------ -----

Other tests:
$esxcli.ssacli.cmd.invoke($ssacliargs1) | Select-Object -Property *
Length
------
116

$var1 = $esxcli.ssacli.cmd.invoke($ssacliargs1) | Select-Object -Property *
$var1.Length
116

The case is that the ssacli is not a PS Module. it is a lsit of HPE commands installed in esxi host.


0 Kudos
LucD
Leadership
Leadership

That looks as if that command is returning 1 big string.
You could try to use the Split method to see if that gives you the individual result one by one.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
SeraGS
Contributor
Contributor

Could you send me an example please?

0 Kudos
LucD
Leadership
Leadership

I don't have the HW to run that command I'm afraid.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos