Last active
February 8, 2021 16:46
-
-
Save natemccurdy/3c04f1583b4bb1acc257 to your computer and use it in GitHub Desktop.
Windows Pagefile management with Puppet
This file contains hidden or 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
# | |
# win_pagefile/manifests/init.pp | |
# | |
# Move pagefile to D: drive, reboot. | |
class win_pagefile ( | |
$pagefile_drive = 'd', | |
) { | |
if $::pagefile_location =~ '[Cc]\:' or $::pagefile_automanaged == true { | |
exec { 'pagefile': | |
command => template('win_pagefile/set_pagefile.ps1.erb'), | |
provider => powershell, | |
logoutput => false, | |
} | |
reboot { 'afterpagefile': | |
apply => immediately, | |
timeout => 5, | |
subscribe => Exec['pagefile'], | |
} | |
} | |
} |
This file contains hidden or 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
# | |
# win_pagefile/lib/facter/pagefile_automanaged.rb | |
# | |
Facter.add('pagefile_automanaged') do | |
confine :osfamily => "windows" | |
setcode do | |
powershell = 'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe' | |
command = '(Get-WmiObject Win32_computersystem -EnableAllPrivileges).AutomaticManagedPagefile' | |
value = Facter::Util::Resolution.exec(%Q{#{powershell} -command "#{command}"}) | |
if value == "True" | |
true | |
else | |
false | |
end | |
end | |
end |
This file contains hidden or 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
# | |
# win_pagefile/lib/facter/pagefile_location.rb | |
# | |
Facter.add('pagefile_location') do | |
confine :osfamily => "windows" | |
setcode do | |
powershell = 'C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe' | |
command = '(Get-WmiObject Win32_pagefilesetting -ComputerName .).name' | |
Facter::Util::Resolution.exec(%Q{#{powershell} -command "#{command}"}) | |
end | |
end |
This file contains hidden or 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
# | |
# win_pagefile/templates/set_pagefile.ps1.erb | |
# | |
$computer = Get-WmiObject Win32_computersystem -EnableAllPrivileges | |
$computer.AutomaticManagedPagefile = $false | |
$computer.Put() | |
$CurrentPageFile = Get-WmiObject -Query "select * from Win32_PageFileSetting where name='c:\\pagefile.sys'" | |
$CurrentPageFile.delete() | |
Set-WMIInstance -Class Win32_PageFileSetting -Arguments @{name="<%= @pagefile_drive %>:\pagefile.sys";InitialSize = 0; MaximumSize = 0} |
Author
natemccurdy
commented
Feb 8, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment