diff --git a/windows/2008r2.json b/windows/2008r2.json index 8b0ab5143..d661d423e 100644 --- a/windows/2008r2.json +++ b/windows/2008r2.json @@ -31,11 +31,23 @@ "install_command": "powershell.exe -Command \"(new-object Net.WebClient).DownloadString('https://omnitruck.chef.io/install.ps1') | iex; install\"", "run_list": [ "packer::vm_tools", - "packer::uninstall_powershell_ise", + "packer::features", "packer::enable_file_sharing", "packer::enable_remote_desktop", "packer::ui_tweaks", "packer::power", + "packer::updates" + ] + }, + { + "type": "windows-restart" + }, + { + "type": "chef-solo", + "cookbook_paths": ["cookbooks"], + "guest_os_type": "windows", + "install_command": "powershell.exe -Command \"(new-object Net.WebClient).DownloadString('https://omnitruck.chef.io/install.ps1') | iex; install\"", + "run_list": [ "packer::cleanup", "packer::defrag" ] diff --git a/windows/2012r2.json b/windows/2012r2.json index 61857f96a..1c38cf75d 100644 --- a/windows/2012r2.json +++ b/windows/2012r2.json @@ -30,7 +30,7 @@ "guest_os_type": "windows", "run_list": [ "packer::vm_tools", - "packer::uninstall_powershell_ise", + "packer::features", "packer::enable_file_sharing", "packer::enable_remote_desktop", "packer::ui_tweaks", diff --git a/windows/2016.json b/windows/2016.json index 87f95562d..aab76e685 100644 --- a/windows/2016.json +++ b/windows/2016.json @@ -30,7 +30,7 @@ "guest_os_type": "windows", "run_list": [ "packer::vm_tools", - "packer::uninstall_powershell_ise", + "packer::features", "packer::enable_file_sharing", "packer::enable_remote_desktop", "packer::ui_tweaks", diff --git a/windows/7.json b/windows/7.json index 30f96b53a..e644328ab 100644 --- a/windows/7.json +++ b/windows/7.json @@ -31,7 +31,7 @@ "install_command": "powershell.exe -Command \"(new-object Net.WebClient).DownloadString('https://omnitruck.chef.io/install.ps1') | iex; install\"", "run_list": [ "packer::vm_tools", - "packer::uninstall_powershell_ise", + "packer::features", "packer::enable_file_sharing", "packer::enable_remote_desktop", "packer::ui_tweaks", diff --git a/windows/cookbooks/packer/kitchen.yml b/windows/cookbooks/packer/kitchen.yml index e6efb0235..62ff53cb5 100644 --- a/windows/cookbooks/packer/kitchen.yml +++ b/windows/cookbooks/packer/kitchen.yml @@ -27,7 +27,7 @@ suites: - name: default run_list: - recipe[packer::vm_tools] - - recipe[packer::uninstall_powershell_ise] + - recipe[packer::features] - recipe[packer::enable_file_sharing] - recipe[packer::enable_remote_desktop] - recipe[packer::ui_tweaks] diff --git a/windows/cookbooks/packer/recipes/cleanup.rb b/windows/cookbooks/packer/recipes/cleanup.rb index 1bce5ec2d..e1cc92f70 100644 --- a/windows/cookbooks/packer/recipes/cleanup.rb +++ b/windows/cookbooks/packer/recipes/cleanup.rb @@ -16,7 +16,8 @@ "C:\\Recovery", "$env:localappdata\\temp\\*", "$env:windir\\logs", - "$env:windir\\winsxs\\manifestcache" + "$env:windir\\winsxs\\manifestcache", + "C:\\Users\\vagrant\Favorites\\*" ) | % { if(Test-Path $_) { Write-Host "Removing $_" @@ -30,6 +31,13 @@ EOH end +# clean all of the event logs +%w(Application Security Setup System).each do |log| + execute "Cleaning the #{log} event log" do + command "wevtutil clear-log #{log}" + end +end + # remove pagefile registry_key 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management' do values [{ diff --git a/windows/cookbooks/packer/recipes/features.rb b/windows/cookbooks/packer/recipes/features.rb new file mode 100644 index 000000000..b701d31fc --- /dev/null +++ b/windows/cookbooks/packer/recipes/features.rb @@ -0,0 +1,8 @@ +windows_feature 'NetFx3' do + action :install + only_if { node['platform_version'].to_f == 6.1 } +end + +windows_feature 'MicrosoftWindowsPowerShellISE' do + action :remove +end diff --git a/windows/cookbooks/packer/recipes/uninstall_powershell_ise.rb b/windows/cookbooks/packer/recipes/uninstall_powershell_ise.rb deleted file mode 100644 index 8fb9548e5..000000000 --- a/windows/cookbooks/packer/recipes/uninstall_powershell_ise.rb +++ /dev/null @@ -1,3 +0,0 @@ -windows_feature 'MicrosoftWindowsPowerShellISE' do - action :remove -end diff --git a/windows/cookbooks/packer/recipes/updates.rb b/windows/cookbooks/packer/recipes/updates.rb new file mode 100644 index 000000000..a7a0abad6 --- /dev/null +++ b/windows/cookbooks/packer/recipes/updates.rb @@ -0,0 +1,17 @@ +# Don't check for updates automatically. This needs to be configured before you can install updates +registry_key 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update' do + values [{ + name: 'AUOptions', + type: :dword, + data: 1, + }] +end + +if node['platform_version'].to_f == 6.1 # 2008R2 + + # This is basically a service pack and we should install it to fix a giant pile of bugs + msu_package '2018-05 monthly rollup' do + source 'http://download.windowsupdate.com/d/msdownload/update/software/secu/2018/05/windows6.1-kb4103718-x64_c051268978faef39e21863a95ea2452ecbc0936d.msu' + action :install + end +end diff --git a/windows/scripts/cleanup.ps1 b/windows/scripts/cleanup.ps1 index 00394b3ed..490e7c9d3 100644 --- a/windows/scripts/cleanup.ps1 +++ b/windows/scripts/cleanup.ps1 @@ -1,9 +1,13 @@ -Write-Host "Uninstall Chef..." +Write-Host "Uninstalling Chef..." if(Test-Path "c:\windows\temp\chef.msi") { Start-Process MSIEXEC.exe '/uninstall c:\windows\temp\chef.msi /quiet' -Wait } -Write-Host "Cleaning Temp Files" +Write-Host "Removing leftover Chef files..." +Remove-Item "C:\Opscode\" -Recurse -Force -ErrorAction SilentlyContinue +Remove-Item "C:\Chef\" -Recurse -Force -ErrorAction SilentlyContinue + +Write-Host "Cleaning Temp Files..." try { Takeown /d Y /R /f "C:\Windows\Temp\*" Icacls "C:\Windows\Temp\*" /GRANT:r administrators:F /T /c /q 2>&1 @@ -20,7 +24,7 @@ $ArraySize= 64kb $SpaceToLeave= $Volume.Size * 0.05 $FileSize= $Volume.FreeSpace - $SpacetoLeave $ZeroArray= new-object byte[]($ArraySize) - + $Stream= [io.File]::OpenWrite($FilePath) try { $CurFileSize = 0 @@ -34,5 +38,5 @@ finally { $Stream.Close() } } - + Remove-Item $FilePath