Powershell: Remote reg query


I need to query a reg value on 200+ servers. Could you please provide me with some guidance and a sample script.  WinRm is not enabled.  If Powershell cannot be used, Is there anything alternate to Powershell script that I can use.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Benjamin VoglarIT ProCommented:
Toni UranjekConsultant/TrainerCommented:
Preferences are for setting values.

You can use reg query if you have Remote Registry service running.

REG QUERY \\RemoteComputer\HKLM\Software\Microsoft\ResKit\Nt\Setup /s

Open in new window

You might want to check this article:

Querying Any Registry Information on Remote Computers via Script
Parity123Author Commented:
@Toni. I checked the link above. This is the kind of reported I wanted. The limitation is that it can query only one reg key/value. I have to query close to 20 Reg Keys. I have to run the script 20 times and I will get 20 reports. I was trying to see if I can get all in one report.

Query multiple reg keys on multiple computers and generate a csv report. If the machine is not reachable it should log not reachable.
Making Bulk Changes to Active Directory

Watch this video to see how easy it is to make mass changes to Active Directory from an external text file without using complicated scripts.

Toni UranjekConsultant/TrainerCommented:
Now you are stepping into the realm of WinRM and Powershell. Simple batch scripts will not produce desired result in such case. Or you can concatenate reports?

BTW, WinRM can be quickly configured through GPO.
Parity123Author Commented:
I am trying to get a dword value, and here is my code

$servername = "Computer1"
$key = "SOFTWARE\Microsoft\Windows\CurrentVersion\BITS"
$value = "somedwordsetting"

$MyReg1 = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $Servername)
$MyRegKey= $MyReg1.OpenSubKey("$key")            
$MySetting = $regkey.GetValue("$value")

write-host $MySetting

when the dword value in registry is set as fffffff it returns  -1.

Please assist.
Toni UranjekConsultant/TrainerCommented:
I do not know where -1 came from, 0xFFFFFFFF usualy means allow or enabled,
0x00000000 usualy means disabled.

Does this make any sense in your case?
Parity123Author Commented:
We have some values (DWORD) set to 0xffffffff (4294967295 in decimal). The regquery returns -1 in this case.
Parity123Author Commented:
Unless the following setting cannot hold such a large decimal value (4294967295 in decimal).

$MySetting = $regkey.GetValue("$value")

Do I need to store/convert the value as Float....
Toni UranjekConsultant/TrainerCommented:

Single or double precision?
Parity123Author Commented:
I am not sure how to retrieve this value as is
Parity123Author Commented:
I read this on another blog, the following is vbscript, but I need this translated in powershell

The bits which represent 4294967295 in a UInt32 are the same bits which
 represent -1 in an Int32:

 Dim a As Int32 = -1
 Dim b As UInt32
 b = BitConverter.ToUInt32(BitConverter.GetBytes(a), 0)

Toni UranjekConsultant/TrainerCommented:
Try this:

[single]$MySetting = $regkey.GetValue("$value")


[double]$MySetting = $regkey.GetValue("$value")
You're correct about the unsigned vs. signed int.  See the output of these two commands.

Open in new window

To see that "-1" as hexidemical
$value = -1
#or with the leading "0x"
"0x{0:x}" -f $value

Open in new window

To see as decimal (unsigned int32)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.