0

I'm trying to build a tool that creates a bootable usb and assign a free drive letter I found here a useful script and did some modification to it

$freeletter = get-wmiobject win32_logicaldisk | select -expand DeviceID -Last 1 | % { [char]([int][char]$_[0]  + 1) + $_[1] }
$splitted = $freeletter -split ":"
[char]$splitted

now I have the free drive letter stored in "$splitted" variable but when I run the following command

New-Partition -DiskNumber $disknumber -UseMaximumSize -IsActive:$true -DriveLetter $splitted

I receive the following error:

New-Partition : Cannot process argument transformation on parameter 'DriveLetter'. Cannot convert the "System.String[]" value of type "System.String[]" to type 
"System.Char".

any suggestion please

1 Answer 1

1

You can simplify it and determine $freeletter like this:

[char]$freeletter = (get-wmiobject win32_logicaldisk | select -expand DeviceID -Last 1)[0]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.