Windows Azure Poweshell实例小脚本测试
   说明:这些东东,是现学现用的,也不难。。。
一、Poweshell 中符合定义

点击(此处)折叠或打开
  1. 整数比较:
  2. -eq 等于 if [ "$a" -eq "$b" ]
  3. -ne 不等于 if [ "$a" -ne "$b" ]
  4. -gt 大于 if [ "$a" -gt "$b" ]
  5. -ge 大于等于 if [ "$a" -ge "$b" ]
  6. -lt 小于 if [ "$a" -lt "$b" ]
  7. -le 小于等于 if [ "$a" -le "$b" ]
  8. < 小于(需要双括号) (( "$a" < "$b" ))
  9. <= 小于等于(...) (( "$a" <= "$b" ))
  10. > 大于(...) (( "$a" > "$b" ))
  11. >= 大于等于(...)


点击(此处)折叠或打开

  1. 实例取偶数
  2. $NUM = 100..110
  3. foreach ( $N in $NUM ) {
  4. if (( $N % 2 -ne 0 )) {
  5. continue
  6. }
  7. $N
  8. }
  9. 实例取数组前两个
  10. $NUM = 100..110
  11. foreach ($m in $NUM) {
  12. foreach ($i in (0..1))
  13. {
  14. #$N=$NUM[$i];
  15. $SN=$m+$i
  16. Write-host "The "$SN
  17. # break $OutID;
  18. }
  19. # Write-host "Hello "$N
  20. }
  21. 实例:break终止innerItem这个内部循环
  22. foreach ( $outerItem in 1..3 ){
  23. Write-Host "OuterItem:$outerItem"
  24. foreach( $innerItem in 1..3 )
  25. {
  26. Write-Host "InnerItem:$innerItem"
  27. #continue在终止内部循环的同时开始执行外部循环
  28. # continue;
  29. break;
  30. }
  31. }
  32. 实例终止外部循环
  33. :Out foreach ( $outerItem in 1..3 ){
  34. Write-Host "OuterItem:$outerItem"
  35. foreach( $innerItem in 1..3 )
  36. {
  37. Write-Host "InnerItem:$innerItem"
  38. break Out;
  39. }
  40. }
  41. 结果:
  42. OuterItem:1
  43. InnerItem:1
  44. 实例:do-While循环
  45. $i = 0
  46. do {
  47. $i ++
  48. Write-Host $i
  49. #break;
  50. }while (($i -ne 10))
  51. 实例:do-until循环,等同于do-while
  52. $i = 0
  53. do {
  54. $i ++
  55. Write-Host $i
  56. #break;
  57. }until (-not($i -ne 10))
  58. 函数写法:
  59. function toUpper {
  60. $args[0].toUpper()
  61. }
  62. toUpper "james"
10-04 03:37