0

I am running PS cmdlet get-customcmdlet which is generating following output

Name                         FreeSpaceGB
----                         -----------
ABC-vol001                   1,474.201
ABC-vol002                   2,345.437     
ABC-vol003                   3,147.135
random-value                 4,147.135

I want to capture 003 from the highest volume number ABC-vol003 I also want to ignore random-value and only want to consider the values which have vol in it

get-customcmdlet | select Name 

Name              
----          
ABC-vol001   
ABC-vol001      
ABC-vol001
random-value

Here, I want 003 to be variable based upon highest volume number

0

1 Answer 1

2

You could do a custom sort, and select the last item, like:

Get-CustomCmdlet | Sort {$_.Name -replace '.*?(\d+)$','$1'} | Select -Last 1

Edit: It looked like you already knew how to use Where, since you had that in your question before you edited it out, but you can use that to only get volumes that have 'vol' in the name, then sort those...

Get-CustomCmdlet | Where{$_.Name -match '-vol\d+'} | Sort {$_.Name -replace '.*?(\d+)$','$1'} | Select -Last 1
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks! I have made a small update to my question. can you please answer accordingly
Doesn't add much, but you can also use ... -descending | Select -First 1.
I am getting random-value 4,147.135 as an output. I want to ignore all random-value and include only which have vol within it
I am able to achieve it by using select Name | Where-Object Name -match vol

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.