# Powershell ForEach-Object 循环
# 对管道对象逐个处理
# 如果使用Get-WmiObject 获取系统中的服务,为了排版可能会也会使用Format-Table对结果进行表格排版。
# Get-WmiObject Win32_Service | Format-Table status,DisplayName
# Get-WmiObject win32_service | ForEach-Object {"Name"+$_.displayName,",processid more than 100:"+($_.prossedId -gt 100)}
# Powershell Foreach 循环
# $array=7..10
# foreach ($n in $array)
# {
# $n*$n
# }
# foreach($file in dir C:\Windows)
# {
# if($file.Length -gt 1mb){
# $file.Name
# }
# }
# Powershell Do While 循环
# 继续与终止循环的条件
# do-while()会先执行再去判断,能保证循环至少执行一次。
#Read-Host从控制台读取一行输入。可以使用它来提示用户输入数据。因为可以将输入保存为安全字符串
# do{
# $n=Read-Host
# }while($n -ne 0)
# 单独使用While
# $n=5
# while($n -gt 0){
# $n
# $n=$n-1
# }
# 终止当前循环
# 使用continue关键字终止当前的循环
# $n=1
# while($n -lt 6){
# if($n -eq 4){
# $n=$n+1
# continue
# }else{
# $n
# }
# $n=$n+1
# }
# 跳出循环语句
# $n=1
# whi
Powershell循环
最新推荐文章于 2025-04-28 15:36:59 发布