Can I do this in powershell? Read the Registry, write out binary contents to file Can I do this in powershell? Read the Registry, write out binary contents to file powershell powershell

Can I do this in powershell? Read the Registry, write out binary contents to file


You don't want to use Out-File because it outputs as a string and uses unicode to boot. The following works based on a similar registry entry:

$b = Get-ItemProperty HKLM:\HARDWARE\ACPI\DSDT\A7546\A7546011\00000011 00000000$b.'00000000' | Set-Content foo.txt -enc byte

Note that Set-Content is useful when you want more direct control over what gets written to file especially if you want to write raw bytes.


$a = gp 'HKLM:\HARDWARE\ACPI\DSDT\HP____\8510x\0001000' '00000000'if ( test-path 8510x.orig ){   echo 'File 8510x.orig already exists.'}else{   [System.IO.File]::WriteAllBytes("8510x.orig",$a."00000000")   echo 'Wrote 8510x.orig'}

I'm leaving my previous answer (above) as an example of accessing .NET objects from PowerShell; but after seeing keith-hill's answer I had to revise mine to use set-content as well:

$a = gp HKLM:\HARDWARE\ACPI\DSDT\HP____\8510x\0001000 00000000if ( test-path 8510x.orig ){   echo 'File 8510x.orig already exists.'}else{   $a.'00000000' | Set-Content 8510x.orig -enc byte    echo 'Wrote 8510x.orig'}


Try the following

$a = gp "hklm:\HARDWARE\ACPI\DSDT\HP____\8510x\0001000" "00000000"$a."00000000" | out-file 8610x.orig