虽然许多普通用户都知道命令提示符(Command Prompt),但只有少数人听说过Windows PowerShell。PowerShell是比命令提示符(Command Prompt)更强大的工具。它还旨在取代命令提示符(Command Prompt),因为它提供了对 Windows 操作系统的更多功能和(Windows operating)控制(power and control)。这就是为什么我们决定体验一下PowerShell并向我们所有的读者解释这个工具是什么,为什么它如此强大以及谁会更频繁地使用它。让我们看看PowerShell是什么以及你可以用它做什么:
什么是 Windows 中的 PowerShell?
为了让您更好地了解PowerShell,我们应该首先定义什么是 shell。不,我们不是在谈论龟壳。🙂 在计算机科学(computer science)中,shell 是一种用户界面(user interface),可让您访问操作系统(operating system)的各种服务。shell 可以是基于命令行的,也可以包含图形用户界面(user interface)( GUI )。
Windows PowerShell是最初由Microsoft开发的用于任务自动化(task automation)和配置管理(configuration management)的 shell 。PowerShell现在是一个开源项目(source project),可以安装在Windows、macOS 和Linux平台上。该 shell 基于.NET 框架(.NET framework),包括命令行 shell(command-line shell)和脚本语言。
PowerShell的第一个版本于 2006 年11 月(November 2006)发布,适用于Windows XP、Windows Server 2003和Windows Vista。PowerShell的最新版本是Windows PowerShell 5.1,它作为Windows 10 周年更新和 Windows Server(Anniversary Update and Windows Server) 2016 的一部分于 2016 年交付。它还适用于Windows Server 2008 R2、Windows Server 2012和Windows Server 2012 R2、Windows 7 Service Pack 1和Windows 8.1(专业版和企业版(Pro and Enterprise editions))。
你可以用 PowerShell 做什么?
Microsoft将(Microsoft)Windows PowerShell设计为一种工具,可帮助您自动化并快速解决许多繁琐的管理任务。例如,您可以使用PowerShell显示安装在网络中的一台或多台计算机上的所有USB设备,或者您可以设置一个耗时的任务在您执行其他工作时在后台运行。您还可以识别和终止没有响应的进程,或者过滤网络中有关计算机的特定信息并将其导出(network and export)为HTML 格式(HTML format)。
PowerShell的功能允许您通过创建脚本和组合多个命令来简化和自动化繁琐且重复的任务。
如果您是网络管理员(network administrator),您会发现PowerShell有助于使用Active Directory。鉴于它包含数百个可自定义的命令(称为 cmdlet),PowerShell可以帮助您提高工作效率。我们推荐Ed Wilson 的(Ed Wilson's)书 - Windows PowerShell Step by Step - 以了解更多信息。如果您想了解最新版本的Windows PowerShell for Windows 10中的新功能,您还应该查看此(Windows 10)Microsoft(Microsoft web)官方网页:PowerShell 文档(PowerShell Documentation)。
PowerShell 与 PowerShell ISE
在标准命令行 shell(command-line shell)之上,您还可以找到Windows PowerShell ISE。ISE代表集成脚本环境(Integrated Scripting Environment),它是一个图形用户界面(user interface),允许您运行命令并创建、修改和测试脚本(modify and test scripts),而无需在命令行(command line)中键入所有命令。该工具允许开发脚本,这些脚本是命令的集合,您可以在其中添加复杂的执行逻辑。
ISE 工具(ISE tool)旨在满足Windows系统管理员的需要,这些管理员需要重复运行一系列命令来操作这些系统的配置。
您在哪里可以找到Windows中的(Windows)PowerShell?
在Windows中打开PowerShell的最快方法是使用任务栏中Cortana的搜索字段(search field)。输入关键字“powershell”,然后单击或点击Windows PowerShell搜索结果。
有关使用Windows 10(Windows 10)、Windows 8.1 和Windows 7的说明启动PowerShell的更多方法,请阅读本文:在Windows中启动(Windows)PowerShell的 9 种方法(包括以管理员身份)。
PowerShell 命令
PowerShell命令称为 cmdlet 。在PowerShell(PowerShell)中查找这些命令的最简单方法是运行“ Get-Command -Type Cmdlet ”。
这将生成PowerShell(PowerShell)中可用命令的完整列表。您可以滚动列表,直到找到正确的列表。PowerShell中的命令数量很大,因此我们提供了专门针对可以使用PowerShell完成的一项任务的文章(当出现多个时,请在每篇文章中搜索PowerShell 方法(PowerShell method)):
- 卸载 Windows 10 应用
- 重新安装所有Windows 10 默认应用(default apps)
- (Use PowerShell)使用PowerShell统计所有(Count All)文件和文件夹(Files And Folders)
- 在 Windows 中查找您的 IP 地址
- 从 Windows 中删除分区
- 打印正在运行的进程列表
- 查找任意网卡的(network card)MAC地址(MAC address)
在Microsoft 的本指南中(this guide from Microsoft),您可以找到示例脚本,让您了解如何使用PowerShell命令。
对于以前在命令提示符和 Linux(Command Prompt and Linux)方面有经验的用户,PowerShell有一个别名列表,这些别名将这些用户熟悉的名称与PowerShell命令相关联。这里有几个例子:cat、dir、mount、rm、chdir、erase、sort、cls、del。有关这些别名的完整列表,请在PowerShell中运行命令“ Get-Command -Type Alias ”。
谁倾向于定期使用PowerShell ?
毫无疑问,PowerShell是许多 IT 管理员的首选武器,因为它可以简化大型企业网络中的管理操作。
举个例子,假设您正在管理一个包含超过 500 台服务器的大型网络,并且您需要实施一个新的安全解决方案(security solution),该解决方案依赖于必须在这些服务器上运行的特定服务。当然,您可以登录到每台服务器并查看它们是否安装并运行了该服务。这是可能的,但您也可能会浪费太多时间来完成任务。如果您使用PowerShell,您可以在几分钟内完成该任务,因为整个操作只需一个脚本即可完成,该脚本收集有关您指定的服务器上运行的服务的信息并将它们转储到文本文件(text file)中。现在这就是生产力!
PowerShell 如何帮助您?
正如您在本文中看到的,Windows PowerShell是一个非常强大的工具,它包含在Windows中,并且可用于许多其他操作系统。它为高级用户和 IT 专业人员带来了许多好处。但是,临时用户也可以从使用它中受益。试试看,阅读我们的教程,让我们知道您对PowerShell的看法。在下面发表评论并分享您的观点。
What is PowerShell in Windows, and what you can do with it?
While many casual usеrѕ know abоut the Command Prompt, only a few have heard about Windows PowerShell. PowerShell is a much more powerful tool than the Command Prompt. It is also intended to replace the Cоmmаnd Prompt, as it delivers more power and control over the Windows оperating system. That's why we decided to get a taѕte of PowerShell and explain to all our readers what this tool is, why it is so powerful and who tends to use it more often. Let's see what PowerShell is and what you can do with it:
What is PowerShell in Windows?
To give you a better understanding of PowerShell, we should first define what a shell is. No, we're not talking about a turtle's shell. 🙂 In computer science, a shell is a user interface that gives you access to various services of an operating system. A shell can be command-line based, or it can include a graphical user interface (GUI).
Windows PowerShell is a shell initially developed by Microsoft for the purposes of task automation and configuration management. PowerShell is now an open source project, and it can be installed on Windows, macOS, and Linux platforms. This shell is based on the .NET framework, and it includes a command-line shell and a scripting language.
The first version of PowerShell was released in November 2006 for Windows XP, Windows Server 2003 and Windows Vista. The latest version of PowerShell is Windows PowerShell 5.1, and it is delivered 2016 as part of Windows 10 Anniversary Update and Windows Server 2016. It also works with Windows Server 2008 R2, Windows Server 2012 and Windows Server 2012 R2, Windows 7 Service Pack 1 and Windows 8.1 (Pro and Enterprise editions).
What can you do with PowerShell?
Microsoft designed Windows PowerShell as a tool that helps you automate and quickly solve a lot of tedious administration tasks. For example, you can use PowerShell to display all the USB devices installed on one or multiple computers in a network, or you can set a time-consuming task to run in the background while you do other work. You can also identify and kill processes that are not responding or filter specific information about computers in a network and export it in HTML format.
PowerShell's capabilities allow you to simplify and automate tedious and repetitive tasks by creating scripts and combining multiple commands.
If you are a network administrator, you find that PowerShell is helpful in working with Active Directory. Given that it contains hundreds of customizable commands, which are called cmdlets, PowerShell can be helpful in making you more productive. We recommend Ed Wilson's book - Windows PowerShell Step by Step - to learn more about it. If you desire to get a glimpse of what is new in the latest iteration of Windows PowerShell for Windows 10, you should also check this official Microsoft web page: PowerShell Documentation.
PowerShell vs PowerShell ISE
On top of the standard command-line shell, you can also find the Windows PowerShell ISE. ISE stands for Integrated Scripting Environment, and it is a graphical user interface that allows you to run commands and create, modify and test scripts without having to type all the commands in the command line. The tool allows the development of scripts which are collections of commands where you can add complex logic for their execution.
The ISE tool is designed for the needs of the administrators of Windows systems that need to run repeatedly sequences of commands that manipulate the configuration of these systems.
Where do you find PowerShell in Windows?
The fastest way to open PowerShell in Windows is to use Cortana's search field from the taskbar. Enter the keyword "powershell" and then click or tap the Windows PowerShell search result.
For more ways to launch PowerShell with instructions for Windows 10, Windows 8.1 and Windows 7, read this article: 9 ways to launch PowerShell in Windows (including as admin).
PowerShell commands
The PowerShell commands are called cmdlets. The easiest way to find these commands in PowerShell is to run "Get-Command -Type Cmdlet".
This produces the full list of commands available in PowerShell. You can scroll through the list until you find the right one. The number of commands in PowerShell is large, so we provide articles dedicated to one task that can be accomplished using PowerShell (search in each article for the PowerShell method when multiple ones are presented):
In this guide from Microsoft, you can find sample scripts that give you a good idea of using PowerShell commands.
For users with previous experience in Command Prompt and Linux, PowerShell has a list of aliases that associate names familiar to these users with the PowerShell commands. Here are a few examples: cat, dir, mount, rm, chdir, erase, sort, cls, del. For a full list of these aliases, run in PowerShell the command "Get-Command -Type Alias".
Who tends to use PowerShell regularly?
Without any doubt, PowerShell is the weapon of choice for many IT administrators, since it can simplify the management operations in large corporate networks.
To give you an example, let's say you are managing a large network containing over five hundred servers, and you need to implement a new security solution that is dependent on a specific service that has to run on those servers. You could, of course, log in to each server and see if they have that service installed and running. It is possible, but it is also likely that you waste too much time to finish the task. If you use PowerShell, you could complete that task in just a few minutes, since the whole operation can be done with only one script that gathers information about the services running on the servers you specify and dumps them into a text file, for instance. Now that's productivity!
How can PowerShell help you?
As you can see from this article, Windows PowerShell is an incredibly powerful tool that is included in Windows, and that is available for many other operating systems. It brings many benefits to power-users and IT professionals. However, casual users can benefit from using it too. Try it out, read our tutorials, and let us know your opinion about PowerShell. Leave a comment below and share your perspective.