Last Updated: February 25, 2016
·
3.178K
· jgemedina

Puppet Module to run a custom PowerShell script.

This Puppet Module will attempt to run a custom PowerShell script within a new PowerShell process in order to preserve the parent process privileges.

class webserverpostdeploymentscripts {
      if $osfamily == 'windows' {
            $wsrpsscriptfile = 'restart-website.ps1'
            $powershellexe = 'C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe'
            $wsrpsscriptpath = "C:/Windows/Temp/${wsrpsscriptfile}"

            file { 'restart-psscript':
                  path => $wsrpsscriptpath,
                  ensure => "file",
                  source => "puppet:///files/$wsrpsscriptfile"
            } ->
            exec { 'restart-website':
                  command => "start-process -verb runas $powershellexe -argumentlist '-file ${wsrpsscriptpath}'",
                  provider => "powershell"
            }
      }
}