Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Written by Thomas Deans - thomas@thomasdeanstech.com - February, 2020
- # Note: Only insert Flash drives you want to be formatted. I was formatting in batches of 8 at a time
- Param(
- $Drives
- )
- $USBLabel = "1234567890"
- $FlashFileSysType = "FAT32"
- $NewFlashFileSysType = "exFAT"
- if ([string]::IsNullOrEmpty($Drives) -or [string]::IsNullOrWhiteSpace($Drives)) { $Drives = $false }
- if ($Drives -eq $false) {
- $Drive_Letters = (Get-Volume | ? { $_.FileSystemType -eq $FlashFileSysType } | ? { $_.DriveType -eq 'Removable' }).DriveLetter
- } else { $Drive_Letters = $Drives }
- # Drive name must follow DOS 8 character limit
- foreach ($DL in $Drive_Letters) {
- Format-Volume -DriveLetter $DL -FileSystem $NewFlashFileSysType -NewFileSystemLabel $USBLabel.Substring(0,8) -Force -Verbose
- }
- Get-Volume | ? { $_.FileSystemType -eq 'Unknown' } | ? { $_.DriveType -eq 'Removable' } | select DriveLetter,FileSystemType,FileSystemLabel,SizeRemaining
- #Eject Flash Drives retainign drive letters
- foreach ($DL in $Drive_Letters) {
- Write-Verbose "Ejecting: $DL" -Verbose
- $driveEject = New-Object -comObject Shell.Application
- $driveEject.Namespace(17).ParseName("$($DL):").InvokeVerb("Eject")
- sleep -s 1
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement