question

MathivananLakshmipriya-9575 avatar image
0 Votes"
MathivananLakshmipriya-9575 asked MathivananLakshmipriya-9575 answered

Unable to fix the issue with powershell script when using get-disk command

Get-disk -Number 3 | select UniqueId

gives below error

Get-Disk : No MSFT_Disk objects found with property 'Number' equal to '3'. Verify the value of the property and retry.
At line:1 char:13
+ $UNIQUEID = Get-Disk -Number 3 | Select UniqueId
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (3:UInt32) [Get-Disk], CimJobException
+ FullyQualifiedErrorId : CmdletizationQuery_NotFound_Number,Get-Disk

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ClementBETACORNE avatar image
0 Votes"
ClementBETACORNE answered MathivananLakshmipriya-9575 commented

Hello,

Are you sure that you have 4 disks attached on your computer ?
If it is not the case you should use wrap your command with a try catch in order to prevent the message for example :

 try {
 Get-disk -number 3 -ErrorAction Stop
 }
 catch {
 Write-output "Less than 4 disk"
 }



· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi,

Thanks for your response. Let me run this way, and will let you know.

0 Votes 0 ·
RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered

You can also code it this way (although the code submitted by @ClementBETACORNE will work quite well).

 $d = Get-Disk |
         ForEach-Object{
             if ($_.Number -eq $WantedDiskNumber){
                 $_.UniqueId
             }
         }
 if ($d){
     $d
 }
 else{
     "Disk number $WantedDiskNumber wasn't found"
 }
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

MathivananLakshmipriya-9575 avatar image
0 Votes"
MathivananLakshmipriya-9575 answered ClementBETACORNE commented

I can able to get the output for disk number 0 but I couldn't get it for number 3. and I have the disk installed.

can someone please help me to troubleshoot this issue?

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

When you run get-disk without the number parameter what do you have ?

Regards,

0 Votes 0 ·
MathivananLakshmipriya-9575 avatar image
0 Votes"
MathivananLakshmipriya-9575 answered

154665-img.png





img.png (61.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.