Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Sort Physical Disks by FriendlyName

$
0
0

Hi Folks,

Sorry but the syntax for trying to do this has gotten the better of me tonight.

I have some Azure disks I want to work on that I've retrieved like this:

$uninitializedDisks = Get-PhysicalDisk -CanPool $true

That returns 11 disks. I want to select the first two drives based on a numeric ordering of the FriendlyName. For example, if I just view the value of:

$unitializedDisks

The friendly names appear as:

PhysicalDisk5
PhysicalDisk11
PhysicalDisk3

and so on. I want to retrieve:

PhysicalDisk1
PhysicalDisk2

I was getting to really messy syntax like:

$uninitializedDisks | sort-object -Property @{Expression={int.Parse($_FriendlyName.ToString().SubString(12, $_FriendlyName.ToString().Length – 12).PadLeft(2,"0"))}} | Select-Object -First 2

But still must have been doing something wrong.

Any help would be appreciated.


Viewing all articles
Browse latest Browse all 13067

Trending Articles