Windows Azure Poweshell实例小脚本测试
说明:这些东东,是现学现用的,也不难。。。一、Poweshell 中符合定义
点击(此处)折叠或打开
|
点击(此处)折叠或打开
- 实例取偶数
- $NUM = 100..110
- foreach ( $N in $NUM ) {
- if (( $N % 2 -ne 0 )) {
- continue
- }
- $N
- }
- 实例取数组前两个
- $NUM = 100..110
- foreach ($m in $NUM) {
- foreach ($i in (0..1))
- {
- #$N=$NUM[$i];
- $SN=$m+$i
- Write-host "The "$SN
- # break $OutID;
- }
- # Write-host "Hello "$N
- }
- 实例:break终止innerItem这个内部循环
- foreach ( $outerItem in 1..3 ){
- Write-Host "OuterItem:$outerItem"
- foreach( $innerItem in 1..3 )
- {
- Write-Host "InnerItem:$innerItem"
- #continue在终止内部循环的同时开始执行外部循环
- # continue;
- break;
- }
- }
- 实例终止外部循环
- :Out foreach ( $outerItem in 1..3 ){
- Write-Host "OuterItem:$outerItem"
- foreach( $innerItem in 1..3 )
- {
- Write-Host "InnerItem:$innerItem"
- break Out;
- }
- }
- 结果:
- OuterItem:1
- InnerItem:1
- 实例:do-While循环
- $i = 0
- do {
- $i ++
- Write-Host $i
- #break;
- }while (($i -ne 10))
- 实例:do-until循环,等同于do-while
- $i = 0
- do {
- $i ++
- Write-Host $i
- #break;
- }until (-not($i -ne 10))
- 函数写法:
- function toUpper {
- $args[0].toUpper()
- }
- toUpper "james"