Hi,
I am getting the blank output without any error for below script,
Please help!!
$ramDisks = 'root','tmp','vsantraces'
$report = @()
Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx.Name -V2
$esxcli.system.visorfs.ramdisk.list.Invoke() |
where{$ramDisks -contains $_.RamdiskName -and $_.Free -lt 99}|
ForEach-Object -Process {
$obj = [ordered]@{
vCenter = ([uri]$esx.ExtensionData.Client.ServiceUrl).Host
Cluster = (Get-Cluster -VMHost $esx).Name
VMHost = $esx.Name
RAMDisk = $_.RamdiskName
FreePre = $_.Free
}
}}
$report | ft -auto
That is due to the automatic casting PS is doing.
The Free property returns a [String], and since you place Free on the left side of the comparison, the right side is converted to an [String] as well.
For [String] comparison, the strings are compared character by character, left to right.
So you end up with the funny situation that '99' -lt '100' returns $false and '100' -lt '99' returns $true.
To fix it you can do explicit casting
[int]$_.Free -lt 100
or interchange the left and right operands, which forces the Free property to be converted to an [Int].
100 -ge $_.Free
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You are not storing anything in $report.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
Thanks for your input. If I provide the free space less than 100, i still see blank output but if I provide 99, it shows me a output, not sure, if I am missing something
$ramDisks = 'root','tmp','vsantraces'
Get-VMHost -PipelineVariable esx |
ForEach-Object -Process {
$esxcli = Get-EsxCli -VMHost $esx.Name -V2
$esxcli.system.visorfs.ramdisk.list.Invoke() |
where{$ramDisks -contains $_.RamdiskName -and $_.Free -lt 99} |
ForEach-Object -Process {
New-Object -TypeName PSObject -Property @{
vCenter = ([uri]$esx.ExtensionData.Client.ServiceUrl).Host
Cluster = (Get-Cluster -VMHost $esx).Name
VMHost = $esx.Name
RAMDisk = $_.RamdiskName
FreePre = $_.Free
}}
} | ft -auto
That is due to the automatic casting PS is doing.
The Free property returns a [String], and since you place Free on the left side of the comparison, the right side is converted to an [String] as well.
For [String] comparison, the strings are compared character by character, left to right.
So you end up with the funny situation that '99' -lt '100' returns $false and '100' -lt '99' returns $true.
To fix it you can do explicit casting
[int]$_.Free -lt 100
or interchange the left and right operands, which forces the Free property to be converted to an [Int].
100 -ge $_.Free
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Got it....Thank you very much. 🙂