Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Powershell command line equivalent of dd

I am writing a Powershell script to make a raw copy of a drive and I have been unable to find a way to complete this.

On Linux, I would use 'dd' to perform this copy.

There are a handful of tools that can do this on Windows but none that I can control directly from the command line. (All have GUI interfaces)

Is there a method to make a physical copy of a drive through Powershell?

Thanks.

like image 711
R3dChief Avatar asked Jun 02 '16 17:06

R3dChief


1 Answers

I've been trying to do this for a while myself and I finally found a good answer.

Git for windows ships with the whole set of GNU core utilities (updated vs what you can find separately) including dd!

Just install Git for Windows or extract the portable version, from there inside of the install directory in git\usr\bin\ you will find the binaries for all of the GNU utils including dd (tested working)

Some further notes on usage in windows since \dev\sda\ isn't a thing:

$DiskDrives = Gwmi Win32_diskdrive | select DeviceID,BytesPerSector,Index,Caption,InterfaceType,Size,TotalSectors,SerialNumber | Out-GridView -OutputMode Multiple -Title 'Select Source Drive(s)'

$BaseOutputPath = 'D:\'
$DiskDrives | %{
. ('C:\Program Files\Git\usr\bin\dd.exe if={0} of={1} bs={2}' -f $_.DeviceID,(-join($BaseOutputPath,(- 
    join($Env:ComputerName,$_.Index)),'.img')),$_.BytesPerSector)
}

The included filename logic is just a placeholder, you can replace that parenthetical with a call to Read-Host if you want it to prompt you for the filename/path.

It is a bit annoying but you really do have to use WMI as the values returned by Get-Disk don't seem to work.

like image 63
Chirishman Avatar answered Sep 20 '22 13:09

Chirishman