Disk number only from Get-Disk

I'm writing a PowerShell script and I want to get the Number only from Get-Disk.

Something like this.  

$DiskNum=Get-Disk|Where-ObjectFilterScript{$_.Bustype -Eq"USB"} |Select-ObjectNumber

However I want $DiskNum to have just the disk number.  At the moment has a table that looks like this Number

                                                                                                                                                      ---------

                                                                                                                                                             1

All and any comments greatly appreciated.

WD   

December 12th, 2014 5:21pm

Use 'Select-Object -ExpandProperty Number' on the end.

Free Windows Admin Tool Kit Click here and download it now
December 12th, 2014 5:26pm

So you're aware, you can also do this with dotted-notation in PowerShell 3.0 and greater, which you must be using if you're using the Get-Disk cmdlet.

$DiskNum = (Get-Disk | Where-Object FilterScript {$_.Bustype -Eq "USB"}).Number


December 12th, 2014 5:43pm

Alright.  Both yours and Tommy's solution work just fine.   Although on first try your solution seems a bit faster.  Further testing will be done.

Thanks guys.

WD

Free Windows Admin Tool Kit Click here and download it now
December 12th, 2014 6:37pm

So you're aware, you can also do this with dotted-notation in PowerShell 3.0 and greater, which you must be using if you're using the Get-Disk cmdlet.

$DiskNum = (Get-Disk | Where-Object FilterScript {$_.Bustype -Eq "USB"}).Number


December 13th, 2014 1:23am

So you're aware, you can also do this with dotted-notation in PowerShell 3.0 and greater, which you must be using if you're using the Get-Disk cmdlet.

$DiskNum = (Get-Disk | Where-Object FilterScript {$_.Bustype -Eq "USB"}).Number


Free Windows Admin Tool Kit Click here and download it now
December 13th, 2014 1:23am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics