I want to sort array only if it contains more than N elements, something like this:
$myArray | if $myArray.Count() > N -> | Sort-Object
How can I do this in one line?
You can just use an if statement and do everything in one line:
if ($myArray.Length -gt N) { $myArray = $myArray | Sort-Object }
But why would you wan't to do it? I would prefer it this way:
if ($myArray.Length -gt N)
{
$myArray = $myArray | Sort-Object
}
You might wan't to find a solution without an if statement (only pipeline) but I don't see a reason for that.