Help changing a power shell to Puppet types and providers

91 views
Skip to first unread message

Atse Tewodors

unread,
Jan 28, 2014, 9:18:57 PM1/28/14
to puppet...@googlegroups.com
Hi,

I am trying converting a powershell script to puppet and providers. I try to compile using https://downloads.puppetlabs.com/windows/puppet-3.0.2.msi but the code executed without windows update setting changed.

Powershell code -Works fine in powershell

$Updates = (New-Object -ComObject "Microsoft.Update.AutoUpdate").Settings
    
if ($Updates.ReadOnly -eq $True) { 
            $Updates.ReadOnly = False
            $Updates.NotificationLevel = 1 #Disabled
   $Updates.Save()
   $Updates.Refresh()
}

else {
$Updates.NotificationLevel = 1 #Disabled
$Updates.Save()
$Updates.Refresh()
}


but when i run the below command using https://downloads.puppetlabs.com/windows/puppet-3.0.2.msi --The Notification level not updated ???

a = %x[ powershell -command " & {($Updates = (New-Object -ComObject "Microsoft.Update.AutoUpdate").Settings.NotificationLevel)}" ]
b = %x[ powershell -command " & {($Updates = (New-Object -ComObject "Microsoft.Update.AutoUpdate").Settings.ReadOnly)}" ]


if b.delete("\n") != "False"
 
%x[ powershell -command " & {($Updates = (New-Object -ComObject "Microsoft.Update.AutoUpdate").Settings; $Updates.ReadOnly = False)}"]

end


if a.delete("\n").to_i != 1

%x[ powershell -command " - < {($Updates = (New-Object -ComObject "Microsoft.Update.AutoUpdate").Settings ; "$Updates.NotificationLevel = '$1'" -Force ; $Updates.save()}" ]

end


Any help is appreciated with the above or any other alternative




Rob Reynolds

unread,
Jan 29, 2014, 2:53:08 AM1/29/14
to puppet...@googlegroups.com
I think this might have to do with 32bit versus x64. 

Try opening an x86 PowerShell console and running the first set of code. 


--
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/106f4ce0-d641-49a6-a555-d1c2a8653d6a%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Rob Reynolds
Developer, Puppet Labs

Join us at PuppetConf 2014September 23-24 in San Francisco - http://bit.ly/pupconf14
Register now and save 40%! Offer expires January 31st.

Atse Tewodors

unread,
Jan 29, 2014, 10:47:52 AM1/29/14
to puppet...@googlegroups.com
The first set of commands run and my pb is when i tried to run the below commands as a .rb file using https://downloads.puppetlabs.com/windows/puppet-3.0.2.msi

a = %x[ powershell -command " & {($Updates = (New-Object -ComObject "Microsoft.Update.AutoUpdate").Settings.NotificationLevel)}" ]
b = %x[ powershell -command " & {($Updates = (New-Object -ComObject "Microsoft.Update.AutoUpdate").Settings.ReadOnly)}" ]


if b.delete("\n") != "False"
 
%x[ powershell -command " & {($Updates = (New-Object -ComObject "Microsoft.Update.AutoUpdate").Settings; $Updates.ReadOnly = False)}"]

end


if a.delete("\n").to_i != 1

%x[ powershell -command " - < {($Updates = (New-Object -ComObject "Microsoft.Update.AutoUpdate").Settings ; "$Updates.NotificationLevel = '$1'" -Force ; $Updates.save()}" ]

end



Any help is appreciated with the above or any other alternative to chnage the above to puppets types and providers

 

Rob Reynolds

unread,
Jan 29, 2014, 11:31:17 AM1/29/14
to puppet...@googlegroups.com
Hi, 
 I guess I wasn't really clear in my first email. I'm not sure the AutoUpdate would run in 32bit mode, which is what puppet/ruby runs under and your call to powershell will stay in 32 bit mode unless you use sysnative. You would need to find the x64 bit version of PowerShell (c:\\windows\\sysnative\\windowspowershell\\v1.0\\powershell.exe).

But first I was hoping to validate if the runtime is the issue. You can validate by taking what you said ran fine with straight PowerShell, opening an x86 version of PowerShell and trying to see if it works. Then move from there to the next step, which is what I mentioned above in getting to the proper runtime of powershell.



--
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.

For more options, visit https://groups.google.com/groups/opt_out.

Josh Cooper

unread,
Jan 29, 2014, 1:02:14 PM1/29/14
to puppet...@googlegroups.com
You might also want to try the autoupdate module on the forge: http://forge.puppetlabs.com/liamjbennett/windows_autoupdate

Josh



For more options, visit https://groups.google.com/groups/opt_out.



--
Josh Cooper

Atse Tewodors

unread,
Jan 30, 2014, 3:15:50 PM1/30/14
to puppet...@googlegroups.com
Due to the run time issue with puppet/ruby calling powershell windows update and i could nt be able to open the zip file http://forge.puppetlabs.com/liamjbennett/windows_autoupdate 

So I am using instead registry setting to disable the auto update, any suggestions for the below

 

confine :operatingsystem => "windows"

 

setcode do

reg_exe = "#{ENV['SystemRoot']}\\System32\\reg.exe"

#Disabling Autoupdate  

   begin 

 Facter::Util::Resolution::exec("#{reg_exe} ADD "HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU /v AutoUpdate /t  Reg_DWORD /d  1")     

   rescue Exception => e   

   puts e

   end

end

Josh Cooper

unread,
Feb 4, 2014, 12:53:26 AM2/4/14
to puppet...@googlegroups.com
On Thu, Jan 30, 2014 at 12:15 PM, Atse Tewodors <adugen...@gmail.com> wrote:
Due to the run time issue with puppet/ruby calling powershell windows update and i could nt be able to open the zip file http://forge.puppetlabs.com/liamjbennett/windows_autoupdate 

On your Windows host, type:

  C:\>puppet module install liamjbennett/windows_autoupdate

Alternatively you can issue the same command on the puppet master, and run the agent once (puppet agent -t) to pull those files down.

Then type:

   C:\>puppet apply -e "class { 'windows_autoupdate': noAutoUpdate => 1 }"


So I am using instead registry setting to disable the auto update, any suggestions for the below

 

confine :operatingsystem => "windows"

 

setcode do

reg_exe = "#{ENV['SystemRoot']}\\System32\\reg.exe"

#Disabling Autoupdate  

   begin 

 Facter::Util::Resolution::exec("#{reg_exe} ADD "HKEY_LOCAL_MACHINE\\SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate\\AU /v AutoUpdate /t  Reg_DWORD /d  1")     

   rescue Exception => e   

   puts e

   end

end

--
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.

For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages