SoFunction
Updated on 2025-03-10

What is the relationship between PowerShell and Cmd command line in the PowerShell?

Is PowerShell an enhanced version of the command line? Can PowerShell execute all commands on the command line? Want PowerShell to replace the command line? The answers to these three questions are enough to let us understand the relationship between PowerShell and the Cmd command line. Let's talk slowly. . .

CMD commands in PowerShell

Start PowerShell and enter several commonly used Cmd commands in it

Copy the codeThe code is as follows:

PS D:\Projects\Practise\PowerShell> dir
    Directory: D:\Projects\Practise\PowerShell
Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----         1/23/2013  12:35 PM            d1
d----         1/23/2013  12:35 PM            d2
-a---         1/21/2013   8:38 PM      36314
-a---         1/21/2013   8:32 PM     241530

or
Copy the codeThe code is as follows:

PS D:\Projects\Practise\PowerShell> cd ..
PS D:\Projects\Practise>

The result is similar to what we expected. However, can we say that PowerShell is a enhanced version of the command line based on this? Try the following command again:
Copy the codeThe code is as follows:

PS D:\Projects\Practise\PowerShell> dir /ad
dir : Cannot find path 'D:\ad' because it does not exist.

This is far from what we expect. In Cmd, it should output information of the subfolder in the current location, but here, it doesn't seem to understand our parameters. The following command is the same:

Copy the codeThe code is as follows:

PS D:\Projects\Practise\PowerShell> fc .\ .\
Format-Custom : A positional parameter cannot be found that accepts argument '.\'.

I originally wanted to call the FC command that compares the two files, but it was understood as Format-Custom, which is wrong. What's going on? At this point, we can answer the first two questions: PowerShell cannot execute all commands on the Cmd command line. To be precise, PowerShell cannot execute any Cmd commands, at least it cannot be executed directly. This is because PowerShell is not a new version or enhanced version of Cmd, but some of its commands are very similar to the Cmd command from appearance to function.

The relationship between PowerShell and Cmd command line

PowerShell can be run in Cmd as an application. Its running method is a bit like running SQLCmd or Nslookup in Cmd. Before exiting explicitly, it is always the application's running environment. All inputs, including commands and data, are accepted and processed by the application.

Copy the codeThe code is as follows:

D:\Projects\Practise\PowerShell>powershell
Windows PowerShell
Copyright (C) 2012 Microsoft Corporation. All rights reserved.

PS D:\Projects\Practise\PowerShell> get-help

TOPIC
    Windows PowerShell Help System

Cmd can also run as an application in PowerShell, and it runs similarly to running PowerShell in Cmd:

Copy the codeThe code is as follows:

PS D:\Projects\Practise\PowerShell> cmd
Microsoft Windows [Version 6.2.9200]
(c) 2012 Microsoft Corporation. All rights reserved.

D:\Projects\Practise\PowerShell>dir /ad
Volume in drive D is Doc
Volume Serial Number is A6C5-E7CE

Directory of D:\Projects\Practise\PowerShell

01/30/2013  04:54 PM    <DIR>          .
01/30/2013  04:54 PM    <DIR>          ..
01/23/2013  12:35 PM    <DIR>          d1
01/23/2013  12:35 PM    <DIR>          d2

PowerShell uses the Alias ​​feature to allow users to use PowerShell commands in the Cmd style. The advantage of this is that when users first come into contact with PowerShell, they are as friendly and familiar as when using Cmd. The downside is that it is easy to confuse PowerShell and Cmd. However, when you understand the concept of Alias ​​and the Get-Alias ​​command, this problem will be solved:

Copy the codeThe code is as follows:

PS D:\Projects\Practise\PowerShell> get-alias dir, echo, type

CommandType     Name                                               ModuleName
-----------     ----                                               ----------
Alias           dir -> Get-ChildItem

Alias           cd -> Set-Location
Alias           echo -> Write-Output

That is to say, dir is actually an alias for PowerShell's Get-ChildItem command, and cd is an alias for Set-Location. . . At this point, the relationship between PowerShell and Cmd has been solved.

Will the Cmd command line be replaced by PowerShell?

I have always hated questions like "Who is worse than who is better" and "who wants to replace whom". The same is true when put here. New things must have their superiority, and old things also have a fan of them. Judging from the degree to which PowerShell is now accepted, Cmd will not be replaced by PowerShell in a short period of time. In the long run, who knows. I only know that more choices will bring more freedom and more possibilities.