Applies to: Command Prompt (cmd.exe) and Windows PowerShell 5.1 on Windows 10, 11 and Windows Server; PowerShell 7.6.6 LTS (PowerShell examples run on 7.6.6, Windows-only parts from Microsoft’s documentation)

Command Prompt (cmd.exe) is the old Windows command interpreter: it runs commands and batch files (.bat, .cmd), and everything that passes between commands is text. PowerShell is a shell and scripting language whose commands (cmdlets) pass objects with properties, so you can filter and sort without cutting up text. Microsoft’s own cmd reference points users who want more advanced scripting to PowerShell. For new work on a Windows server, use PowerShell.

The main differences

  • Text or objects. In PowerShell, each file from Get-ChildItem is an object with a Length, a LastWriteTime and so on. Filtering and sorting take one line (output from our test):
    PS> Get-ChildItem | Where-Object Length -gt 1000 | Sort-Object Length -Descending | Select-Object Name, Length
    
    Name  Length
    ----  ------
    c.txt  20001
    a.log   5001
    The same objects convert straight to JSON: Get-ChildItem -Filter *.log | Select-Object Name, Length | ConvertTo-Json -Compress gave [{"Name":"a.log","Length":5001},{"Name":"b.log","Length":6}].
  • Command names. cmd uses short built-in commands and programs (dir, copy, ipconfig, netsh). PowerShell cmdlets are named Verb-Noun, such as Get-ChildItem or Copy-Item. PowerShell can still run programs such as ipconfig and ping; their output arrives as plain strings.
  • Familiar names still work in PowerShell as aliases, but they take PowerShell parameters, so dir -Recurse instead of dir /s. In PowerShell 7.6.6, Get-Alias showed dir = Get-ChildItem, copy = Copy-Item, del = Remove-Item, type = Get-Content, cd = Set-Location and cls = Clear-Host.
  • Variables. cmd: set NAME=value and %NAME%. PowerShell: $name = "value" and $env:NAME for environment variables.
  • Scripts. cmd runs .bat and .cmd files. PowerShell runs .ps1 files, controlled by the execution policy; according to Microsoft, when no policy is set it is Restricted (no scripts) on Windows clients and RemoteSigned on Windows Server. See PowerShell cmdlets and the execution policy.
  • Success and failure. Both know && (run the next command only if this one worked) and || (only if it failed), but in PowerShell only from version 7; Windows PowerShell 5.1 doesn’t have them. PowerShell also sets $? (True or False) and $LASTEXITCODE for programs.

The same jobs in both

Task                      Command Prompt           PowerShell
List files                dir                      Get-ChildItem
Copy a file               copy a.txt b.txt         Copy-Item a.txt b.txt
Delete a file             del a.txt                Remove-Item a.txt
Show a file               type a.txt               Get-Content a.txt
Show an env variable      echo %USERNAME%          $env:USERNAME
List env variables        set                      Get-ChildItem Env:
Run one in the other      powershell -Command ...  cmd /c dir

Windows PowerShell 5.1 or PowerShell 7?

Windows comes with Windows PowerShell 5.1 (powershell.exe), built on .NET Framework. PowerShell 7 (pwsh.exe) is the newer, cross-platform version; it installs next to 5.1 and doesn’t replace it. According to Microsoft, 7.6.6 is the current LTS release. Install it with:

winget install --id Microsoft.PowerShell --source winget

winget isn’t available on Windows Server 2022 or older, and on Windows Server 2025 only with the Desktop Experience; there, use the MSI package from Microsoft’s install page. Some older Windows modules still only run in Windows PowerShell 5.1, so keep both.

Which to use

  • PowerShell for anything new: server administration, scripts, working with services, the firewall and network settings, and remote management.
  • Command Prompt for old batch files you don’t want to rewrite, and quick one-off commands such as ipconfig /all, which work the same in PowerShell anyway.

On a Windows VPS or server you reach both over Remote Desktop. Useful next steps: open ports on Windows Server and change the RDP port.

Official documentation: cmd, differences between Windows PowerShell 5.1 and PowerShell 7 and install PowerShell on Windows.

Ucartz services for this topic

  • Hire an expert: engineers per 15 minutes, per hour or per month, with no contract.
  • Server management: on-demand administration, hardening, migrations and monitoring.
Was this answer helpful? 0 Users Found This Useful (0 Votes)