Windows Powershell Foreach 循环
更新时间:2014年10月02日 12:08:28 投稿:hebedich
Foreach-object 为cmdlet命令,使用在管道中,对管道结果逐个处理,foreach为遍历集合的关键字。
下面举两个例子:
复制代码 代码如下:
$array=7..10
foreach ($n in $array)
{
$n*$n
}
#49
#64
#81
#100
foreach($file in dir c:\windows)
{
if($file.Length -gt 1mb)
{
$File.Name
}
}
#explorer.exe
#WindowsUpdate.log
这里只为了演示foreach,其实上面的第二个例子可以用Foreach-Object更简洁。
复制代码 代码如下:
PS C:\Powershell> dir C:\Windows | where {$_.length -gt 1mb} |foreach-object {$_.Name}
explorer.exe
WindowsUpdate.log
相关文章
探索PowerShell (二) PowerShell的基本操作
这里介绍下如何打开powershell控制台,在 程序>附件>windows powershell中即可,主要是界面不再是dos窗口,据说功能也增加了很多2012-12-12


最新评论