DiskPart “Attribute Volume” Object Not Found

The title isn’t very pretty, but it gets the point across.  I had a weirdly partitioned computer come in to my shop, and I needed to make corrections.  The last issue I confronted was that the Recovery partition had a drive letter… it shouldn’t.  The user shouldn’t see it at all, normally.  But when I tried

attribute volume set nodefaultdriveletter

I was presented with an “Object Not Found” message.  I searched for a solution but could not find one; I was about to give up when I had an idea.

(Note that the drive in question was a Basic disk.  This likely doesn’t work the same way for Dynamic disks; I haven’t tried it so I can’t say for sure.)

First, I did:

select partition <x>

where <x> was the partition for the C: drive.  Then I did:

detail partition

I highlighted and copied the GUID after the Type: heading and pasted it into a notepad window.  I then selected the “problem” partition and did the same thing, so that now I knew both of the Type ID values.  Then, with the problem partition still selected I did:

set id=<drive-C-type>

Now I was able to fix the volume:

select volume <problem-partition>

attribute volume set nodefaultdriveletter

This time it worked.  Finally, I made sure the problem partition was still selected and did:

set id=<problem-partition-type>

to put the partition back to the correct type.

Rebooted just to make sure, and all was well.