windows 7 与 PowerShell 2.0

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@CSDN
可以通过两种方式来查看:
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@CSDN

3. 已经发布 3.0 了。。。
2011年年底(12月)发布了 3.0
//z 2012-3-2 18:02:51 PM IS2120@CSDN
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命令。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值