Windows Powershell Foreach 循环 Windows Powershell Foreach 循环

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

Windows Powershell Foreach 循环 Windows Powershell Foreach 循环

  2021-03-19 我要评论
想了解Windows Powershell Foreach 循环的相关内容吗,在本文为您仔细讲解Windows Powershell Foreach 循环的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:Windows,Powershell,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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们