hebedich 通过本文主要向大家介绍了powershell foreach,windows powershell,windowspowershell2.0,windows powershell64,windows10 powershell等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
下面举两个例子:
$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
</div>
这里只为了演示foreach,其实上面的第二个例子可以用Foreach-Object更简洁。
PS C:\Powershell> dir C:\Windows | where {$_.length -gt 1mb} |foreach-object {$_.Name}
explorer.exe
WindowsUpdate.log
</div>

