PowerShell: Env: Avoid truncation of environment variables

17

3

PowerShell displays environment variables, one line for each. If a variable has a long enough value, it is truncated, and appended an ellipsis:

> gci env:

Name                           Value
----                           -----
<suppressed lines>
PSModulePath                   C:\Windows\system32\WindowsPowerSh...
<suppressed lines>

Is there any way of obtaining full values for all vars at once, as in a standard cmd prompt? (the answers given for Powershell get-childitem env:path returns ellipsed one line, how to have something useful? would not apply, then).

sancho.s Reinstate Monica

Posted 2013-12-18T17:41:17.990

Reputation: 2 404

I've spent an hour on searching for ways to get PowerShell to display the complete content of my path environment variable. It always truncates it to 2452 characters, with or without ellipsis marks, even if I specify wider formatting. This makes it impossible to treat PS as anything other than trivially useful. My opinion of PS is that it's a POS and nothing has changed that. I've read through hundreds of blogs and search results and nobody has a solution. Not even here. – Suncat2000 – 2017-06-21T13:11:39.137

Answers

22

Default formatting truncates, specify -Wrap and see full output.

gci env: | Format-Table -Wrap -AutoSize

Result

PSModulePath            C:\Users\KNUCKLE-DRAGGER\Documents\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\

or if you prefer the output to exactly simulate cmd.exe, try

cmd /c start /b set

Result

PSModulePath=C:\Users\KNUCKLE-DRAGGER\Documents\WindowsPowerShell\Modules;C:\Windows\system32\WindowsPowerShell\v1.0\Modules\

Knuckle-Dragger

Posted 2013-12-18T17:41:17.990

Reputation: 1 817

This is already very good. Any way of getting the same format as a standard cmd prompt? Perhaps invoking cmd.exe from the PowerShell prompt? – sancho.s Reinstate Monica – 2013-12-18T17:56:02.787

Good, that's what I was proposing. – sancho.s Reinstate Monica – 2013-12-18T18:02:25.577

4

If you want to emulate set output from powershell without invoking cmd try:

dir env: | %{"{0}={1}" -f $_.Name,$_.Value}

a lot of typing, so wrap it in a function:

function set {dir env: | %{"{0}={1}" -f $_.Name,$_.Value}}

zdan

Posted 2013-12-18T17:41:17.990

Reputation: 2 732

Both options work ok. – sancho.s Reinstate Monica – 2013-12-20T14:44:24.410