custom fact with registry value

566 views
Skip to first unread message

kaustubh chaudhari

unread,
Jun 10, 2015, 1:17:21 PM6/10/15
to puppet...@googlegroups.com
Hi All,

I want to read registry value on windows system and present it as a fact. i tried it in many ways but no luck.

I have this powershell script in facts.d directory
==
$path = 'HKLM:\Software\SunGard\BigFix'
$wave = Get-ItemProperty $path | Select-Object -ExpandProperty bigfix
Write-Host zzzPatching_Wave = $wave
==

every time i run this errors out.  it directly displays $wave as key and Get-ItemProperty....... as value in dashboard. Not the actual output as value. However if i run this on system through powershell it gives the correct output.

Tried another way.
Created a custom fact.
==
Facter.add(:zpatchwave) do
  confine :kernelversion => "6.1.7601"
  setcode do
      powershell = 'C:\Windows\syswow64\WindowsPowerShell\v1.0\powershell.exe'
      command = '(Get-ItemProperty -Path "HKLM:Software\SunGard\BigFix" -name "bigfix")."bigfix"'
    Facter::Util::Resolution.exec(%Q{#{powershell} -command "#{command}"})
 end
end
==

but this is not executed successfully, it displays as path not found for HKLM in the dashboard.

Any help is appreciated. Struggling on this.

-Cheerzzz
Kaustubh

Rob Reynolds

unread,
Jun 10, 2015, 5:33:15 PM6/10/15
to puppet...@googlegroups.com
On Wed, Jun 10, 2015 at 12:17 PM, kaustubh chaudhari <kaus...@gmail.com> wrote:
Hi All,

I want to read registry value on windows system and present it as a fact. i tried it in many ways but no luck.

I have this powershell script in facts.d directory
==
$path = 'HKLM:\Software\SunGard\BigFix'
$wave = Get-ItemProperty $path | Select-Object -ExpandProperty bigfix
Write-Host zzzPatching_Wave = $wave
==

every time i run this errors out.  it directly displays $wave as key and Get-ItemProperty....... as value in dashboard. Not the actual output as value. However if i run this on system through powershell it gives the correct output.

Tried another way.
Created a custom fact.
==
Facter.add(:zpatchwave) do
  confine :kernelversion => "6.1.7601"
  setcode do
      powershell = 'C:\Windows\syswow64\WindowsPowerShell\v1.0\powershell.exe'
      command = '(Get-ItemProperty -Path "HKLM:Software\SunGard\BigFix" -name "bigfix")."bigfix"'
    Facter::Util::Resolution.exec(%Q{#{powershell} -command "#{command}"})
 end
end
==

You might try it another way, using ruby code.
Facter.add(:myfact) do
  confine :kernel => :windows
  setcode do
    require 'win32/registry'

    value = nil
    hive = Win32::Registry::HKEY_CLASSES_ROOT
    hive.open('SOFTWARE\Somewhere\SomeValue',  Win32::Registry::KEY_READ | 0x100) do |reg|
      value = reg['SomeValue']
    end
    value
  end
end    
 

but this is not executed successfully, it displays as path not found for HKLM in the dashboard.

Any help is appreciated. Struggling on this.

-Cheerzzz
Kaustubh

--
You received this message because you are subscribed to the Google Groups "Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to puppet-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/puppet-users/bf96b0d5-82df-4a45-b1df-dc5b8a5fe717%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Rob Reynolds
Developer, Puppet Labs

PuppetConf 2015 is coming to Portland, Oregon! Join us October 5-9.
Register now to take advantage of the Early Adopter discount save $349!

Rob Reynolds

unread,
Jun 10, 2015, 5:37:52 PM6/10/15
to puppet...@googlegroups.com
On Wed, Jun 10, 2015 at 4:32 PM, Rob Reynolds <r...@puppetlabs.com> wrote:


On Wed, Jun 10, 2015 at 12:17 PM, kaustubh chaudhari <kaus...@gmail.com> wrote:
Hi All,

I want to read registry value on windows system and present it as a fact. i tried it in many ways but no luck.

I have this powershell script in facts.d directory
==
$path = 'HKLM:\Software\SunGard\BigFix'
$wave = Get-ItemProperty $path | Select-Object -ExpandProperty bigfix
Write-Host zzzPatching_Wave = $wave
==

every time i run this errors out.  it directly displays $wave as key and Get-ItemProperty....... as value in dashboard. Not the actual output as value. However if i run this on system through powershell it gives the correct output.

FWIW, I think you are running into registry redirection (built in to Windows). As in you are running Puppet from a 32-bit process on a 64-bit operating system, so it doesn't see your 64-bit registry value. I wrote a blog post[1] awhile back talking about some common things you might run into with Windows. You can also read more about registry redirection and our 64-bit versions of Puppet on the Windows overview page[2].

kaustubh chaudhari

unread,
Jun 11, 2015, 2:11:04 PM6/11/15
to puppet...@googlegroups.com
Cool! Thanks for your direction.

I am running puppet 3.6 which is a 32bit binary. Which was eventually calling 32bit binary of powershell on 64bit system. This partially works, 32bit powershell have limited visibility to registry not all registry.

I just changed the command section from this(c:\windows\system32 to c:\windows\sysnative)after this it used the correct system native powershell binary.


Atlast done! Once again thanks for your help Rob! Have a nice time ahead!

-Kaustubh


Reply all
Reply to author
Forward
0 new messages