windows 7 与 PowerShell 2.0

本文深入探讨了Windows PowerShell 2.0及3.0版本的功能特点,包括查看版本信息的方法,如通过Get-Host、$host变量和$PSVersionTable变量。同时介绍了在Windows 7中启动PowerShell的不同方式,包括通过开始菜单、附件和传统CMD窗口。此外,文章详细说明了PowerShell的两种启动模式:命令行模式和集成脚本环境,并提供了如何在PowerShell环境中运行命令和脚本的实例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2012.9.4 发布了 POWERSHELL 3.0


windows 7 与 PowerShell 2.0


windows 7 不需要下载安装 PowerShell 2.0 了,在windows 7发布的时候已经内置了 PowerShell 2.0
对于 windows 2008 R2来说,也是如此。

//z 2012-3-2 18:02:51 PM IS2120@优快云
可以通过两种方式来查看:
1.  get-host
Name             : ConsoleHost
Version          : 2.0
InstanceId       : 64afc087-40cb-4b55-b3d3-d9dd389cb2eb
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : en-US
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace


2. $PSVersionTable 环境变量
该变量只在版本2.0中定义了

Name                           Value
----                           -----
CLRVersion                     2.0.50727.5448
BuildVersion                   6.1.7601.17514
PSVersion                      2.0
WSManStackVersion              2.0
PSCompatibleVersions           {1.0, 2.0}
SerializationVersion           1.1.0.1
PSRemotingProtocolVersion      2.1
//z 2012-3-2 18:02:51 PM IS2120@优快云

3. 已经发布 3.0 了。。。
2011年年底(12月)发布了 3.0
//z 2012-3-2 18:02:51 PM IS2120@优快云
4. 类似 grep
Example of grep -R equivilant: Get-ChildItem -recurse -include *.txt | Select-String -CaseSenstive "SomeString"
Get-ChildItem -recurse -include *.txt | Select-String -CaseSensitive "SomeString"

function pgrep { param([string]$search, [string]$inc) Get-ChildItem -recurse -include $inc | Select-String -CaseSensitive $search }
pgrep SomeStringToSearch *.txt
Then to really make it magical, add the function alias to your PowerShell Profile and you can almost dull the pain of not having proper command line tools.

提供三种方法

1. 直接使用 Get-Host

PS C:\Users\TopSage> Get-Host

Name             : ConsoleHost
Version          : 2.0
InstanceId       : b354f4bf-ff4e-452a-b747-78267a914c0a
UI               : System.Management.Automation.Internal.Host.InternalHostUserInterface
CurrentCulture   : zh-CN
CurrentUICulture : en-US
PrivateData      : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
IsRunspacePushed : False
Runspace         : System.Management.Automation.Runspaces.LocalRunspace


2. 使用$host变量

PS C:\Users\TopSage> $host.version

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1


3. 检查$PSVersionTable变量,PS2里有$PSVersionTable变量,而PS1里没有

PS C:\Users\TopSage> if (test-path variable:psversiontable) {$psversiontable.psversion} else {[version]"1.0.0.0"}

Major  Minor  Build  Revision
-----  -----  -----  --------
2      0      -1     -1

//z 2014-04-23 15:30:34 L.252 BG57IV3@XCL T138147975 .K.F253293061 [T286,L3964,R187,V5273]
启动PowerShell

  在Win7中点击“开始→所有程序”,在“附件”中有个Windows PowerShell,点击展开Windows PowerShell,里面有Windows PowerShell ISE和Windows PowerShell这两个选项(图1),后者是CMD那样的命令行模式界面,前者是图形化的PowerShell开发环境、包含了调试功能和交互式控制台,适合PowerShell编程的用户使用。

  除了以上方法能启动PowerShell,在传统的CMD窗口中输入PowerShell回车也能启动PowerShell,与CMD不同,PowerShell的提示符是PS开头的(图2);

  如要启动PowerShell ISE,可以点击“开始→所有程序→附件→Windows PowerShell→Windows PowerShell ISE”,这是一个集成的脚本环境(图3),里面有3个窗格,在顶部窗格中你可以练习编程创建或编辑脚本,中间是运行结果,最下方窗格中能输入运行 PowerShell命令。


转载于:https://www.cnblogs.com/IS2120/archive/2012/03/02/6745935.html

Microsoft Windows PowerShell 是一种新的命令行外壳和脚本语言,用于进行系统治理和自动化。Windows PowerShell 建立在 .NET Framework 的基础上,IT 专业人员可通过命令或脚本来治理计算机,从而通过系统自动化来提高工作效率。 Windows PowerShell 包括: * 129 个命令行工具(称为“cmdlet”),用于执行常见系统治理任务,如治理服务、进程、事件日志、证书、注册表以及使用 Windows Management Instrumentation (WMI)。 * 采用标准命名约定和通用参数的命令行工具,易于把握和使用;以及用于对数据和对象进行排序、筛选以及格式设置的简便工具。 * 对现有脚本语言、现有命令行工具以及多种 Windows 版本的支持,其中包括 Windows XP、Windows Server 2003、Windows Vista 以及 Windows Server(代码名称为“Longhorn”)。 * 方便的功能,使用户能够浏览数据存储(如注册表和证书存储),就像面对文件系统一样。 * 用于治理位于不同存储中以及采用不同格式的 Windows 数据的标准实用程序,这些数据包括 Active Directory (ADSI)、Windows Management Instrumentation (WMI)、组件对象模型 (COM) 对象、ActiveX 数据对象 (ADO)、HTML 和 XML。 * 在命令行进行的高级表达式分析和 .NET 对象处理,其中包括对对象进行流水线处理以帮助提高 IT 专业人员的工作效率。 * 可扩展的接口,使独立软件供给商和企业开发人员能够构建自定义 cmdlet 以满足特有的应用程序和系统治理要求。 安装本更新程序后,可能需要重新启动计算机。我们根据 Windows Vista 许可条款向您提供本更新程序并授予您使用许可。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值