Skip to main content
St Louis

Back to all posts

How to Use an Environment Variable In Powershell Console?

Published on
2 min read
How to Use an Environment Variable In Powershell Console? image

Best PowerShell Environment Variable Tools to Buy in October 2025

1 Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools

Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools

BUY & SAVE
$47.34 $59.99
Save 21%
Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools
2 Beginner’s Guide to PowerShell Scripting: Automate Windows Administration, Master Active Directory, and Unlock Cloud DevOps with Real-World Scripts and Projects

Beginner’s Guide to PowerShell Scripting: Automate Windows Administration, Master Active Directory, and Unlock Cloud DevOps with Real-World Scripts and Projects

BUY & SAVE
$0.99
Beginner’s Guide to PowerShell Scripting: Automate Windows Administration, Master Active Directory, and Unlock Cloud DevOps with Real-World Scripts and Projects
3 AWS Tools for PowerShell 6: Administrate, maintain, and automate your infrastructure with ease

AWS Tools for PowerShell 6: Administrate, maintain, and automate your infrastructure with ease

BUY & SAVE
$48.99
AWS Tools for PowerShell 6: Administrate, maintain, and automate your infrastructure with ease
4 Learn Windows PowerShell in a Month of Lunches

Learn Windows PowerShell in a Month of Lunches

BUY & SAVE
$34.99
Learn Windows PowerShell in a Month of Lunches
5 PowerShell Advanced Cookbook: Enhance your scripting skills and master PowerShell with 90+ advanced recipes (English Edition)

PowerShell Advanced Cookbook: Enhance your scripting skills and master PowerShell with 90+ advanced recipes (English Edition)

BUY & SAVE
$37.95
PowerShell Advanced Cookbook: Enhance your scripting skills and master PowerShell with 90+ advanced recipes (English Edition)
6 Learn PowerShell Toolmaking in a Month of Lunches

Learn PowerShell Toolmaking in a Month of Lunches

BUY & SAVE
$20.51 $44.99
Save 54%
Learn PowerShell Toolmaking in a Month of Lunches
7 Learn PowerShell Scripting in a Month of Lunches

Learn PowerShell Scripting in a Month of Lunches

BUY & SAVE
$45.28
Learn PowerShell Scripting in a Month of Lunches
8 PowerShell for Sysadmins: Workflow Automation Made Easy

PowerShell for Sysadmins: Workflow Automation Made Easy

BUY & SAVE
$28.99
PowerShell for Sysadmins: Workflow Automation Made Easy
9 Hands-On Penetration Testing on Windows: Unleash Kali Linux, PowerShell, and Windows debugging tools for security testing and analysis

Hands-On Penetration Testing on Windows: Unleash Kali Linux, PowerShell, and Windows debugging tools for security testing and analysis

BUY & SAVE
$22.26 $48.99
Save 55%
Hands-On Penetration Testing on Windows: Unleash Kali Linux, PowerShell, and Windows debugging tools for security testing and analysis
+
ONE MORE?

To use an environment variable in PowerShell console, you can access the value of the variable by using the syntax $env:VariableName. For example, to access the value of the PATH environment variable, you would use $env:PATH. You can also set the value of an environment variable using the same syntax. Additionally, you can list all available environment variables by using the Get-ChildItem Env: command in PowerShell. This will display a list of all defined environment variables along with their values.

How to assign a value to an environment variable in PowerShell console?

To assign a value to an environment variable in PowerShell console, you can use the following command:

$env:VARIABLE_NAME = "value"

Replace "VARIABLE_NAME" with the name of the environment variable you want to set, and "value" with the value you want to assign to it.

For example, to set an environment variable named "MyVariable" with a value of "12345", you would use the following command:

$env:MyVariable = "12345"

After running this command, the environment variable will be set to the specified value and can be accessed using the "$env:VARIABLE_NAME" syntax.

How to import environment variables in PowerShell console?

To import environment variables in PowerShell console, you can use the following command:

$env:VARIABLE_NAME = "VALUE"

Replace VARIABLE_NAME with the name of the environment variable you want to set and replace VALUE with the value you want to assign to that variable.

For example, to set a variable named MY_VAR with the value of Hello World, you would use the following command:

$env:MY_VAR = "Hello World"

You can then access this environment variable in PowerShell and any other programs running in the same session.

How to export environment variables in PowerShell console?

To export environment variables in the PowerShell console, you can use the following command:

$env:VARIABLE_NAME = "value"

Replace "VARIABLE_NAME" with the name of the environment variable you want to set, and replace "value" with the value you want to assign to the variable.

For example, to set a variable named "MYVAR" with a value of "hello", you would run the following command:

$env:MYVAR = "hello"

You can then access this environment variable using the usual syntax of $env:VARIABLE_NAME in PowerShell scripts or commands.