Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

Expand-Archive ignores ProgressPreference = 'SilentlyContinue' and fails over SSH #77

Open
dzmitry-lahoda opened this issue Jul 3, 2019 · 5 comments
Milestone

Comments

@dzmitry-lahoda
Copy link

dzmitry-lahoda commented Jul 3, 2019

  1. Install client of open ssh on windows https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse

  2. install server on windows https://docs.microsoft.com/en-us/windows-server/administration/openssh/openssh_install_firstuse

  3. Run script which expands archive over SSH:

. $PSScriptRoot/variables.ps1

$archiveVersion = $MONGO_VERSION
$download = "http://fastdl.mongodb.org/win32/$($archiveVersion).zip"
$runtimeFolder = "mongo"
$pathToExe = "$($FOOBAR_RUNTIME)$($runtimeFolder)/$($archiveVersion)/bin/mongod.exe"

$runtimeExecutable = Test-Path $pathToExe

if ($runtimeExecutable -ne 'True') {
  Write-Host "No executable deployed at $($pathToExe). Will deploy."
  if (!(Test-Path $FOOBAR_TEMP)) {
    New-Item -ItemType Directory -Path $FOOBAR_TEMP
  }

  if (!(Test-Path "$($FOOBAR_RUNTIME)$($runtimeFolder)/")) {
    New-Item -ItemType Directory -Path "$($FOOBAR_RUNTIME)$($runtimeFolder)/"
  }
  
  # TODO if SSH and cannot show progress
  # https://social.technet.microsoft.com/Forums/en-US/32063c17-8375-4511-86ea-b80cf3f02433/how-to-disable-invokewebrequest-progressstatus-bar-when-testing-cas-services
  $ProgressPreference = 'SilentlyContinue'  

  if (!(Test-Path "$($FOOBAR_TEMP)$($archiveVersion).zip")) {
      Write-Host "Will download $($download)"
      [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
      Invoke-WebRequest -Uri $download -OutFile "$($FOOBAR_TEMP)$($archiveVersion).zip"
      # TODO: check SHA
  }
  
  $unpacked = "$($FOOBAR_TEMP)$($archiveVersion).zip"
  Write-Host "Will unpack into $($unpacked)"
  Expand-Archive -Path $unpacked -DestinationPath "$($FOOBAR_RUNTIME)$($runtimeFolder)/"  -Force
}

Actual:

Will unpack into C:\FOOBAR\Server/.temp/mongodb-win32-x86_64-2008plus-ssl-4.0.8.zip
Write-Progress : Win32 internal error "Access is denied" 0x5 occurred while reading the console output buffer. Contact Microsoft Customer Support Services.
At C:\program files\powershell\6\Modules\Microsoft.PowerShell.Archive\Microsoft.PowerShell.Archive.psm1:1176 char:9
+         Write-Progress -Activity $cmdletName -Status $status -Percent ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ReadError: (:) [Write-Progress], HostException
+ FullyQualifiedErrorId : ReadConsoleOutput,Microsoft.PowerShell.Commands.WriteProgressCommand

Expected:

  1. No error.
  2. I got same error on other machines for Invoke-WebRequest and $ProgressPreference = 'SilentlyContinue'
  3. So $ProgressPreference = 'SilentlyContinue' should work for Expand-Archive.
  4. Other machines works fine.

Machine which fails

PS C:\FOOBAR\Server> systeminfo

Host Name:                 S10825139
OS Name:                   Microsoft Windows Server 2019 Standard
OS Version:                10.0.17763 N/A Build 17763
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Standalone Server
OS Build Type:             Multiprocessor Free
Registered Owner:          Windows User
Registered Organization:
Product ID:                00429-80522-20345-AA672
Original Install Date:     7/1/2019, 3:09:08 PM
System Boot Time:          7/1/2019, 3:16:11 PM
System Manufacturer:       HPE
System Model:              ProLiant DL325 Gen10
System Type:               x64-based PC
Processor(s):              1 Processor(s) Installed.
                           [01]: AMD64 Family 23 Model 1 Stepping 2 AuthenticAMD ~1200 Mhz
BIOS Version:              HPE A41, 1/25/2019
Windows Directory:         C:\Windows
System Directory:          C:\Windows\system32
Boot Device:               \Device\HarddiskVolume1
System Locale:             en-us;English (United States)
Input Locale:              en-us;English (United States)
Time Zone:                 (UTC) Coordinated Universal Time
Total Physical Memory:     32,613 MB
Available Physical Memory: 28,042 MB
Virtual Memory: Max Size:  37,733 MB
Virtual Memory: Available: 33,714 MB
Virtual Memory: In Use:    4,019 MB
Page File Location(s):     C:\pagefile.sys
Domain:                    WORKGROUP
Logon Server:              \\S10825139
Hotfix(s):                 18 Hotfix(s) Installed.
                           [01]: KB4502559
                           [02]: KB4462930
                           [03]: KB4465664
                           [04]: KB4470502
                           [05]: KB4470788
                           [06]: KB4471331
                           [07]: KB4477029
                           [08]: KB4480056
                           [09]: KB4480979
                           [10]: KB4487038
                           [11]: KB4489907
                           [12]: KB4493478
                           [13]: KB4493510
                           [14]: KB4497932
                           [15]: KB4499728
                           [16]: KB4503308
                           [17]: KB4504369
                           [18]: KB4503327
Network Card(s):           4 NIC(s) Installed.
                           [01]: Broadcom NetXtreme Gigabit Ethernet
                                 Connection Name: Embedded LOM 1 Port 1
                                 DHCP Enabled:    No
                                 IP address(es)
                                 [01]: 212.32.254.57
                                 [02]: fe80::259c:9fa3:73ce:5d29
                           [02]: Broadcom NetXtreme Gigabit Ethernet
                                 Connection Name: Embedded LOM 1 Port 3
                                 Status:          Media disconnected
                           [03]: Broadcom NetXtreme Gigabit Ethernet
                                 Connection Name: Embedded LOM 1 Port 4
                                 Status:          Media disconnected
                           [04]: Broadcom NetXtreme Gigabit Ethernet
                                 Connection Name: Embedded LOM 1 Port 2
                                 DHCP Enabled:    Yes
                                 DHCP Server:     10.32.255.2
                                 IP address(es)
                                 [01]: 10.32.27.193
                                 [02]: fe80::5189:f2a8:2f65:88ee
Hyper-V Requirements:      VM Monitor Mode Extensions: Yes
                           Virtualization Enabled In Firmware: Yes
                           Second Level Address Translation: Yes
                           Data Execution Prevention Available: Yes

Versions:

Write-Host "Runn as Administrator once on Windows as soon as machine obtained in powershell.exe via RPD"
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0; Set-Service -Name sshd -StartupType 'Automatic'; Restart-Service -Name sshd

$pwshUrl = "https://github.com/PowerShell/PowerShell/releases/download/v6.1.2/PowerShell-6.1.2-win-x64.msi"

6.2.1 has same issue.

I expect Expand-Archive to work fine on Windows Server 2019 over Open SSH.

@dzmitry-lahoda
Copy link
Author

Workaround

  try {
    Expand-Archive -Path $unpacked -DestinationPath "$($FOOBAR_RUNTIME)$($runtimeFolder)/"  -Force
  }
  catch {
    tar -xkf $unpacked -C "$($FOOBAR_RUNTIME)$($runtimeFolder)/"
  }

@dzmitry-lahoda
Copy link
Author

dzmitry-lahoda commented Jul 3, 2019

I run from cmder and vscode consoles on client, not sure if it is relevant

@dzmitry-lahoda
Copy link
Author

Probably archive should be big enough to repro.

@ndabas
Copy link

ndabas commented Mar 20, 2020

This is actually a limitation of script modules. Script modules inherit variable scope from the global scope, instead of from the calling script scope. The simple workaround is to set the preference variable in global scope:

$global:ProgressPreference = "SilentlyContinue"

More info:
https://devblogs.microsoft.com/scripting/weekend-scripter-access-powershell-preference-variables/
https://powershell.org/2014/01/getting-your-script-module-functions-to-inherit-preference-variables-from-the-caller/

@SydneyhSmith SydneyhSmith added this to the 1.2.0 milestone Jun 1, 2022
mvaessen added a commit to mvaessen/Windows-Containers that referenced this issue Jul 4, 2023
When running on Windows Server 2019 via SSH this results in `Win32 internal error "Access is denied" 0x5 occurred while reading the console output buffer. Contact Microsoft Customer Support Services.`.

Changes prevent issues with CLI non-interactive execution on Window Server 2019 by suppressing process bar for Expand-Archive command (see: PowerShell/Microsoft.PowerShell.Archive#77)

Tested on Windows Server 2019 & 2022
mvaessen added a commit to mvaessen/Windows-Containers that referenced this issue Jul 4, 2023
When running on Windows Server 2019 via SSH this results in `Win32 internal error "Access is denied" 0x5 occurred while reading the console output buffer. Contact Microsoft Customer Support Services.`.

Changes prevent issues with CLI non-interactive execution on Window Server 2019 by suppressing process bar for Expand-Archive command (see: PowerShell/Microsoft.PowerShell.Archive#77)

Tested on Windows Server 2019 & 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants