What is the relationship between the PowerShell and the cmd command line in the PowerShell introductory tutorial? _powershell

Source: Internet
Author: User
Tags reserved

is powershell an enhanced version of the command line? PowerShell can execute all commands on the command line? PowerShell want to override the command line? The answers to these three questions are sufficient to let us understand the relationship between PowerShell and the cmd command line. Let's go slowly ...

cmd command in PowerShell

Start PowerShell and enter a few commonly used CMD commands

Copy Code code 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 alias.txt
-A---1/21/2013 8:32 PM 241530 cmdlets.txt

Or
Copy Code code as follows:

PS d:\projects\practise\powershell> CD.
PS d:\projects\practise>

The result was similar to what we had expected. But can we say that PowerShell is PowerShell is the command line of the enhanced version? Try the following command again:
Copy Code code as follows:

PS d:\projects\practise\powershell> dir/ad
Dir:cannot find path ' D:\ad ' because it does not exist.

This is a far cry from our expectations. In cmd, it should output information about subfolders of the current location, but it doesn't seem to understand our parameters here. The following command is the same:

Copy Code code as follows:

PS D:\projects\practise\powershell> FC. \alias.txt. \cmdlets.txt
Format-custom:a positional parameter cannot is found that accepts '. Argument '.

I was going to call the FC command to compare two files, but it was understood as format-custom, irrelevant. What the hell is going on here? Here we can answer the first two questions: PowerShell cannot execute all the commands on the cmd command line, specifically, PowerShell cannot execute any CMD commands, at least not directly. This is because, PowerShell is not a new version of CMD or the enhanced version of what, but some of its commands from appearance to function are similar to the cmd command.

The relationship between PowerShell and the cmd command line

PowerShell can be used as an application running in CMD, running in a way that is a bit like running sqlcmd or nslookup in cmd, which is the operating environment of the application until the exit is clear, all input, including commands and data, are accepted and processed by the application.

Copy Code code as follows:

D:\projects\practise\powershell>powershell
Windows PowerShell
Copyright (C) is 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, running in a similar way to running PowerShell in CMD:

Copy Code code as follows:

PS d:\projects\practise\powershell> cmd
Microsoft Windows [Version 6.2.9200]
(c) 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 This feature allows users to use the PowerShell command in a cmd style. The advantage of this is that the user in the first contact with PowerShell, as in the use of CMD as cordial, familiar. The downside is that it's easy to confuse PowerShell with CMD. But when you understand the concept of alias and the Get-alias command, the problem will be solved:

Copy Code code 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, dir is actually an alias for the PowerShell Get-childitem command, and the CD is Set-location alias ... Here PowerShell and cmd relationship problem is solved.

is the CMD Command Guild replaced by PowerShell?

I have always hated similar "who is not as good", "who to replace who" problem, put here also, the new things must have its advantages, the old things also have a ticket fans. From the point of view that PowerShell is accepted now, in a short time cmd will not be replaced by PowerShell. In the long run, who knows? I only know that one more choice is one more freedom, one more possibility.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.