PowerShell

How to print PATH environment variable in PowerShell (Core)

Run

$env:PATH

to show the PATH environment variable in PowerShell.

Posted by Uli Köhler in PowerShell, Windows

How to fix Windows “echo $PATH” empty result

When you try to run

echo $PATH

you will always get an empty result.

Instead, if you are in cmd, use

echo %PATH%

but if you are using PowerShell, you need to use

$env:PATH

 

Posted by Uli Köhler in PowerShell, Windows

How to generate filename with date and time in PowerShell

You can use Get-Date like this to generate a date that is compatible with characters allowed in filenames:

Get-Date -UFormat "%Y-%m-%d_%H-%m-%S"

Example output:

2020-12-11_01-12-26

In order to generate a complete filename, surround that with $() and prepend/append other parts of your desired filename:

mysqldump-$(Get-Date -UFormat "%Y-%m-%d_%H-%m-%S").sql

 

Posted by Uli Köhler in PowerShell, Windows

How to make PowerShell output error messages in English

If you want to see a PowerShell output (e.g. an error message) in english instead of your local language, prefix your command by

[Threading.Thread]::CurrentThread.CurrentUICulture = 'en-US';

For example, in order to run to run My-Cmdlet -Arg 1 with output in English instead of your local language, use

[Threading.Thread]::CurrentThread.CurrentUICulture = 'en-US'; My-Cmdlet -Arg 1

[Threading.Thread]::CurrentThread.CurrentUICulture only affects the current command and does not have any effect for other commands. Hence your need to copy the command before each and every command for which you want to see the output in English.

Possibly you also need to install the English help files in order to see more messages in English. In order to do that, run this command in PowerShell as an administrator:

Update-Help -UICulture en-US

 

Posted by Uli Köhler in PowerShell, Windows