O R G A N I C / F E R T I L I Z E R: powershell: counting characters to validate strings...

Nov 17, 2010

powershell: counting characters to validate strings...

throwing a note together for my failing memory.

while running a command to retrieve some values from esx, chris and I ran into a weird problem.  the following command would fail to retrieve the scsi lun information where the model equals symmetrix.

Get-VMHost myESXHost | Get-ScsiLun | where { $_.Model -eq "SYMMETRIX" }

 

while this failed, it worked using a wildcard search.

Get-VMHost myESXHost | Get-ScsiLun | where { $_.Model -like "*sym*" }

 

the most logical thing we decided was funky characters -- and most likely whitespace.  this is what I came up with to find the character count in the model:

(Get-VMHost myESXHost | Get-ScsiLun | where { $_.Model -like "*sym*" } | Select-object -First 1).model | Measure-Object -Character