Burn USB Key PowerShell

Christmas bonus post...

For Christmas - amongst other things - I got 3 more Jamiroquai albums (I’ve got all 8 now) and also an Amazon Giftcard with which I purchased Anjunabeats Volume 13. So, I wanted to update my car music USB key, but needed to use a fresh USB key. I realized that the method of my 24th April 2018 post Using PowerShell to Create a Correctly Ordered USB Music Key was way too clunky, so came up with the following script.

You’ll need to copy all your music into a folder of folders first, and make sure it’s ordered how you want.

Image: Car Music folder

Then just run the PowerShell as in the below example:

.\BurnUSB.ps1 -SourcePath "D:\CAR MUSIC" -DestinationDrive F

And your USB key will be burned like a CD (since car music systems read USB keys like a CD, that is the first copied file is first in the playlist, second copied second, third copied third, etcetera.)

The Script


Param(
  [Parameter(Mandatory=$true)][String]$SourcePath,
  [Parameter(Mandatory=$true)][String]$DestinationDrive
)

[System.Array]$Folders = (Get-ChildItem $SourcePath | sort-object Name).Name

Foreach($Folder in $Folders){
  [String]$NewFolderPath = Join-Path ($DestinationDrive + ":") ($Folder)
  "New-Item -Path $NewFolderPath -ItemType directory"
  New-Item -Path $NewFolderPath -ItemType directory

  [String]$ReadFolderPath = Join-Path ($SourcePath) ($Folder)
  [System.Array]$MusicFiles = (Get-ChildItem $ReadFolderPath | sort-object Name).Name

  $MusicFiles | Foreach{
    [String]$FileToCopy = Join-Path ($ReadFolderPath) ($_)
    [String]$FileDestination = Join-Path ($NewFolderPath) ($_)
    "Copy-Item -LiteralPath $FileToCopy $FileDestination"
    Copy-Item -LiteralPath $FileToCopy $FileDestination
  }
}


Comments

  1. A modest suggestion...MP3Tag. And all your issues about music contents, ordering, naming, tagging and so on will disappear! ;-)

    ReplyDelete

Post a Comment