I’m trying to make a powershell script that will clone a disk to a .img file.
It works if I run each command separately, but doesnt when compiled into a .ps1 file.
$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 FilesGitusrbindd.exe" if={0} of={1} bs=1M' -f $_.DeviceID,(-join($BaseOutputPath,(-join($Env:ComputerName,$_.Index)),'.img')))}
When run, I get the following output:
. : The term '& "C:Program FilesGitusrbindd.exe" if=\.PHYSICALDRIVE2 of=D:THEIAGO2.img bs=1M' is not
recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if
a path was included, verify that the path is correct and try again.
At line:1 char:19
+ ... rives | %{. ('& "C:Program FilesGitusrbindd.exe" if={0} of={1} b ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (& "C:Program F...IAGO2.img bs=1M:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
And then running & "C:Program FilesGitusrbindd.exe" if=\.PHYSICALDRIVE2 of=D:THEIAGO2.img bs=1M
alone runs as expected.
I’ve tried everything to fix it, like cd’ind to the exe dir, and running it locally with .dd.exe but it still doesn’t work.