chocolatey / boxstarter

Repeatable, reboot resilient windows environment installations made easy using Chocolatey packages
https://boxstarter.org/
Apache License 2.0
1.31k stars 162 forks source link

Install-WindowsUpdate not working when run remotely #346

Open fernanqv opened 6 years ago

fernanqv commented 6 years ago

When I run Install-WindowsUpdate remotely using the command Install-BoxstarterPackage of boxstarter 2.11 I get the following error:

There were problems installing updates: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

For two years I've been using the version 2.6.25 of Boxstarter and updates were installed successfuly.

In order to debug the problem I've run the Install-BoxstarterPackage command locally in the remote machine with the version 2.11 installed by Boxstarter remotely (the one found in C:\Users\User\appdata\Local\temp) and it also works. The problem only arise when I run Install-BoxstarterPackage remotely.

Below you can find the output of the command I use to update the Servers remotely and after that the output when I run it locally (actualizaciones.txt only contains the following line "Install-WindowsUpdate -acceptEula")

PS C:\Windows\system32> Install-BoxstarterPackage -ComputerName dcinves03.unican.es -PackageName http://scom.unican.es/scripts/actualizaciones.txt
Boxstarter Version 2.11.0
(c) 2018 Chocolatey Software, Inc, 2012 - 2018 Matt Wrock. https://boxstarter.org

Boxstarter: Configuring local PowerShell Remoting settings...
Boxstarter: Configuring CredSSP settings...
Boxstarter: Testing remoting access on dcinves03.unican.es...
Boxstarter: Remoting is accessible on dcinves03.unican.es
Boxstarter: Copying Boxstarter Modules and LocalRepo packages at C:\ProgramData\Boxstarter to C:\Users\OP_REM~1\AppData\Local\Temp on dcinves03.unican.es...
Hit Line breakpoint on 'C:\ProgramData\Boxstarter\Boxstarter.Chocolatey\Install-BoxstarterPackage.ps1:643'
[DBG]: PS C:\Windows\system32>> 
Boxstarter: Running remote install...
[DBG]: PS C:\Windows\system32>> 
[DCINVES03]Boxstarter: Installing package http://scom.unican.es/scripts/actualizaciones.txt
[DCINVES03]Boxstarter: Disabling Automatic Updates from Windows Update
Attempting to build package from 'tmpDA70.tmp.nuspec'.
Successfully created package 'C:\Users\op_remotas\AppData\Local\Temp\Boxstarter\BuildPackages\tmpDA70.tmp.1.0.0.nupkg'
[DCINVES03]Boxstarter: Created a temporary package tmpDA70.tmp from http://scom.unican.es/scripts/actualizaciones.txt in C:\Users\op_remotas\AppData\Local\Temp\Boxsta
rter\BuildPackages
[DCINVES03]++ Boxstarter starting Calling Chocolatey to install tmpDA70.tmp. This may take several minutes to complete...
Installing the following packages:
tmpDA70.tmp
By installing you accept licenses for the packages.
[NuGet] Installing 'tmpDA70.tmp 1.0.0'.
[NuGet] Successfully installed 'tmpDA70.tmp 1.0.0'.

tmpDA70.tmp v1.0.0 (forced)
tmpda70.tmp package files install completed. Performing other installation steps.
+ Boxstarter starting Checking for updates...
There were problems installing updates: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
ERROR: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
The install of tmpda70.tmp was NOT successful.
Error while running 'C:\ProgramData\chocolatey\lib\tmpDA70.tmp\tools\ChocolateyInstall.ps1'.
 See log for details.

Chocolatey installed 0/1 packages. 1 packages failed.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).

Failures
 - tmpda70.tmp (exited -1) - Error while running 'C:\ProgramData\chocolatey\lib\tmpDA70.tmp\tools\ChocolateyInstall.ps1'.
 See log for details.
Chocolatey reported an unsuccessful exit code of -1. See C:\Users\op_remotas\AppData\Local\Boxstarter\boxstarter.log for details.
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,chocolatey
    + PSComputerName        : dcinves03.unican.es

[DCINVES03]++ Boxstarter finished Calling Chocolatey to install tmpDA70.tmp. This may take several minutes to complete... 00:00:09.3884155
[DCINVES03]Boxstarter: Restore Automatic Updates from Windows Update
[DBG]: PS C:\Windows\system32>> 

Errors       : {Chocolatey reported an unsuccessful exit code of -1. See C:\Users\op_remotas\AppData\Local\Boxstarter\boxstarter.log for details., Chocolatey 
               reported an unsuccessful exit code of -1. See C:\Users\op_remotas\AppData\Local\Boxstarter\boxstarter.log for details.}
ComputerName : dcinves03.unican.es
Completed    : True
FinishTime   : 9/17/2018 7:19:46 AM
StartTime    : 9/17/2018 7:19:15 AM

Boxstarter: Rolling back remoting settings changed by Boxstarter...

PS C:\Windows\system32> ipmo -force 'C:\Users\op_remotas\AppData\Local\Temp\boxstarter\Boxstarter.Chocolatey\Boxstarter.Chocolatey.psm1'
PS C:\Windows\system32> ipmo -force 'C:\Users\op_remotas\AppData\Local\Temp\boxstarter\BoxStarter.Common\Boxstarter.Common.psm1'
WARNING: The names of some imported commands from the module 'Boxstarter.Common' include unapproved verbs that might make them less discoverable. To find the commands with unappro
Verbose parameter. For a list of approved verbs, type Get-Verb.
PS C:\Windows\system32> Install-BoxstarterPackage http://scom.unican.es/scripts/actualizaciones.txt
Boxstarter: Installing package http://scom.unican.es/scripts/actualizaciones.txt
Boxstarter Version 2.11.0
(c) 2018 Chocolatey Software, Inc, 2012 - 2018 Matt Wrock. https://boxstarter.org

Boxstarter: Disabling Automatic Updates from Windows Update
Attempting to build package from 'tmpEE7B.tmp.nuspec'.
Successfully created package 'C:\Users\op_remotas\AppData\Local\Temp\boxstarter\BuildPackages\tmpEE7B.tmp.1.0.0.nupkg'
Boxstarter: Created a temporary package tmpEE7B.tmp from http://scom.unican.es/scripts/actualizaciones.txt in C:\Users\op_remotas\AppData\Local\Temp\boxstarter\BuildPackages
+ Boxstarter starting Calling Chocolatey to install tmpEE7B.tmp. This may take several minutes to complete...
Installing the following packages:
tmpEE7B.tmp
By installing you accept licenses for the packages.
[NuGet] Installing 'tmpEE7B.tmp 1.0.0'.
[NuGet] Successfully installed 'tmpEE7B.tmp 1.0.0'.

tmpEE7B.tmp v1.0.0 (forced)
tmpee7b.tmp package files install completed. Performing other installation steps.
+ Boxstarter starting Checking for updates...
+ Boxstarter starting Checking for updates...
Restarting windows update service
Restarting windows update service
+ Boxstarter finished Checking for updates... 00:00:09.8220862
+ Boxstarter finished Checking for updates... 00:00:09.8220862
1 Updates found
1 Updates found
+ Boxstarter starting Download of Definition Update for Windows Defender Antivirus - KB2267602 (Definition 1.275.1362.0)
+ Boxstarter starting Download of Definition Update for Windows Defender Antivirus - KB2267602 (Definition 1.275.1362.0)
+ Boxstarter finished Download of Definition Update for Windows Defender Antivirus - KB2267602 (Definition 1.275.1362.0) 00:00:03.0067770
+ Boxstarter finished Download of Definition Update for Windows Defender Antivirus - KB2267602 (Definition 1.275.1362.0) 00:00:03.0067770
+ Boxstarter starting Install 1 of 1 updates: Definition Update for Windows Defender Antivirus - KB2267602 (Definition 1.275.1362.0)
+ Boxstarter starting Install 1 of 1 updates: Definition Update for Windows Defender Antivirus - KB2267602 (Definition 1.275.1362.0)
+ Boxstarter finished Install 1 of 1 updates: Definition Update for Windows Defender Antivirus - KB2267602 (Definition 1.275.1362.0) 00:00:49.3957277
+ Boxstarter finished Install 1 of 1 updates: Definition Update for Windows Defender Antivirus - KB2267602 (Definition 1.275.1362.0) 00:00:49.3957277
 The install of tmpee7b.tmp was successful.
  Software install location not explicitly set, could be in package or
  default install location if installer.

Chocolatey installed 1/1 packages. 0 packages failed.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
+ Boxstarter finished Calling Chocolatey to install tmpEE7B.tmp. This may take several minutes to complete... 00:01:10.3152365
True
Boxstarter: Restore Automatic Updates from Windows Update

Errors       : {}
ComputerName : localhost
Completed    : True
FinishTime   : 17/09/2018 12:04:38
StartTime    : 17/09/2018 12:03:22
pauby commented 6 years ago

This might explain it - a known issue?

mwrock commented 6 years ago

Boxstarter will apply the updates via a scheduled task when running remotely so the usual winrm limitations don't apply. However I don't see the expected output here about starting the scheduled task. So something looks wrong there.

fernanqv commented 6 years ago

I have just realized that the boxstarter.zip I was copying to the remote computer was not the one downloaded from the boxstarter site but one created by me by compressing my local installation. I have used the zip downloaded from your website and it works ok.

Sorry for the inconvenience

fernanqv commented 6 years ago

I have repeated all the tests again and I've just realized that the problem I mentioned when running Install-WindowsUpdate in remote with Boxstarter 2.11.0 is real.

While trying to solve the problem I substituted the boxstarter.zip located in Boxstarter.Chocolatey with an old version (2.6.24) and then the remote Install-WindowsUpdate worked. If I use the boxstarter.zip provided by the installation it fails.

hoshsadiq commented 5 years ago

Got the same issue. Trying to run it using packer. Script I'm running:

$ErrorActionPreference = "Stop"
$DebugPreference = 2
$VerbosePreference = 2
$WarningPreference = 2

Write-Host "Running Windows Update"

Import-Module Boxstarter.WinConfig
Install-WindowsUpdate -acceptEula -SuppressReboots

Write-Host "Finished Windows Update"

and the output:

    amazon-ebs: #################################################################################
    amazon-ebs: ## C:\Temp\packer-scripts\004-Install-WindowsUpdates.ps1 -> Failed
    amazon-ebs: #################################################################################
    amazon-ebs: VERBOSE: Exporting function 'Confirm-Choice'.
    amazon-ebs: VERBOSE: Exporting function 'Create-BoxstarterTask'.
    amazon-ebs: VERBOSE: Exporting function 'Enter-Dotnet4'.
    amazon-ebs: VERBOSE: Exporting function 'Get-CurrentUser'.
    amazon-ebs: VERBOSE: Exporting function 'Get-HttpResource'.
    amazon-ebs: VERBOSE: Exporting function 'Get-IsMicrosoftUpdateEnabled'.
    amazon-ebs: VERBOSE: Exporting function 'Get-IsRemote'.
    amazon-ebs: VERBOSE: Exporting function 'Invoke-FromTask'.
    amazon-ebs: VERBOSE: Exporting function 'Invoke-RetriableScript'.
    amazon-ebs: VERBOSE: Exporting function 'Log-BoxStarterMessage'.
    amazon-ebs: VERBOSE: Exporting function 'Enter-BoxstarterLogable'.
    amazon-ebs: VERBOSE: Exporting function 'Out-BoxstarterLog'.
    amazon-ebs: VERBOSE: Exporting function 'Remove-BoxstarterError'.
    amazon-ebs: VERBOSE: Exporting function 'Remove-BoxstarterTask'.
    amazon-ebs: VERBOSE: Exporting function 'Start-TimedSection'.
    amazon-ebs: VERBOSE: Exporting function 'Stop-TimedSection'.
    amazon-ebs: VERBOSE: Exporting function 'Test-Admin'.
    amazon-ebs: VERBOSE: Exporting function 'Write-BoxstarterLogo'.
    amazon-ebs: VERBOSE: Exporting function 'Write-BoxstarterMessage'.
    amazon-ebs: VERBOSE: Loading module from path 'C:\ProgramData\Boxstarter\Boxstarter.Bootstrapper\Boxstarter.Bootstrapper.psd1'.
    amazon-ebs: VERBOSE: Loading module from path
    amazon-ebs: 'C:\ProgramData\Boxstarter\Boxstarter.Bootstrapper\..\Boxstarter.Common\Boxstarter.Common.psd1'.
    amazon-ebs: VERBOSE: Importing function 'Confirm-Choice'.
    amazon-ebs: VERBOSE: The 'Create-BoxstarterTask' command in the Boxstarter.Common' module was imported, but because its name does
    amazon-ebs: not include an approved verb, it might be difficult to find. The suggested alternative verbs are "New".
    amazon-ebs: VERBOSE: Importing function 'Create-BoxstarterTask'.
    amazon-ebs: VERBOSE: Importing function 'Enter-BoxstarterLogable'.
    amazon-ebs: VERBOSE: Importing function 'Enter-Dotnet4'.
    amazon-ebs: VERBOSE: Importing function 'Get-CurrentUser'.
    amazon-ebs: VERBOSE: Importing function 'Get-HttpResource'.
    amazon-ebs: VERBOSE: Importing function 'Get-IsMicrosoftUpdateEnabled'.
    amazon-ebs: VERBOSE: Importing function 'Get-IsRemote'.
    amazon-ebs: VERBOSE: Importing function 'Invoke-FromTask'.
    amazon-ebs: VERBOSE: Importing function 'Invoke-RetriableScript'.
    amazon-ebs: VERBOSE: The 'Log-BoxStarterMessage' command in the Boxstarter.Common' module was imported, but because its name does
    amazon-ebs: not include an approved verb, it might be difficult to find. For a list of approved verbs, type Get-Verb.
    amazon-ebs: VERBOSE: Importing function 'Log-BoxStarterMessage'.
    amazon-ebs: VERBOSE: Importing function 'Out-BoxstarterLog'.
    amazon-ebs: VERBOSE: Importing function 'Remove-BoxstarterError'.
    amazon-ebs: VERBOSE: Importing function 'Remove-BoxstarterTask'.
    amazon-ebs: VERBOSE: Importing function 'Start-TimedSection'.
    amazon-ebs: VERBOSE: Importing function 'Stop-TimedSection'.
    amazon-ebs: VERBOSE: Importing function 'Test-Admin'.
    amazon-ebs: VERBOSE: Importing function 'Write-BoxstarterLogo'.
    amazon-ebs: VERBOSE: Importing function 'Write-BoxstarterMessage'.
    amazon-ebs: VERBOSE: Loading module from path 'C:\ProgramData\Boxstarter\Boxstarter.Bootstrapper\./boxstarter.bootstrapper.psm1'.
    amazon-ebs: VERBOSE: Loading module from path 'C:\ProgramData\Boxstarter\Boxstarter.WinConfig\BoxStarter.WinConfig.psd1'.
    amazon-ebs: VERBOSE: Loading module from path
    amazon-ebs: 'C:\ProgramData\Boxstarter\Boxstarter.WinConfig\..\Boxstarter.Common\Boxstarter.Common.psd1'.
    amazon-ebs: VERBOSE: Importing function 'Confirm-Choice'.
    amazon-ebs: VERBOSE: The 'Create-BoxstarterTask' command in the Boxstarter.Common' module was imported, but because its name does
    amazon-ebs: not include an approved verb, it might be difficult to find. The suggested alternative verbs are "New".
    amazon-ebs: VERBOSE: Importing function 'Create-BoxstarterTask'.
    amazon-ebs: VERBOSE: Importing function 'Enter-BoxstarterLogable'.
    amazon-ebs: VERBOSE: Importing function 'Enter-Dotnet4'.
    amazon-ebs: VERBOSE: Importing function 'Get-CurrentUser'.
    amazon-ebs: VERBOSE: Importing function 'Get-HttpResource'.
    amazon-ebs: VERBOSE: Importing function 'Get-IsMicrosoftUpdateEnabled'.
    amazon-ebs: VERBOSE: Importing function 'Get-IsRemote'.
    amazon-ebs: VERBOSE: Importing function 'Invoke-FromTask'.
    amazon-ebs: VERBOSE: Importing function 'Invoke-RetriableScript'.
    amazon-ebs: VERBOSE: The 'Log-BoxStarterMessage' command in the Boxstarter.Common' module was imported, but because its name does
    amazon-ebs: not include an approved verb, it might be difficult to find. For a list of approved verbs, type Get-Verb.
    amazon-ebs: VERBOSE: Importing function 'Log-BoxStarterMessage'.
    amazon-ebs: VERBOSE: Importing function 'Out-BoxstarterLog'.
    amazon-ebs: VERBOSE: Importing function 'Remove-BoxstarterError'.
    amazon-ebs: VERBOSE: Importing function 'Remove-BoxstarterTask'.
    amazon-ebs: VERBOSE: Importing function 'Start-TimedSection'.
    amazon-ebs: VERBOSE: Importing function 'Stop-TimedSection'.
    amazon-ebs: VERBOSE: Importing function 'Test-Admin'.
    amazon-ebs: VERBOSE: Importing function 'Write-BoxstarterLogo'.
    amazon-ebs: VERBOSE: Importing function 'Write-BoxstarterMessage'.
    amazon-ebs: VERBOSE: Loading module from path 'C:\ProgramData\Boxstarter\Boxstarter.WinConfig\./boxstarter.WinConfig.psm1'.
    amazon-ebs: VERBOSE: Exporting function 'Disable-BingSearch'.
    amazon-ebs: VERBOSE: Exporting function 'Disable-GameBarTips'.
    amazon-ebs: VERBOSE: Exporting function 'Disable-InternetExplorerESC'.
    amazon-ebs: VERBOSE: Exporting function 'Disable-MicrosoftUpdate'.
    amazon-ebs: VERBOSE: Exporting function 'Disable-UAC'.
    amazon-ebs: VERBOSE: Exporting function 'Enable-MicrosoftUpdate'.
    amazon-ebs: VERBOSE: Exporting function 'Enable-RemoteDesktop'.
    amazon-ebs: VERBOSE: Exporting function 'Enable-UAC'.
    amazon-ebs: VERBOSE: Exporting function 'Get-LibraryNames'.
    amazon-ebs: VERBOSE: Exporting function 'Get-UAC'.
    amazon-ebs: VERBOSE: Exporting function 'Install-WindowsUpdate'.
    amazon-ebs: VERBOSE: Exporting function 'Move-LibraryDirectory'.
    amazon-ebs: VERBOSE: Exporting function 'Set-CornerNavigationOptions'.
    amazon-ebs: VERBOSE: Exporting function 'Set-ExplorerOptions'.
    amazon-ebs: VERBOSE: Exporting function 'Set-StartScreenOptions'.
    amazon-ebs: VERBOSE: Exporting function 'Set-TaskbarOptions'.
    amazon-ebs: VERBOSE: Exporting function 'Set-TaskbarSmall'.
    amazon-ebs: VERBOSE: Exporting function 'Set-WindowsExplorerOptions'.
    amazon-ebs: VERBOSE: Exporting function 'Update-ExecutionPolicy'.
    amazon-ebs: VERBOSE: Importing function 'Disable-BingSearch'.
    amazon-ebs: VERBOSE: Importing function 'Disable-GameBarTips'.
    amazon-ebs: VERBOSE: Importing function 'Disable-InternetExplorerESC'.
    amazon-ebs: VERBOSE: Importing function 'Disable-MicrosoftUpdate'.
    amazon-ebs: VERBOSE: Importing function 'Disable-UAC'.
    amazon-ebs: VERBOSE: Importing function 'Enable-MicrosoftUpdate'.
    amazon-ebs: VERBOSE: Importing function 'Enable-RemoteDesktop'.
    amazon-ebs: VERBOSE: Importing function 'Enable-UAC'.
    amazon-ebs: VERBOSE: Importing function 'Get-LibraryNames'.
    amazon-ebs: VERBOSE: Importing function 'Get-UAC'.
    amazon-ebs: VERBOSE: Importing function 'Install-WindowsUpdate'.
    amazon-ebs: VERBOSE: Importing function 'Move-LibraryDirectory'.
    amazon-ebs: VERBOSE: Importing function 'Set-CornerNavigationOptions'.
    amazon-ebs: VERBOSE: Importing function 'Set-ExplorerOptions'.
    amazon-ebs: VERBOSE: Importing function 'Set-StartScreenOptions'.
    amazon-ebs: VERBOSE: Importing function 'Set-TaskbarOptions'.
    amazon-ebs: VERBOSE: Importing function 'Set-TaskbarSmall'.
    amazon-ebs: VERBOSE: Importing function 'Set-WindowsExplorerOptions'.
    amazon-ebs: VERBOSE: Importing function 'Update-ExecutionPolicy'.
    amazon-ebs: VERBOSE: Exporting function 'Enter-BoxstarterLogable'.
    amazon-ebs: VERBOSE: Exporting function 'Start-TimedSection'.
    amazon-ebs: VERBOSE: Exporting function 'Stop-TimedSection'.
    amazon-ebs: VERBOSE: Exporting function 'Write-BoxstarterMessage'.
    amazon-ebs: VERBOSE: Exporting function 'Get-BoxstarterTempDir'.
    amazon-ebs: VERBOSE: Exporting function 'Invoke-BoxStarter'.
    amazon-ebs: VERBOSE: Exporting function 'Invoke-Reboot'.
    amazon-ebs: VERBOSE: Exporting function 'Test-PendingReboot'.
    amazon-ebs: VERBOSE: Importing function 'Enter-BoxstarterLogable'.
    amazon-ebs: VERBOSE: Importing function 'Get-BoxstarterTempDir'.
    amazon-ebs: VERBOSE: Importing function 'Invoke-BoxStarter'.
    amazon-ebs: VERBOSE: Importing function 'Invoke-Reboot'.
    amazon-ebs: VERBOSE: Importing function 'Start-TimedSection'.
    amazon-ebs: VERBOSE: Importing function 'Stop-TimedSection'.
    amazon-ebs: VERBOSE: Importing function 'Test-PendingReboot'.
    amazon-ebs: VERBOSE: Importing function 'Write-BoxstarterMessage'.
    amazon-ebs: DEBUG:
    amazon-ebs: public class BoxstarterConnectionConfig {
    amazon-ebs:     public BoxstarterConnectionConfig(System.Uri connectionURI, System.Management.Automation.PSCredential credential,
    amazon-ebs: System.Management.Automation.Remoting.PSSessionOption psSessionOption) {
    amazon-ebs:         ConnectionURI=connectionURI;
    amazon-ebs:         Credential=credential;
    amazon-ebs:         PSSessionOption=psSessionOption;
    amazon-ebs:     }
    amazon-ebs:     public System.Uri ConnectionURI;
    amazon-ebs:     public System.Management.Automation.PSCredential Credential;
    amazon-ebs:     public System.Management.Automation.Remoting.PSSessionOption PSSessionOption;
    amazon-ebs: }
    amazon-ebs: VERBOSE: Exporting function 'Install-ChocolateyInstallPackageOverride'.
    amazon-ebs: VERBOSE: Exporting function 'Write-HostOverride'.
    amazon-ebs: VERBOSE: Exporting function 'Export-BoxstarterVars'.
    amazon-ebs: VERBOSE: Exporting function 'Enable-BoxstarterClientRemoting'.
    amazon-ebs: VERBOSE: Exporting function 'Enable-BoxstarterCredSSP'.
    amazon-ebs: VERBOSE: Exporting function 'Get-BoxStarterConfig'.
    amazon-ebs: VERBOSE: Exporting function 'Get-PackageRoot'.
    amazon-ebs: VERBOSE: Exporting function 'Install-BoxstarterPackage'.
    amazon-ebs: VERBOSE: Exporting function 'Invoke-BoxStarterBuild'.
    amazon-ebs: VERBOSE: Exporting function 'Invoke-BoxstarterFromTask'.
    amazon-ebs: VERBOSE: Exporting function 'Invoke-Chocolatey'.
    amazon-ebs: VERBOSE: Exporting function 'Invoke-ChocolateyBoxstarter'.
    amazon-ebs: VERBOSE: Exporting function 'New-BoxstarterPackage'.
    amazon-ebs: VERBOSE: Exporting function 'New-PackageFromScript'.
    amazon-ebs: VERBOSE: Exporting function 'Resolve-VMPlugin'.
    amazon-ebs: VERBOSE: Exporting function 'Set-BoxStarterConfig'.
    amazon-ebs: VERBOSE: Exporting function 'Set-BoxstarterShare'.
    amazon-ebs: VERBOSE: Exporting alias 'Install-ChocolateyInstallPackage'.
    amazon-ebs: VERBOSE: Exporting alias 'Write-Host'.
    amazon-ebs: VERBOSE: Exporting alias 'Enable-BoxstarterVM'.
    amazon-ebs: Running Windows Update
    amazon-ebs: VERBOSE: Loading module from path 'C:\ProgramData\Boxstarter\Boxstarter.WinConfig\Boxstarter.WinConfig.psd1'.
    amazon-ebs: VERBOSE: Importing function 'Disable-BingSearch'.
    amazon-ebs: VERBOSE: Importing function 'Disable-GameBarTips'.
    amazon-ebs: VERBOSE: Importing function 'Disable-InternetExplorerESC'.
    amazon-ebs: VERBOSE: Importing function 'Disable-MicrosoftUpdate'.
    amazon-ebs: VERBOSE: Importing function 'Disable-UAC'.
    amazon-ebs: VERBOSE: Importing function 'Enable-MicrosoftUpdate'.
    amazon-ebs: VERBOSE: Importing function 'Enable-RemoteDesktop'.
    amazon-ebs: VERBOSE: Importing function 'Enable-UAC'.
    amazon-ebs: VERBOSE: Importing function 'Get-LibraryNames'.
    amazon-ebs: VERBOSE: Importing function 'Get-UAC'.
    amazon-ebs: VERBOSE: Importing function 'Install-WindowsUpdate'.
    amazon-ebs: VERBOSE: Importing function 'Move-LibraryDirectory'.
    amazon-ebs: VERBOSE: Importing function 'Set-CornerNavigationOptions'.
    amazon-ebs: VERBOSE: Importing function 'Set-ExplorerOptions'.
    amazon-ebs: VERBOSE: Importing function 'Set-StartScreenOptions'.
    amazon-ebs: VERBOSE: Importing function 'Set-TaskbarOptions'.
    amazon-ebs: VERBOSE: Importing function 'Set-TaskbarSmall'.
    amazon-ebs: VERBOSE: Importing function 'Set-WindowsExplorerOptions'.
    amazon-ebs: VERBOSE: Importing function 'Update-ExecutionPolicy'.
    amazon-ebs: VERBOSE: [EC2AMAZ-TIJA998]Boxstarter: Invoking Import-Module
    amazon-ebs: C:\ProgramData\Boxstarter\boxstarter.WinConfig\Boxstarter.Winconfig.psd1
    amazon-ebs: Install-WindowsUpdate -GetUpdatesFromMS:$False -AcceptEula:$True -SuppressReboots -Criteria "IsHidden=0 and
    amazon-ebs: IsInstalled=0 and Type='Software' and BrowseOnly=0" in scheduled task
    amazon-ebs: VERBOSE: [EC2AMAZ-TIJA998]Boxstarter: Found 0 tasks already running

After this it simply exits with a non-zero value which means packer stops and cleans up image.

s-frostick commented 5 years ago

Seeing the same issue with 2.12.0 (Windows 10 LTSC)

The test for Get-IsRemote (https://github.com/chocolatey/boxstarter/blob/master/Boxstarter.WinConfig/Install-WindowsUpdate.ps1) is failing.

If i set it to

 if($true){
        Invoke-FromTask @"
Import-Module $($boxstarter.BaseDir)\boxstarter.WinConfig\Boxstarter.Winconfig.psd1
Install-WindowsUpdate -GetUpdatesFromMS:`$$GetUpdatesFromMS -AcceptEula:`$$AcceptEula -SuppressReboots -Criteria "$Criteria"
"@ -IdleTimeout 0 -TotalTimeout 0
        if(Test-PendingReboot){
            Invoke-Reboot
        }
        return
    }

Then things proceed.

s-frostick commented 5 years ago

So for me it appears that the failure is happening here

https://github.com/chocolatey/boxstarter/blob/4c8c3500b8676755eba054530dbb33af4b9a6d3d/BoxStarter.Common/Get-IsRemote.ps1#L15

The environment variable env:IsRemote is False so the the Invoke-FromTask is not called and the access denied exception happens.

Is there any more information on this environment variable ? I did a grep through the zip ( (C:\ProgramData\Boxstarter\Boxstarter.Chocolatey\Boxstarter.zip) that gets transferred to the remote machine but i cant see where it would be set.

./BoxStarter.Common/Get-IsRemote.ps1:13: if($env:IsRemote -ne $null) { return [bool]::Parse($env:IsRemote) } ./BoxStarter.Common/Get-IsRemote.ps1:16: $env:IsRemote = Test-ChildOfWinrs ./BoxStarter.Common/Get-IsRemote.ps1:17: return [bool]::Parse($env:IsRemote)

The only time It seems to get set is here

https://github.com/chocolatey/boxstarter/blob/4c8c3500b8676755eba054530dbb33af4b9a6d3d/BoxStarter.Common/Get-IsRemote.ps1#L18

but that block is not called. If i force it by falsifying the if above it then returns here.

https://github.com/chocolatey/boxstarter/blob/4c8c3500b8676755eba054530dbb33af4b9a6d3d/BoxStarter.Common/Get-IsRemote.ps1#L39

s-frostick commented 5 years ago

So finally got it to run, the fix i currently have is i have added another check in the Get-IsRemote script which seems to work.

if((Get-Host).Name -eq "Chocolatey_PSHost") {return $true}
if($PSSenderInfo -ne $null) {return $true}
if($PowershellRemoting) {return $false}

There is however another failure which seems to be caused by a change in the value of $env:temp variable at different points.

https://github.com/chocolatey/boxstarter/blob/4c8c3500b8676755eba054530dbb33af4b9a6d3d/BoxStarter.Common/Create-BoxstarterTask.ps1#L27

The $env:temp variable here seems to point to C:\Users\USERNAME\AppData\Local\Temp\BoxstarterTask.ps1

However in Invoke-FromTask

https://github.com/chocolatey/boxstarter/blob/4c8c3500b8676755eba054530dbb33af4b9a6d3d/BoxStarter.Common/Invoke-FromTask.ps1#L124

It is now pointing at C:\Users\USERNAME\AppData\Local\Temp\chocolatey\chocolatey ( this is where the BoxstarterTask.ps1 script ends up) so when the scheduled task runs it can't find the file and the process just hangs.

For the moment i just changed the path in Create-BoxstarterTask.ps1 #L27 and #L45 to $home\AppData\Local\Temp\chocolatey\chocolatey\BoxstarterTask.ps1 and below is the final result of a successful run.

 Install-BoxstarterPackage -ComputerName COMPUTER -PackageName https://gistlocation/boxstarter.txt
-Credential $cred -Verbose

...

VERBOSE: VERBOSE: [COMPUTER]Boxstarter: Invoking Import-Module
C:\Users\USERNAME\AppData\Local\Temp\Boxstarter\boxstarter.WinConfig\Boxstarter.Winconfig.psd1
Install-WindowsUpdate -GetUpdatesFromMS:$False -AcceptEula:$True -SuppressReboots -Criteria "IsHidden=0 and
IsInstalled=0 and Type='Software' and BrowseOnly=0" in scheduled task
VERBOSE: VERBOSE: [COMPUTER]Boxstarter: Found 0 tasks already running
VERBOSE: VERBOSE: [COMPUTER]Boxstarter: Launched task. Waiting for task to launch command...
VERBOSE: VERBOSE: [COMPUTER]Boxstarter: Command launched in process 360
VERBOSE: VERBOSE: [COMPUTER]Boxstarter: Waiting on 360
+ Boxstarter starting Checking for updates...

Restarting windows update service

+ Boxstarter finished Checking for updates... 00:00:11.2189705
1 Updates found

+ Boxstarter starting Download of 2018-10 Update for Windows 10 Version 1607 for x64-based Systems (
KB4091664)

+ Boxstarter finished Download of 2018-10 Update for Windows 10 Version 1607 for x64-based Systems (
KB4091664) 00:04:58.8955007
+ Boxstarter starting Install 1 of 1 updates: 2018-10 Update for Windows
 10 Version 1607 for x64-based Systems (KB4091664)

VERBOSE: VERBOSE: [COMPUTER]Boxstarter: Proc has exited: True or Is Null: False
+ Boxstarter finished Install 1 of 1 updates: 2018-10 Update for Windows 10 Version 1607 for x64-based Systems (KB4091664) 00:00:04.7242964
A Restart is Required.

....

Chocolatey installed 1/1 packages. 0 packages failed.
 See the log for details (C:\ProgramData\chocolatey\logs\chocolatey.log).
VERBOSE: [COMPUTER]Boxstarter: restoring current directory location to C:\WINDOWS\system32
VERBOSE: [COMPUTER]Boxstarter: Exit Code: 0
[COMPUTER]++ Boxstarter finished Calling Chocolatey to install tmp6279.tmp. This may take several minutes to complete... 00:00:50.0543465
VERBOSE: [COMPUTER]Boxstarter: Removing Boxstarter Scheduled Task...
VERBOSE: [COMPUTER]Boxstarter: Removed Boxstarter Scheduled Task with this result: SUCCESS: The scheduled task
"Boxstarter Task" was successfully deleted.
[COMPUTER]Boxstarter: Restore Automatic Updates from Windows Update
VERBOSE: [COMPUTER]Boxstarter: Cleaning up and not rebooting
VERBOSE: [COMPUTER]+ Boxstarter finished Installation session. 00:01:06.4881537
VERBOSE: Boxstarter: Result from Remote Boxstarter:  Completed
VERBOSE: Boxstarter: checking if session should be removed...
VERBOSE: Boxstarter: Removing session 50...
VERBOSE: Boxstarter: Session removed...
VERBOSE: Boxstarter: Composing record for pipeline...
VERBOSE: Boxstarter: writing object...

Errors       : {}
ComputerName : computer
Completed    : True
FinishTime   : 11/01/2019 13:33:21
StartTime    : 11/01/2019 13:19:30

VERBOSE: Boxstarter: object written...
Boxstarter: Rolling back remoting settings changed by Boxstarter...
VERBOSE: Boxstarter: Reseting CredSSP Trusted Hosts to computer
VERBOSE: Boxstarter: Reseting GroupPolicy for Credentials Delegation
wspait commented 5 years ago

We can also confirm that this is definately an issue. The workarounds above to try to fix the issue within boxstarter will break Boxstarter in other ways. We worked aroud it for now by making a package that kicks off install-windowsupdate via a schedulled task. but this approach has obvious drawbacks, first being that it is bypassing all of the logic that is already built into boxstarter... Do we know if anyone is looking at this or working on it? Thanks

renehernandez commented 5 years ago

@pauby I would like to try tackling this issue. I noticed that there are not issues labeled as good first issue. Would this one be a good first issue candidate?

pauby commented 5 years ago

@renehernandez We don't have a label for good first issue but instead use up for grabs. But this would be a good issue to work on. Whether it's a good first issue only you can decide :smile:

shealfox commented 5 years ago

I was trying to use Boxstarter when I ran into this same issue. Does anyone know if it was ever fixed? Is this still being worked on ?

mattnewport commented 3 years ago

I'm hitting this issue as well when trying to update an Azure VM remotely. Any updates on this one?