您现在的位置是:网站首页> 编程资料编程资料
Windows Powershell Foreach 循环_PowerShell_
2023-05-26
527人已围观
简介 Windows Powershell Foreach 循环_PowerShell_
下面举两个例子:
复制代码 代码如下:
$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
您可能感兴趣的文章:
相关内容
- Windows Powershell ForEach-Object 循环_PowerShell_
- Windows Powershell Switch 语句_PowerShell_
- Windows Powershell IF-ELSEIF-ELSE 语句_PowerShell_
- Windows Powershell Where-Object 条件过滤_PowerShell_
- Windows Powershell条件表达式之条件操作符_PowerShell_
- Windows Powershell创建对象_PowerShell_
- Powershell小技巧之去除多余的空格_PowerShell_
- Powershell小技巧之创建短网址_PowerShell_
- Powershell小技巧之查找脚本中的函数_PowerShell_
- Powershell小技巧之保存服务信息_PowerShell_
