对于任何使用Linux(Linux)系统的人来说,带有闪烁光标的黑色(或蓝色)终端都是经典图像。但是,在Microsoft Windows中,您不再需要使用命令行界面。无论(Whether)是安装新应用程序还是配置操作系统,您都可以通过图形用户界面 ( GUI ) 完成所有操作。
不过, Windows 操作系统(Windows OS)中的终端命令仍有时间和地点。您只能使用命令行 shell 设置批处理命令或自动化任务等内容。
那么,哪个命令行工具更好,命令提示符(Command Prompt)还是Powershell?有什么理由同时使用两者吗?各自的优点和缺点是什么?这是一个完整的概述。
Windows命令提示符——现代(Modern)系统(Systems)的MS-DOS(Command Prompt—MS-DOS)
在黑色终端和键入命令的黑暗时代,微软通过其(Microsoft)MS-DOS操作系统开始流行。即使公司最终放弃了命令行界面(Command Line Interface)( CLI ),微软还是在(Microsoft)MS-DOS之上构建了操作系统。用户仍然可以使用MS-DOS Prompt访问其功能,后来重命名为Command Prompt。
所有版本的Windows操作系统都包括命令提示符(Command Prompt),无论是Windows NT、Windows 7还是Windows 10。运行命令提示符(Command Prompt)会打开一个黑色终端窗口,其中有一个闪烁的光标准备好接受命令。默认活动目录是当前用户的文件夹,尽管您可以使用 CD 命令轻松切换。
您可以使用各种命令(variety of commands)来执行有用的任务,从验证系统文件的完整性(integrity of your system files)到检查硬盘驱动器(checking the hard drive)的逻辑错误。您甚至可以使用命令提示符(Command Prompt)格式化驱动器(format a drive)或隐藏文件(hide files)。输入(Entering)“ DIR ”列出活动目录的内容,让您访问或重命名任何文件或文件夹。
命令提示符的唯一问题是它只是一个解释器。虽然您可以使用批处理文件来重用一组命令,但它远没有像Bash这样的适当 shell 强大。此外,Windows的每个新版本都使GUI越来越远离命令行表示,这意味着您实际上无法使用命令提示符(Command Prompt)进行太多控制。
如何使用命令
(Getting started)命令提示符(Command Prompt)入门很简单。您无需安装或配置任何东西——只需在开始菜单中搜索(Start Menu)CMD即可找到该应用程序。这将直接打开一个新的 cmd.exe 窗口以供输入。对于某些命令,您必须使用管理员权限打开CMD 。
命令提示符:优点和缺点
优点
- 易于学习和使用。
- 各种有用的命令,如 chkdsk 或 scannow。
- 系统占用空间小。
缺点
- 一组有限的命令。
- 很难编写可重用的脚本。
- 无法设置自动化任务。
- 没有适用于所有GUI操作的命令行对应项。
Windows Powershell——微软的脚本外壳(Scripting Shell)
Linux用户一直对命令提示符(Command Prompt)感到失望。毕竟,CMD命令的范围有限,并不意味着自动化。管理数十台PC的(PCs)系统(System)管理员需要一个可用于设置自动化任务的脚本环境,例如Bash。
这就是PowerShell的用武之地。使用(PowerShell).NET框架构建的成熟脚本语言,您可以使用Windows PowerShell自动执行Windows服务器或家用计算机上的大多数管理任务。需要明确的是,现在也可以直接在Windows 10或 Windows 11上运行 Bash ,但(run Bash directly)PowerShell具有更好的集成性。
PowerShell通过称为 cmdlet 的专用 .NET 类工作。PowerShell cmdlet 通过与注册表(Registry)或文件系统等服务提供商交互来执行系统管理任务。这种模块化方法允许PowerShell脚本具有高度可扩展性和通用性。
该实用程序基本上充当了自己的开源编程语言,其语法比一堆传统的DOS命令更丰富。复杂的脚本几乎可以控制计算机的各个方面,使其成为系统管理的绝佳工具。企业(Enterprise)用户可以使用PowerShell与WMI(Windows Management Instrumentation)接口,通过脚本管理整个服务器。
如何使用 PowerShell
与命令提示符(Command Prompt)不同,Windows PowerShell是一种完整的脚本语言。这意味着您不仅要打开终端窗口并输入命令,还要使用其语法编写脚本。
为此,您有两个选择。PowerShell ISE(集成脚本环境(Integrated Scripting Environment))是用于测试PowerShell脚本的出色应用程序,因为它允许在单个应用程序中编写和调试代码。但Windows已停止在ISE上的开发,并将很快弃用它。
您现在可以使用官方扩展在 Visual Studio中编写(Studio)PowerShell脚本。(PowerShell)如果您计划为自动化和系统管理编写复杂的脚本,这是一种更好的方法。
PowerShell:优点和缺点
优点
- 可以自动化大多数 GUI 菜单任务。
- (Highly)通过第三方插件高度可扩展。
- 模块化设计使脚本具有通用性和可重用性。
- 可以与Registry等系统组件交互。
- 可与WMI一起用于管理企业系统。
缺点
PowerShell VS 命令提示符(PowerShell VS Command Prompt):哪个是最好的?
与大多数事情一样,更强大并不总是更好。有时(Sometimes)简单本身就是一种美德,尤其是在您不需要高级功能的情况下。
将命令提示符(Command Prompt)与PowerShell进行比较时也可以这样说。在纸面上,PowerShell是明显的赢家,它具有更强大的框架和广泛的功能。您可以使用它来自动化大多数管理任务,例如Linux发行版中的 bash shell。
但大多数用户不需要那种级别的自定义或控制。对于希望执行基本命令行活动的家庭用户,CMD是一个更容易使用的工具。命令提示符(Command Prompt)的语法要基本得多,并提供 chkdsk 和SFC等关键工具作为单行命令。
最适合您的命令行实用程序是完成工作的实用程序。如果您想要一个类似 Linux 的脚本环境来管理服务器或联网计算机,那么您需要PowerShell 。另一方面,如果您正在寻找的只是一种执行基本命令以修复硬盘驱动器(repair your hard drive)或查找隐藏文件的方法,那么命令提示符(Command Prompt)就是您的最佳选择。
PowerShell vs Command Prompt: Pros and Cons
Α black (or blue) terminal with a blinking cursоr іs a claѕsic image for anyone using a Linux system. In Microsoft Windows, however, you don’t need to work wіth a command-line interface anymore. Whether installing new apps or configurіng your operating system, you can do everything through the graphic user interface (GUI).
There is still a time and place for terminal commands in a Windows OS, though. You can only set up things like batch commands or automated tasks using a command-line shell.
So, which command-line tool is better, Command Prompt or Powershell? Is there any reason to use both? What are the advantages and disadvantages of each? Here is a complete overview.
Windows Command Prompt—MS-DOS For Modern Systems
In the dark ages of black terminals and typed commands, Microsoft became popular through its MS-DOS operating system. Even when the company finally transitioned out of the Command Line Interface (CLI), Microsoft built the OS on top of MS-DOS. Users could still access its functionality using the MS-DOS Prompt, later renamed to just Command Prompt.
All versions of the Windows operating system include the Command Prompt, whether Windows NT, Windows 7, or Windows 10. Running the Command Prompt opens a black terminal window with a blinking cursor ready to accept commands. The default active directory is the current user’s folder, though you can switch that easily with the CD command.
You can use a variety of commands to perform useful tasks, from verifying the integrity of your system files to checking the hard drive for logical errors. You can even format a drive or hide files using the Command Prompt. Entering “DIR” lists the contents of the active directory, letting you access or rename any files or folders.
The only problem with the command prompt is that it’s just an interpreter. While you can use batch files to reuse a collection of commands, it is nowhere near as powerful as a proper shell like Bash. Moreover, every new release of Windows takes the GUI further and further away from command-line representation, meaning you can’t actually control much using the Command Prompt.
How to Use CMD
Getting started with the Command Prompt is simple. You don’t need to install or configure anything – just search for CMD in the Start Menu to find the app. That will directly open a new cmd.exe window ready to be typed in. For some commands, you have to open CMD using administrator permissions.
Command Prompt: Pros and Cons
Pros
- Easy to learn and use.
- Variety of useful commands like chkdsk or scannow.
- Low system footprint.
Cons
- A limited set of commands.
- Hard to write reusable scripts.
- Cannot set up automated tasks.
- Does not have command-line counterparts for all GUI actions.
Windows Powershell—Microsoft’s Scripting Shell
Linux users have always been disappointed with the Command Prompt. After all, CMD commands are limited in their scope and not meant for automation. System administrators managing dozens of PCs require a scripting environment that can be used to set up automated tasks, like Bash.
And that’s where PowerShell comes in. A fully-fledged scripting language built using the .NET framework, you can use Windows PowerShell to automate most administration tasks on a Windows server or a home computer. To be clear, it is now also possible to run Bash directly on Windows 10 or Windows 11 as well, but PowerShell has better integration.
PowerShell works through specialized .NET classes called cmdlets. PowerShell cmdlets perform system administration tasks by interfacing with service providers like the Registry or the file system. This modular approach allows PowerShell scripts to be highly extensible and versatile.
The utility basically acts as an open-source programming language of its own, with a richer syntax than a bunch of legacy DOS commands. Complex scripts can control almost every aspect of the computer, making it an excellent tool for system administration. Enterprise users can use PowerShell to interface with WMI (Windows Management Instrumentation) to manage entire servers through scripts.
How to Use PowerShell
Unlike the Command Prompt, Windows PowerShell is a complete scripting language. This means you don’t just open up a terminal window and enter commands but write scripts using its syntax.
For this, you have two options. The PowerShell ISE (Integrated Scripting Environment) is an excellent app for testing out PowerShell scripts, as it allows for writing and debugging code in a single app. But Windows has stopped development on the ISE and will soon deprecate it.
You can now write PowerShell scripts in Visual Studio using an official extension. This is a better approach if you plan on writing complex scripts for automation and system administration.
PowerShell: Pros and Cons
Pros
- Can automate most GUI menu tasks.
- Highly extensible through third-party add-ons.
- Modular design makes scripts versatile and reusable.
- Can interface with system components like the Registry.
- Usable with WMI for managing enterprise systems.
Cons
- Hard to learn for beginners.
- Too verbose for simple tasks.
PowerShell VS Command Prompt: Which One is the Best?
As with most things, more powerful isn’t always better. Sometimes simplicity is a virtue in itself, especially if the advanced features aren’t necessary to you.
The same can be said when comparing the Command Prompt with PowerShell. On paper, PowerShell is the clear winner, with a more robust framework and extensive functionality. You can use it to automate most administrative tasks like the bash shell present in Linux distros.
But most users don’t need that level of customization or control. For a home user looking to perform basic command-line activities, CMD is a much easier tool to use. The syntax of Command Prompt is far more basic and offers key tools like chkdsk and SFC as one-line commands.
The best command-line utility for you is the one that gets your job done. If you want a Linux-like scripting environment to manage servers or networked computers, PowerShell is what you need. On the other hand, if all you are looking for is a way to execute basic commands to repair your hard drive or find hidden files, the Command Prompt is the way to go.