Custom Facts for windows with powershell

670 views
Skip to first unread message

Harish Kothuri

unread,
May 23, 2016, 2:08:29 PM5/23/16
to Puppet Users
Hi, 

I'm trying to create a custom fact to get the installed software using powershell command in windows as follows...


PS Command:- 
Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | where{$_.DisplayName -and $_.displayname -notmatch 'Update'} | Select-Object DisplayName, DisplayVersion | ForEach-Object {Write-Host $_.DisplayName"="$_.DisplayVersion}

Output:-
7-Zip 15.14 = 15.14
ActiveState ActiveTcl 8.4.20.0 = 8.4.20.0
Microsoft .NET Framework 4 Client Profile = 4.0.30319
Microsoft .NET Framework 4 Extended = 4.0.30319
Notepad++ = 6.9.1
Microsoft .NET Framework 4 Extended = 4.0.30319
Puppet = 3.8.7
Microsoft Visual C++ 2012 Redistributable (x86) - 11.0.61030 = 11.0.61030.0
Microsoft .NET Framework 4 Client Profile = 4.0.30319
MSXML 4.0 SP2 Parser and SDK = 4.20.9818.0
Microsoft Visual C++ 2008 Redistributable - x86 9.0.30729.17 = 9.0.30729
VC9.0 SP0 Debug CRT DLLs = 1.0.0
Microsoft Visual C++ 2012 x86 Additional Runtime - 11.0.61030 = 11.0.61030
Microsoft Visual C++ 2012 x86 Minimum Runtime - 11.0.61030 = 11.0.61030
Microsoft Visual C++ 2010  x86 Redistributable - 10.0.40219 = 10.0.40219
ActivePerl 5.16.3 Build 1603 = 5.16.1603


i have created a powershellscript like  getinstalledlist.ps1 with above command and placed in facters.d folder. 

When i run puppet agent -t , i get the following error.

Error: Could not retrieve catalog from remote server: Error 400 on SERVER: Failed to parse inline template: `@7_zip_15_14 . 


Can someone help me to get this going?

Thanks & Regards,
Harish Kothuri

Jim

unread,
May 23, 2016, 10:07:08 PM5/23/16
to Puppet Users
Hi Harish,

I am new to powershell and would like t help you although I am new to puppet itself.

In your powershell command why are you looking for registry key 'Uninstall' should it be Installed?

Please advise.

Thanks
Jim

Jim

unread,
May 23, 2016, 11:05:43 PM5/23/16
to Puppet Users
Hi Harish,

I tried to do a simulation at my end and it might be because of syntax error. Please provide some feedback.

Regards,
Jim


On Tuesday, 24 May 2016 04:08:29 UTC+10, Harish Kothuri wrote:

John Ericson

unread,
May 31, 2016, 3:59:07 PM5/31/16
to Puppet Users
Hi Harish!

This fact looks really interesting. I'm interested in doing the same thing in my environment. Did you solve the problem? And if so, do you care to share your solution?

Regards,
John

Harish Kothuri

unread,
May 31, 2016, 11:18:51 PM5/31/16
to Puppet Users
Hello All,

Everything works fine after removing 7-Zip software. Looks like highphen (-) is having a problem in the name. You can also use regex to avoid those.

Thanks

Harish Kothuri

unread,
May 31, 2016, 11:21:40 PM5/31/16
to Puppet Users
Hi Jim,

As what i understand from the command and the registry in windows, Uninstall section list all software's which can be uninstalled - which is nothing but installed software's. 

-Harish

John Ericson

unread,
Jun 1, 2016, 12:31:21 PM6/1/16
to Puppet Users
Thanks for clarifying!

I changed it to include the regexp fix:

Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | where{$_.DisplayName -and $_.displayname -notmatch 'Update'} | Select-Object DisplayName, DisplayVersion | ForEach-Object {$factName = $_.DisplayName -replace '-', '_'; $version = $_.DisplayVersion; Write-Host $factName"="$version}
Reply all
Reply to author
Forward
0 new messages