Alex Rivera | Logout

How to access the 64-bit registry from a 32-bit Powershell instance?

Asked 2009-03-10T14:11:09.970
23

If you launch a 32-bit instance of Powershell (%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe), then the registry provider only sees the limited 32-bit parts of the registry.

**32-bit console**
PS> (dir HKLM:\SOFTWARE | measure).count - (dir HKLM:\SOFTWARE\wow6432node | measure).count

0

**64-bit console**
PS> (dir HKLM:\SOFTWARE | measure).count - (dir HKLM:\SOFTWARE\wow6432node | measure).count

-5

Is there any way to force the provider into 64-bit mode? I could drop down to [Microsoft.Win32] .Net APIs, or maybe WMI, but I'd rather not. I'm using Powershell v2 CTP3 if that expands the possibilities at all.

Edit
Report

1 Answer

7

I believe the built in cmdlet Start-Job will allow you to check the 64 bit registry from a 32-bit instance.

If not, using Invoke-Command to loop back to the local machine wil. A 64-bit machine will have two endpoints (64-bit and 32-bit), and the 64-bit endpoint will be the default.

Example creating a registry value and ensuring it is in the 64-bit path, not 32.

Invoke-Command -scriptblock {
    New-ItemProperty -Path HKLM:\SOFTWARE\Acme 
                     -Name NameofNewReg 
                     -PropertyType String -Value "1"
    } -computername .
answered 2011-01-10T06:31:05.823

Your Answer