vmware / powerclicore

PowerCLI Core Dockerfile
Apache License 2.0
100 stars 47 forks source link

PowerShell Hashtables does not properly print/output with current Photon Container #58

Closed lamw closed 1 year ago

lamw commented 3 years ago

It looks like PowerShell Hashtables can not be printed using current Photon/PowerShell Docker Container. Using the Microsoft image, it does work and assume this is related to either the version of PS (latest for Photon is 7.1.2) and Microsoft version is 7.1.3 and I've not had success in manually installing the latest version using Photon Docker container to confirm if its related to PowerShell version and/or underlying container OS

Current Behavior:

Dockerfile:

FROM vmware/powerclicore

ENTRYPOINT ["/bin/pwsh"]

No output when attempting to pass $hash to Out-String cmdlet:

# docker run --rm lamw/ps -Command '$hash=@{"foo"="bar"};$hash|out-string'

<no output>

Expected Behavior:

# docker run --rm mcr.microsoft.com/powershell /bin/pwsh -Command '$hash=@{"foo"="bar"};$hash | out-string'

Name                           Value
----                           -----
foo                            bar
dmilov commented 3 years ago

The problem comes from the TERM environment variable which is set to linux in the base container. The default width in columns of the TERM linux is small to display the formatted hashtable.

Suggested workarounds of the issue

  1. Use -Width parameter of the Out-String cmdlet
    docker run --rm lamw/ps -Command '$hash=@{"foo"="bar"};$hash | out-string -Width 80'
  2. Use different TERM in your image
    
    FROM vmware/powerclicore

ENV TERM xterm

ENTRYPOINT ["/bin/pwsh"]

dmilov commented 3 years ago

Meanwhile, I'll update the powerclicore image to use linux-basic terminal which hasn't this issue

dmilov commented 3 years ago

Pushed new version of vmware/powerclicore image with the fix. The tags latest and 12.3.1 have the fix now.

Tested:

Dockerfile

FROM vmware/powerclicore

ENTRYPOINT ["/bin/pwsh"]
docker build -t dmpcli .
docker run --rm dmpcli -Command "`$hash=@{'foo'='bar'};`$hash|out-string"

Name                           Value
----                           -----
foo                            bar
dmilov commented 3 years ago

The fix of this one led to regression in the interactive scenario which is more important than this one. Reverting the fix here with the ask to run it with -e TERM=linux-basic as a workaround