1. <dd id="erndk"></dd>
                1. PowerShell - Loops

                  互聯網 2022/1/29 7:06:07

                  PowerShell - Loops If Statement # If statement with Zero else Statement $Number = 16 if ($Number -gt 10) { Write-Host "The value $Number is gerater than 10"}# If statement with ONE else Statement $Number = 8 if ($Number -gt 10) { Write-Host …

                  PowerShell - Loops

                  If Statement
                  # If statement with Zero else Statement
                  $Number = 16
                  if ($Number -gt 10)
                  { Write-Host "The value $Number is gerater than 10"}
                  
                  # If statement with ONE else Statement
                  $Number = 8
                  if ($Number -gt 10)
                  { Write-Host "The value $Number is greater than 10"}
                  else
                  { Write-Host "The value $Number is less than or equal to 10"}
                  
                  #####################################################################
                  # If Statement with ZERO elseif Statement
                  $Number = 16
                  if ($Number -gt 10)
                  { Write-Host "The value $Number is greater than 10"}
                  else
                  { Write-Host "The value $Number is less than or equal to 10"}
                  
                  # If Statement with ONE elseif statement
                  $Number = 16
                  if ($Number -gt 10)
                  { Write-Host " Number is greater than 10"}
                  elseif ($Number -eq 10)
                  { Write-Host " Number si equal to 10"}
                  else
                  { Write-Host " Number is less than or equal to 10"}
                  
                  # Ternary Operater (Introduced In PowerShell 7.0)
                  2 -eq 3 ? "This is True":"This is False"
                  
                  Foreach Loop
                  ####################################################################
                  #*************** PowerShell Foreach Loop ***************************
                  ####################################################################
                  
                  # Running foreach Loop as a command
                  $fruits = "Apple", "Orange", "KiWi"; foreach ($Item in $fruits){"This is $Item"}
                  # Running foreach Loop in a Script
                  $fruits = "Apple", "Orange", "KiWi"
                  foreach ($Item in $fruits)
                  {
                  "This is $Item"
                  }
                  # Using foreach against Command Output
                  foreach ($Service in Get-Service)
                  {
                  "This is $(($Service).displayname)"
                  }
                  
                  While Loop
                  ####################################################################
                  #*************** PowerShell While Loop ***************************
                  ####################################################################
                  # Using while loop to return Items of any Array or Collection
                  $List = 15..18
                  $i = 0
                  While ($i -le $list.count) {$list[$i];$i++}
                  # Using PowerShell While Loop in Interactive way
                  $i = 0
                  $answer = Read-Host -Prompt "Write further Count ? => Yes or No"
                  while($answer -like "Yes"){$i;$answer = Read-Host -Prompt "Enter";$i++}
                  

                  image-20220128144349183

                  Do Loop
                  ####################################################################
                  #*************** PowerShell Do Loop ********************************
                  ####################################################################
                  #*************** Do-While Loop *************************************
                  ####################################################################
                  
                  # Using do-while loop to read contents of an Array or Collection
                  $list = 1..8
                  $i = 0
                  do{$List[$i];$i++} while ($i -le $list.count)
                  # Using Do-while loop Interactively
                  $i = 0
                  do{$i;$i++;$answer = Read-Host -Prompt "Write further Count ? => Yes or No"} while($answer -like "Yes")
                  

                  image-20220128145950785

                  #*************** Do-Until Loop *************************************
                  ####################################################################
                  
                  # Using do-until loop to read contents of an Array or Collection
                  $list = 1..8
                  $i = 0
                  do{$List[$i];$i++} until ($i -eq $list.count)
                  # Using Do-until loop Interactively
                  $i = 0
                  do{$i;$i++;$answer = Read-Host -Prompt "Write further Count ? => Yes or No"} until ($answer -like "no")
                  
                  For Loop
                  # For Loop
                  # Syntax ==> for (<Init>; <Condition>; <Repeat>) {<Statement list>}
                  for ($i = 0;$I -le 8;$i++) {$i}
                  
                  # Different Variables in Statement list
                  $Count = 0
                  for ($i = 0;$I -le 8;$i++) {"$Count Apple"; $Count++}
                  
                  # Using multiple commands in init and repeat portion, Usinf multiple Conditions
                  for (($i = 0), ($m = 100);$I -le 100 -and $m -ge 100;$i++, $m++) {"$i is $m"}
                  
                  # Some Fun
                  $i = 0
                  for(;;) {$i;$i++}
                  
                  # For Loop with Interaction
                  for(($i = 0), ($answer = Read-Host -Prompt "Write further Count ? => Yes or No");$answer -like "Yes";$i++)
                  {$i;$answer = Read-Host -Prompt "Write further Count ? => Yes or No"}
                  

                  image-20220128152731723

                  隨時隨地學軟件編程-關注百度小程序和微信小程序
                  關于找一找教程網

                  本站文章僅代表作者觀點,不代表本站立場,所有文章非營利性免費分享。
                  本站提供了軟件編程、網站開發技術、服務器運維、人工智能等等IT技術文章,希望廣大程序員努力學習,讓我們用科技改變世界。
                  [PowerShell - Loops]http://www.yachtsalesaustralia.com/tech/detail-291381.html

                  贊(0)
                  關注微信小程序
                  程序員編程王-隨時隨地學編程

                  掃描二維碼或查找【程序員編程王】

                  可以隨時隨地學編程啦!

                  技術文章導航 更多>
                  国产在线拍揄自揄视频菠萝

                        1. <dd id="erndk"></dd>