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.
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
PS C:\Users\TopSage> $host.version
Major Minor Build Revision
----- ----- ----- --------
2 0 -1 -1
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命令。