Whilst your question is old, I thought I'd give my workaround as windows updates and packer were some of the bains of my life, I've tried various scripts to varying degrees of success.
In the end I came across the following provisioner and it's taken all my pain away, working every time without fail. https://github.com/rgl/packer-provisioner-windows-update On Sunday, 20 August 2017 21:15:59 UTC+1, [email protected] wrote: > > Hi everyone > > I am trying to get the famous windows updates working in 2012. for 2012r2, > all went fine, just installed some power shell libraries I found and ran > this: > > "type": "powershell", > "elevated_user": "vagrant", > "elevated_password": "vagrant", > "pause_before": "10m", > "inline": [ > "get-wuinstall -WindowsUpdate -AcceptAll -IgnoreReboot -Verbose" > ] > }, > > - all worked fine, fully tested. > > Tried on 2012, thought it would be fine - indeed not. after a LOT of > faffing about it, it turns out the scheduled task that is created is too > big for windows to run it, it just says the scheduled task no longer > exists. If you look at the actual task the string it runs is a massive > string of base 64 (don't know why but I am sure there is a reason!) - > decode this and it's a massive string of variables followed by a path to > the actual power shell... It turns out, if I half the base 64, windows > let's it run - so the issue seems to be the length of the code in the > scheduled task. Can't find anything about this being a a known issue. > > Anyway... > > I want to try and make that is base 64 encoded shorter, as to make it run, > the base 64 encoded strings is currently " Uploading elevated shell wrapper > for command [if (Test-Path > variable:global:ProgressPreference){$ProgressPreference='SilentlyContinue'};$env:PACKER_BUILDER_TYPE="vmware-iso"; > > $env:PACKER_BUILD_NAME="vmware-iso"; $env:PACKER_HTTP_ADDR=" > 192.168.100.65:8000"; &'c:/a/1.ps1';exit $LastExitCode]" - which is > obviously long, I want to take out all of the variables, I have tried > running execute command but this doesn't seem to do a thing, as below > produced the former: > > { > "type": "powershell", > "elevated_user": "vagrant", > "elevated_password": "vagrant", > "remote_path": "c:/a/1.ps1", > "execute_command": "TEST", > "scripts": [ > "./scripts/windows-update-all.ps1" > ] > } > > I have tried to make things as short as possible, hence the c:/a/1.ps1. > This is really annoying because it's a really eligantt solution for 20212r2 > but just doesn't work in 2012, anyone know of this, or has any ideas how I > can troubleshoot it? > > > below is the last bit of code from a run, packer is version 1.0.4 > > many thanks > > ==> vmware-iso: Provisioning with Powershell... > 2017/08/20 12:46:47 ui: ==> vmware-iso: Provisioning with Powershell... > 2017/08/20 12:46:47 ui: ==> vmware-iso: Provisioning with shell script: > ./scripts/windows-update-all.ps1 > ==> vmware-iso: Provisioning with shell script: > ./scripts/windows-update-all.ps1 > 2017/08/20 12:46:47 packer: 2017/08/20 12:46:47 Opening > ./scripts/windows-update-all.ps1 for reading > 2017/08/20 12:46:47 packer: 2017/08/20 12:46:47 Building elevated command > wrapper for: if (Test-Path > variable:global:ProgressPreference){$ProgressPreference='SilentlyContinue'};$env:PACKER_BUILDER_TYPE="vmware-iso"; > > $env:PACKER_BUILD_NAME="vmware-iso"; $env:PACKER_HTTP_ADDR=" > 192.168.100.65:8000"; &'c:/a/1.ps1';exit $LastExitCode > 2017/08/20 12:46:47 packer: 2017/08/20 12:46:47 Uploading elevated shell > wrapper for command [if (Test-Path > variable:global:ProgressPreference){$ProgressPreference='SilentlyContinue'};$env:PACKER_BUILDER_TYPE="vmware-iso"; > > $env:PACKER_BUILD_NAME="vmware-iso"; $env:PACKER_HTTP_ADDR=" > 192.168.100.65:8000"; &'c:/a/1.ps1';exit $LastExitCode] to > [${env:TEMP}\packer-elevated-shell-5999e727-ddcf-e4d7-2216-cee952a4992d.ps1] > from [/tmp/packer-elevated-shell.ps1791211094] > 2017/08/20 12:46:47 packer: 2017/08/20 12:46:47 [INFO] 3016 bytes written > for 'uploadData' > 2017/08/20 12:46:47 [INFO] 3016 bytes written for 'uploadData' > 2017/08/20 12:46:47 packer: 2017/08/20 12:46:47 Uploading file to > '${env:TEMP}\packer-elevated-shell-5999e727-ddcf-e4d7-2216-cee952a4992d.ps1' > 2017/08/20 12:46:48 packer: 2017/08/20 12:46:48 [INFO] 63 bytes written > for 'uploadData' > 2017/08/20 12:46:48 [INFO] 63 bytes written for 'uploadData' > 2017/08/20 12:46:48 packer: 2017/08/20 12:46:48 Uploading file to > 'c:/a/1.ps1' > 2017/08/20 12:46:49 packer: 2017/08/20 12:46:49 [INFO] starting remote > command: powershell -executionpolicy bypass -file > "%TEMP%\packer-elevated-shell-5999e727-ddcf-e4d7-2216-cee952a4992d.ps1" > vmware-iso: Exception calling "Run" with "1" argument(s): "Could not > load file or assembly > 2017/08/20 12:46:50 ui: vmware-iso: Exception calling "Run" with "1" > argument(s): "Could not load file or assembly > vmware-iso: 'Microsoft.PowerShell.Commands.Management' or one of its > dependencies. The > 2017/08/20 12:46:50 ui: vmware-iso: > 'Microsoft.PowerShell.Commands.Management' or one of its dependencies. The > 2017/08/20 12:46:50 ui: vmware-iso: system cannot find the file > specified." > vmware-iso: system cannot find the file specified." > vmware-iso: At > C:\Users\vagrant\AppData\Local\Temp\packer-elevated-shell-5999e727-ddcf-e4d7 > 2017/08/20 12:46:50 ui: vmware-iso: At > C:\Users\vagrant\AppData\Local\Temp\packer-elevated-shell-5999e727-ddcf-e4d7 > 2017/08/20 12:46:50 ui: vmware-iso: -2216-cee952a4992d.ps1:51 char:1 > vmware-iso: -2216-cee952a4992d.ps1:51 char:1 > 2017/08/20 12:46:50 ui: vmware-iso: + $t.Run($null) | Out-Null > vmware-iso: + $t.Run($null) | Out-Null > 2017/08/20 12:46:50 ui: vmware-iso: + ~~~~~~~~~~~~~~~~~~~~~~~~ > vmware-iso: + ~~~~~~~~~~~~~~~~~~~~~~~~ > 2017/08/20 12:46:50 ui: vmware-iso: + CategoryInfo : > NotSpecified: (:) [], MethodInvocationException > vmware-iso: + CategoryInfo : NotSpecified: (:) [], > MethodInvocationException > 2017/08/20 12:46:50 ui: vmware-iso: + FullyQualifiedErrorId : > ComMethodTargetInvocation > vmware-iso: + FullyQualifiedErrorId : ComMethodTargetInvocation > vmware-iso: > 2017/08/20 12:46:50 ui: vmware-iso: > 2017/08/20 12:47:00 packer: 2017/08/20 12:47:00 [INFO] command 'powershell > -executionpolicy bypass -file > "%TEMP%\packer-elevated-shell-5999e727-ddcf-e4d7-2216-cee952a4992d.ps1"' > exited with code: 1 > 2017/08/20 12:47:00 packer: 2017/08/20 12:47:00 [INFO] RPC endpoint: > Communicator ended with: 1 > 2017/08/20 12:47:00 [INFO] 509 bytes written for 'stderr' > 2017/08/20 12:47:00 [INFO] 0 bytes written for 'stdout' > 2017/08/20 12:47:00 [INFO] RPC client: Communicator ended with: 1 > 2017/08/20 12:47:00 [INFO] RPC endpoint: Communicator ended with: 1 > > > > > -- This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list. GitHub Issues: https://github.com/mitchellh/packer/issues IRC: #packer-tool on Freenode --- You received this message because you are subscribed to the Google Groups "Packer" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/f2b9c8e0-ca8b-44d1-b10e-90ab260a6ca3%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
