Ask Your Question

Executing a batch file on Windows agent

asked 2015-09-30 05:34:03 -0500

michaelokoluko gravatar image

updated 2015-09-30 05:37:49 -0500


I need a bit of help running the download.bat file after the download.ps1has been dowloaded. What trigger/dependency do i require cmd.exe or powershell.exe? Below is my current manifest init.pp - I might need to reformat the "unless" and "command" attribute (?)

class downloadscript { file { 'C:\puppetfolder\download.ps1': ensure => present, source => 'puppet:///modules/downloadscript/download.ps1', mode => '0775', owner => 'Administrator', group => 'Administrator', } -> exec { 'Execute download.bat': path => 'c:\User\Administrator\Desktop\download.bat', command => 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -ExecutionPolicy RemoteSigned -File c:\User\Administrator\Desktop\download.bat', unless => 'c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe If (Test-Path C:\puppetfolder\download.ps1) { exit 1 } else {exit 0}', #refreshonly => true, logoutput => true, provider => powershell } }

I have attached a notepad of my code as the format here may not be readable

Many thanks in advance.

edit retag flag offensive close merge delete


Edit your question and use the formatting tools to format your question so that it's readable.

ramindk gravatar imageramindk ( 2015-09-30 12:50:59 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2015-10-14 02:38:31 -0500

joshc gravatar image

When using the powershell provider, the command parameter should be the powershell code to run, not the powershell.exe command to run, e.g.

exec { 'rename-guest':
  command => 'Get-WMIObject Win32_UserAccount ...',
  logoutput => true,
  provider => powershell

That said, it can be cumbersome to inline powershell in a single line, especially due to quotes and escaping. Alternatively you can wrap powershell code in a template:, and then reference the powershell code from the resource:

In Puppet 4, you can also inline powershell code in your manifest using HEREDOC syntax.

Finally since you're just trying to use powershell to download a file, you should look at one of the many modules on the forge for doing that, e.g. staging, pget, archive

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2015-09-30 05:34:03 -0500

Seen: 625 times

Last updated: Oct 14 '15