0
votes

I'm trying to format an USB drive with powershell. The only problem is that it ereases everything of the disk but doesn't create a partition.

And I don't know how to get this working. Does anyone have an idea?

$driveLetter = "D";
Format-Volume -DriveLetter $driveletter -NewFileSystemLabel "Formated USB drive" -Force -FileSystem NTFS;

Error Message:

Format-Volume : Invalid Parameter
Activity ID: {dcc55555-5b20-4fe0-9abf-4d40078f4c36}
At C:\formatUsb.ps1:2 char:9
+         Format-Volume -DriveLetter $driveletter -NewFileSystemLabel $ ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (StorageWMI:ROOT/Microsoft/...age/MSFT_Volume) [Format-Volume], CimE
    xception
    + FullyQualifiedErrorId : StorageWMI 5,Format-Volume
1
I have just tried it and it works for me. Copy-pasted the whole command, executed successfully - Vladimir Bundalo
Are you also running Windows 10? @VladimirBundalo - StuiterSlurf
Yes - version 10.0.15063 - Vladimir Bundalo
Did you setup anything special with your powershell? - StuiterSlurf
Nope, but I have to apologize as I didn't wait until the end. It is throwing me the same error message. I am trying different combinations now - Vladimir Bundalo

1 Answers

0
votes

I only changed one thing at it worked. But i don't know how or why

$driveLetter = "D:"; Format-Volume -DriveLetter $driveletter -NewFileSystemLabel "Formated USB drive" -Force -FileSystem NTFS;

My code looks like this:

$SelSource = Read-Host
$filesystem = Read-Host
if ($filesystem -match "NTFS")
{
  Write-Host "Info:" -ForegroundColor Blue -NoNewline; Write-Host " NTFS Doesn't work on all USBs."
  Format-Volume -DriveLetter $SelSource -Force -FileSystem NTFS;
}