windows – How can i get the size of a disk and save it in a variable to delete it in diskpart ? CMD/BASH

i have following problem:
I would like to intercept the size of a hard drive in WinPe-Live and then delete it in Diskpart or not. Since it happens when the hard drive in the computer is defective, the USB stick deletes itself with the WinPe-Live system. To prevent this, I would like to make a query that asks the size of the hard drive or USB stick in order to format it or not to format it.

Hope you can help me with a code snippet or another solution to prevent the stick from deleting itself.