powercli - PowerShell Object Count -


i'm using vmware powercli query datastores have amount of freespace. query come nothing, one, or more one. feel there's got easier way check if it's 1 or more one.

$ds = get-datastore | {$_.freesapcegb -gt 50} | sort-object freespacegb -descending 

i know check if results this

if ($ds) 

i know check if there's more one

if ($ds.count) 

if there more one, want use 1 freespace use first one

$ds[0] 

but if there one, $ds[0] not work , have use $ds, makes duplicate coding.

i know can limit results

| select -first 1 

but without limiting results there easier way this?

this should it:

$ds = @(get-datastore | {$_.freesapcegb -gt 50} | sort-object freespacegb -descending) 

then should able use $ds[0] long $ds.count greater 0.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -