• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >PowerShell > PowerShell入门教程之PowerShell和Cmd命令行的关系?

PowerShell入门教程之PowerShell和Cmd命令行的关系?

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了powershell和cmd,powershell和cmd区别,powershell替换cmd,powershell入门,powershell入门教程等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

PowerShell是命令行的加强版吗?PowerShell能执行命令行的所有命令吗?PowerShell要替代命令行?这三个问题的答案足以让我们了解PowerShell与Cmd命令行之间的关系。让我们慢慢道来。。。

PowerShell中的CMD命令

启动PowerShell,在其中输入几个常用的Cmd命令
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
</div>
或者
PS D:\Projects\Practise\PowerShell> cd ..
PS D:\Projects\Practise>
</div>
结果跟我们的预期是差不多。不过,我们是否就能据此说PowerShell就是PowerShell是命令行的加强版吗?再试试下面这个命令:
PS D:\Projects\Practise\PowerShell> dir /ad
dir : Cannot find path 'D:\ad' because it does not exist.
</div>

这个跟我们的期望相去甚远。在Cmd中,它应该输出当前位置的子文件夹的信息,但是这里,它似乎理解不了我们的参数。下面这个命令也是一样:
PS D:\Projects\Practise\PowerShell> fc .\alias.txt .\cmdlets.txt
Format-Custom : A positional parameter cannot be found that accepts argument '.\cmdlets.txt'.
</div>

我本来想要调用比较两个文件的fc命令,结果它却理解成了Format-Custom,牛头不对马嘴。这是怎么回事儿呢?到这里我们就可以回答前两个问题了:PowerShell不能执行Cmd命令行的所有命令,确切地说,PowerShell不能执行任何Cmd命令,至少不能直接执行。这是因为,PowerShell不是Cmd的新版本或者加强版什么的,只是它的有些命令从长相到功能都跟Cmd命令很相似而已。

PowerShell与Cmd命令行的关系

  PowerShell可以做为一个应用程序在Cmd中运行,其运行方式有点像在Cmd中运行SQLCmd或者Nslookup,在没有明确exit退出之前,一直是应用程序的运行环境,一切的输入,包括命令和数据,都由应用程序来接受和处理。
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
</div>

Cmd也可以在PowerShell中作为应用程序运行,其运行方式与在Cmd中运行PowerShell相似:
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
</div>

PowerShell通过Alias这个特性,可以让使用者以Cmd风格来使用PowerShell命令。这样做的好处是让用户在刚接触PowerShell的时候,就像在使用Cmd一样亲切、熟悉。坏处是,让人容易把PowerShell和Cmd搞混了。不过当你了解了Alias的概念和Get-Alias命令以后,这个问题将迎刃而解:
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
</div>

就是说dir实际上是PowerShell的Get-ChildItem命令的一个别名,cd是Set-Location的别名。。。到这里PowerShell和Cmd的关系问题算是解决了。

Cmd命令行会被PowerShell替代吗?

  我其实一直以来都很讨厌类似“谁不如谁好”、“谁要代替谁”的问题,放到这里也一样,新的东西必然有它的优越性,旧的东西也有一票粉丝。从现在PowerShell被接受的程度来看,短时间内Cmd不会被PowerShell替代。长远来看呢,谁知道呢。我只知道,多一份选择就多一份自由,多一种可能性。

</div>

您可能想查找下面的文章:

  • 浅谈CMD和win powershell的区别
  • 在cmd中直接运行PowerShell脚本文件的方法
  • PowerShell入门教程之Cmd命令与PowerShell命令相互调用的方法
  • PowerShell入门教程之PowerShell和Cmd命令行的关系?
  • PowerShell中运行CMD命令的技巧总结(解决名称冲突和特殊字符等问题)

相关文章

  • Powershell脚本的4种执行权限介绍
  • PowerShell是什么?
  • Powershell中获取所有磁盘盘符的方法
  • Windows Powershell 通过函数扩展别名
  • Powershell小技巧之删除不规则字符
  • Powershell小技巧之开启关闭远程连接
  • PowerShell脚本开发之收发UDP消息包
  • PowerShell中的变量基础知识介绍
  • 揭秘PowerShell 5.0新特性和新功能
  • PowerShell脚本实现添加、修改任务计划的例子

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Powershell获取图片名字、文件夹及拍摄时间的例子
    • PowerShell中使用ArrayList实现数组插入、删除、添加例子
    • powershell操作word详解
    • PowerShell查看进程的所属用户
    • PowerShell读取文件内容、替换文件内容、读取限定行的例子
    • PowerShell脚本trap语句捕获异常写法实例
    • Powershell在一个会话中只允许执行指定命令的方法
    • PowerShell使用match操作符来筛选数组
    • Powershell小技巧之查找脚本中的函数
    • PowerShell入门教程之PowerShell管道介绍

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有