gus9pw
Last Updated: February 25, 2016
·
1.479K
· jgemedina
9ceed3ede68b252b29127ddf840a36ef

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"
            }
      }
}
Say Thanks
Respond