Here is a quick and simple one-liner to retrieve all of your environment variables into an output .txt file.
It utilizes the “gci env:” command to retrieve the environment variables on your current machine, then using piping, sends that information to “Format-List”, which will output all the properties retrieved with “gci env:” into a list of properties. Finally, the formatted list is piped into the “Out-File” command, to be saved as a .txt file at the given path.
(gci env:) | Format-List | Out-File -FilePath .\EnvironmentVariables.txt
For demonstration purposes, the -FilePath for the “Out-File” command is just the current location.
If you don’t want to output the environment variables into the text file, you can cut out the final piped command, and just use:
# with formatting:
(gci env:) | Format-List
# or without the formatting:
gci env:
This will just display the environment variable values in the terminal.