热门问题
时间线
聊天
视角

PowerShell

任务自动化和组态管理框架 来自维基百科,自由的百科全书

PowerShell
Remove ads

PowerShell(包括Windows PowerShellPowerShell Core)是微软公司开发的任务自动化和组态管理架构,由在.NET Framework和后来的.NET上构建的命令行界面壳层相关脚本语言组成,最初仅仅是Windows元件,后于2016年8月18日开源并提供跨平台支持。[5]

事实速览 编程范型, 设计者 ...

在PowerShell中,管理任务通常由cmdlets(发音为command-lets)执行,这是执行特定操作的专用.NET。可以将cmdlet集合至脚本、可执行文件(一般是独立应用程序)中,或通过常规.NET类(或WMI / COM对象)实例化。[6][7]

Remove ads

源起与目的

UNIX系统一直有著功能强大的壳程式(shell),Windows PowerShell的诞生就是要提供功能相当于UNIX系统的命令列壳程式(例如:shbashcsh),同时也内建脚本语言以及辅助脚本程式的工具。

程式特性

  • 一致性的设计让所有工具和系统资料的使用语法、命名原则都相同。
  • 脚本语言简单易学,而且能支援现有的脚本程式和命令列工具。
  • 内含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补齐、上下文相关帮助、语法着色、选择性执行等功能,而且还支持从右到左的书写顺序等功能。

Remove ads

技术基础

Windows PowerShell是以.NET Framework技术为基础,并且与现有的WSH保持回溯相容,因此它的脚本程式不仅能存取.NET CLR,也能使用现有的COM技术。同时也包含了数种系统管理工具、简易且一致的语法,常见如登录资料库、WMI。Exchange Server 2007以及System Center Operations Manager 2007等伺服器软体都将内建Windows PowerShell。

范例

  • 停止所有目前执行中的以"p"字元开头命名的程式:
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
Remove ads

命令提示字元比较

更多信息 PowerShell(命令行), PowerShell(别名) ...
  1. 尽管外部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.[8]
  2. Clear-Host被实现为预定义的PowerShell功能。
  3. Available in Windows NT4, Windows 98 Resource Kit, Windows 2000 Support Tools
  4. Available in Windows XP Professional Edition and later
  5. Also used in UNIX to send a process any signal, the "Terminate" signal is merely the default
  6. curl and wget aliases are absent from PowerShell Core, so as to not interfere with invoking similarly named native commands.
Remove ads

Windows PowerShell 3.0

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。[9][10]

PowerShell 3.0 是一个更大的软件包 Windows Management Framework 3.0 (WMF3) (WMF3) 的一部分。 PowerShell 3.0 是一个更大的软件包 Windows 管理框架 3.0 (WMF3) 的一部分,其中还包含支持远程协作的 WinRM 服务。[11][12]

PowerShell 3.0 的新功能包括:[13][14]

  • 计划任务:可使用 Windows 任务调度程序基础架构计划任务在预定的时间和日期运行。
  • 会话重新连接:会话可以断开并重新连接。远程会话现在能更好地应对临时网络故障。
  • 改进了代码编写:增加了代码自动完成(IntelliSense)和代码片段。PowerShell ISE 允许用户使用对话框填写 PowerShell cmdlet 参数。
  • 授权支持:可将管理任务授权给无权执行此类任务的用户,而无需授予他们永久性的额外权限。
  • 更新帮助:可使用 Update-Help 命令更新帮助文档。
Remove ads

参考文献

扩展阅读

外部链接

Loading related searches...

Wikiwand - on

Seamless Wikipedia browsing. On steroids.

Remove ads