Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
cmd.exe

PowerShell: How to Emulate cmd.exe’s set Command

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For the ordinary cmd.exe command set NAME=value, use PowerShell’s environment-variable syntax:

$Env:NAME = 'value'

Read it with $Env:NAME, list the current process environment with Get-ChildItem Env:, and remove it with $Env:NAME = $null or Remove-Item Env:NAME. Do not confuse $Env:NAME with $name: the former is an environment variable inherited by child processes, while the latter is an ordinary PowerShell variable.

Basic set equivalents

cmd.exe operation PowerShell equivalent What it does
set Get-ChildItem Env: Lists environment variables in the current process.
set NAME Get-ChildItem Env:NAME* Finds variables whose names begin with NAME; the wildcard makes the prefix match explicit.
Read one value $Env:NAME Returns the value as a string.
set NAME=value $Env:NAME = 'value' Sets a value for the current PowerShell process.
set NAME= $Env:NAME = $null or Remove-Item Env:NAME Removes the variable. Empty-string behavior is version-dependent.

Listing and reading variables

# List the current process environment
Get-ChildItem Env:

# Read one variable
$Env:Path

# Prefix-style lookup, similar to cmd.exe's "set NAME"
Get-ChildItem Env:Path*

PowerShell exposes environment variables through the Env: provider. The item-style equivalents are Get-Item Env:NAME, Set-Item Env:NAME 'value', and Remove-Item Env:NAME.

Assigning and removing a value

$Env:APP_MODE = 'development'

# Remove it from this process
Remove-Item Env:APP_MODE
# Equivalent removal form
$Env:APP_MODE = $null

These changes affect the current PowerShell process and processes it starts; they do not permanently rewrite Windows user or machine settings.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
PowerShell for Sysadmins: Workflow Automation Made Easy
  • Book - powershell for sysadmins: workflow automation made easy
  • Language: english
  • Binding: paperback

Do not use an ordinary PowerShell variable by mistake

$name = 'value'       # PowerShell-only variable
$Env:NAME = 'value'   # Environment variable

$name is script data. A child program normally cannot see it. $Env:NAME is placed in the process environment, so a child process launched afterward can inherit it. Environment values are strings; convert other data types when assigning them.

Translate the other forms of set

Prompting with set /P

For a batch command such as set /P NAME=Prompt, prompt with Read-Host and assign the result to the environment variable:

$Env:USERNAME_INPUT = Read-Host 'Enter a name'

This is a behavior-level equivalent, not identical parser compatibility. Read-Host returns the entered text, which is then available to child processes through $Env:USERNAME_INPUT.

Arithmetic with set /A

Use a normal PowerShell expression rather than copying cmd.exe’s arithmetic syntax:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
$count = 4 + 5

If another process needs the result as an environment string, convert it explicitly:

$Env:COUNT = $count.ToString()

cmd.exe arithmetic has its own conventions, including hexadecimal values with 0x and leading-zero octal notation. Review such expressions instead of assuming they have the same meaning in PowerShell.

Expansion, quoting, and special characters

Variable expansion

Batch files commonly expand a value as %NAME%. PowerShell uses $Env:NAME in expressions and expandable double-quoted strings:

"
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently Asked Questions

Does $name = 'value' replace set NAME=value?

No. $name creates an ordinary PowerShell variable. Use $Env:NAME = 'value' when the value must be an environment variable visible to child processes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I make an environment-variable change permanent?

Use Windows User or Machine scope through System.Environment.SetEnvironmentVariable() or the Environment Variables control panel. A persistent change generally affects processes launched later, not shells that are already running.

The Bottom Line

Use $Env:NAME = 'value' for the normal set NAME=value translation. Handle listing, prompting, arithmetic, deletion, and persistence separately because each has different PowerShell semantics.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Read next

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.