Created
May 2, 2018 20:03
-
-
Save natemccurdy/1105ee9c1d75bf078a051f5993ea02d6 to your computer and use it in GitHub Desktop.
Windows PowerPlan management with Puppet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class win_power_settings ( | |
$power_setting = 'high_performance', | |
){ | |
case $power_setting { | |
'power_saver': { | |
$power_setto = 'a1841308-3541-4fab-bc81-f71556f20b4a' | |
} | |
'high_performance': { | |
$power_setto = '8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c' | |
} | |
'balanced': { | |
$power_setto = '381b4222-f694-41f0-9685-ff5bb260df2e' | |
} | |
default: { | |
fail( 'You have not chosen wisely; choose power_saver, high_performance, or balanced.' ) | |
} | |
} | |
if $facts['powerplan_name'] != $power_setto { | |
exec { 'set_power': | |
command => "PowerCfg -SetActive ${power_setto}", | |
provider => powershell, | |
logoutput => true, | |
path => $facts['path'], | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Facter.add('powerplan_name') do | |
confine :osfamily => 'windows' | |
setcode do | |
powershell = 'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe' | |
command = '(powercfg /GETACTIVESCHEME)' | |
# The output of the exec looks liks: | |
# Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced) | |
# | |
powerplan = Facter::Util::Resolution.exec(%Q{#{powershell} -command "#{command}"}).split(' ') | |
powerplan[4].tr('()', '') | |
end | |
end | |
Facter.add('powerplan_guid') do | |
confine :osfamily => 'windows' | |
setcode do | |
powershell = 'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe' | |
command = '(powercfg /GETACTIVESCHEME)' | |
# The output of the exec looks liks: | |
# Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced) | |
# | |
powerplan = Facter::Util::Resolution.exec(%Q{#{powershell} -command "#{command}"}).split(' ') | |
powerplan[3].to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment