Hi,
So I'm struggling to find a way to collect all of the registry entries in "SOFTWARE\Microsoft\Windows NT\CurrentVersion" on a remote machine, that I can pass login credentials to. I'm looking to replicate what Win32_Product does initially,
but will also want to grab other info from the registry too. I've read that Win32_Product isn't a good idea to run as it can cause issues, its also slow as hell. So I'm trying to figure out an alternative.
I'm trying to convert a VBS script over into Powershell, got everything working. But this.
The Get-WmiObject seems like the way to do it, but I can't figure out how to get it to grab multiple entries like Win32_Product does.
$reg = Get-WmiObject -List -Namespace root\default -ComputerName $Computer -Credential $Cred | Where-Object {$_.Name -eq "StdRegProv"}
$HKLM = 2147483650
$reg.GetStringValue($HKLM,"SOFTWARE\Microsoft\Windows NT\CurrentVersion","ProductName").sValue
This will grab a single value, but I can't figure out how to modify it so that I can get all values.
My attempt at modifying it with the below doesn't work. :(
$reg = Get-WmiObject -List -Namespace root\default -ComputerName $Computer -Credential $Cred | Where-Object {$_.Name -eq "StdRegProv"}
$HKLM = 2147483650
$RegKey = $reg.EnumValues($HKLM,$KeyAddress)
$SubKeys = $RegKey.GetSubKeyNames()
Foreach($key in $SubKeys) {
$thiskey = $UninstallKey+"\\"+$Key
$ThisSubKey = $Reg.OpenSubKey($ThisKey)
$DisplayName = $ThisSubKey.GetValue("DisplayName")
Write-Host $ComputerName, $DisplayName
}
...
Using .Net works, kind of - But ...
1) I can't work out how to pass credentials
2) The below code will only pull the root folders of HKEY_LOCAL_MACHINE. The OpenSubKey isn't doing what I'd expect.
3) I'll need to modify it so that it actually writes results to an object/array.
$key = "SOFTWARE\Microsoft\Windows\CurrentVersion"
$type = [Microsoft.Win32.RegistryHive]::LocalMachine
$regKey = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey($type, $Computer)
$regKey = $regKey.OpenSubKey($key)
Write-Host "Sub Keys"
Write-Host "--------"
Foreach($sub in $regKey.GetSubKeyNames()){$sub}
Write-Host
Write-Host "Values"
Write-Host "------"
Foreach($val in $regKey.GetValueNames()){$val}
I feel like I've checked every link online about this to no avail.
If only Get-ItemProperty had a -MachineName -Credentials properties! It's so tidy, simple and fast... :(
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | select DisplayName, Publisher, InstallDate
Just as a further note, this codes going into RunSpaces to be performed in parallel. But I can't guarantee that Invoke-Command will be enabled on the target computer. I'm also trying to target the script to run in Powershell 2.0 if possible.
Thanks for any help or links that will point me in the right direction.