PowerShell(包括Windows PowerShell和PowerShell Core)是微软公司开发的任务自动化和配置管理架构,由在.NET Framework和后来的.NET上构建的命令行界面壳层相关脚本语言组成,最初仅仅是Windows组件,后于2016年8月18日开源并提供跨平台支持。[4]
Quick Facts 编程范型, 设计者 ...
Close
在PowerShell中,管理任务通常由cmdlets(发音为command-lets)执行,这是执行特定操作的专用.NET类。可以将cmdlet集合至脚本、可执行文件(一般是独立应用程序)中,或通过常规.NET类(或WMI / COM对象)实例化。[5][6]
UNIX系统一直有着功能强大的壳程序(shell),Windows PowerShell的诞生就是要提供功能相当于UNIX系统的命令行壳程序(例如:sh、bash或csh),同时也内置脚本语言以及辅助脚本程序的工具。
- 一致性的设计让所有工具和系统资料的使用语法、命名原则都相同。
- 脚本语言简单易学,而且能支持现有的脚本程序和命令行工具。
- 内含129种称为cmdlet的标准工具,可用来处理常见的系统管理工作。
- 具备完整的扩展,独立软件商或开发者都能很容易的自行扩展。
- 进程间数据传递内容具有强类型特征。
- PowerShell Core可以自动检测字符编码,自动识别Linux和Windows下的换行符,跨平台运行。
cmdlet是Windows PowerShell的指令,发音念法为command-let。这相当于DOS或其他壳程序的内置指令,指令名称的格式都是以连字号(-)隔开的一对动词和名词,并且通常都是单数名词;例如在线查询说明的cmdlet指令为get-help,名称的动词部分大致有get、set、add、remove等等(字母都不分大小写)。
Windows PowerShell ISE是Windows PowerShell的主机应用程序。在此程序中,可以在单个Windows GUI中运行命令、编辑与测试脚本。此程序具有多行编辑、Tab补齐、上下文相关帮助、语法着色、选择性执行等功能,而且还支持从右到左的书写顺序等功能。
Windows PowerShell是以.NET Framework技术为基础,并且与现有的WSH保持回溯兼容,因此它的脚本程序不仅能访问.NET CLR,也能使用现有的COM技术。同时也包含了数种系统管理工具、简易且一致的语法,常见如登录数据库、WMI。Exchange Server 2007以及System Center Operations Manager 2007等服务器软件都将内置Windows PowerShell。
get-process p* | stop-process
- 停止所有目前执行中的所有使用大于1000MB存储器的程序:
get-process | where { $_.WS -gt 1000MB } | stop-process
get-childitem | measure-object -property length -sum
- 将"hello, world!"字符串转为英文大写字符,成为"HELLO, WORLD!":
"hello, world!".ToUpper()
- 订阅一个指定的RSS Feed并显示它最近8个主题:
$rssUrl = "http://blogs.msdn.com/powershell/rss.aspx"
$blog = [xml](new-object System.Net.WebClient).DownloadString($rssUrl)
$blog.rss.channel.item | select title -first 8
More information PowerShell(命令行), PowerShell(别名) ...
Close
尽管外部ping命令仍可用于PowerShell,但“Test-Connection”的输出是一个可以通过编程来检查的结构化对象。
While the external ping command remains available to PowerShell, Test-Connection's output is a structured object that can be programmatically inspected.[7]
Clear-Host被实现为预定义的PowerShell功能。
Available in Windows NT4, Windows 98 Resource Kit, Windows 2000 Support Tools
Available in Windows XP Professional Edition and later
Also used in UNIX to send a process any signal, the "Terminate" signal is merely the default
curl
and wget
aliases are absent from PowerShell Core, so as to not interfere with invoking similarly named native commands.
PowerShell 3.0 与 Windows 8 和 Windows Server 2012 集成。微软还为 Windows 7 的 Service Pack 1、Windows Server 2008 的 Service Pack 1 和 Windows Server 2008 R2 的 Service Pack 1 提供了 PowerShell 3.0。[8][9]
PowerShell 3.0 是一个更大的软件包 Windows Management Framework 3.0 (WMF3) (WMF3) 的一部分。
PowerShell 3.0 是一个更大的软件包 Windows 管理框架 3.0 (WMF3) 的一部分,其中还包含支持远程协作的 WinRM 服务。[10][11]
PowerShell 3.0 的新功能包括:[12][13]
- 计划任务:可使用 Windows 任务调度程序基础架构计划任务在预定的时间和日期运行。
- 会话重新连接:会话可以断开并重新连接。远程会话现在能更好地应对临时网络故障。
- 改进了代码编写:增加了代码自动完成(IntelliSense)和代码片段。PowerShell ISE 允许用户使用对话框填写 PowerShell cmdlet 参数。
- 授权支持:可将管理任务授权给无权执行此类任务的用户,而无需授予他们永久性的额外权限。
- 更新帮助:可使用 Update-Help 命令更新帮助文档。
WMF 3.0. www.microsoft.com. [2023-09-09]. (原始内容存档于2023-06-19).
- Oakley, Andy. Monad (AKA PowerShell). O'Reilly Media. 2005. ISBN 0-596-10009-4.
- Holmes, Lee. Windows PowerShell Quick Reference. O'Reilly Media. 2006. ISBN 0-596-52813-2.
- Holmes, Lee. Windows PowerShell Cookbook. O'Reilly Media. 2007. ISBN 0-596-52849-3.
- Watt, Andrew. Professional Windows PowerShell. Wrox Press. 2007. ISBN 0-471-94693-1.
- Kumaravel, Arul; White, Jon; Naixin Li, Michael; Happell, Scott; Xie, Guohui; Vutukuri, Krishna C. Professional Windows PowerShell Programming: Snapins, Cmdlets, Hosts and Providers. Wrox Press. 2008. ISBN 0-470-17393-9.
- Kopczynski, Tyson; Handley, Pete; Shaw, Marco. Windows PowerShell Unleashed 2nd. Pearson Education. 2009. ISBN 978-0-672-32988-3.
- Jones, Don; Hicks, Jeffery. Windows PowerShell 2.0: TFM 3rd. Sapien Technologies. 2010. ISBN 978-0-9821314-2-8.
- Finke, Douglas. Windows PowerShell for Developers. O'Reilly Media. 2012. ISBN 1-4493-2270-0.
- Wilson, Ed. Windows PowerShell 3.0 Step by Step. Microsoft Press. 2013. ISBN 978-0-7356-6339-8.
- Wilson, Ed. Windows PowerShell Best Practices. Microsoft Press. 2014. ISBN 978-0-7356-6649-8.