Windows Azure Poweshell实例小脚本测试
说明:这些东东,是现学现用的,也不难。。。
一、Poweshell 中符合定义
点击(此处)折叠或打开
-
整数比较:
-
-eq 等于 if [ "$a" -eq "$b" ]
-
-ne 不等于 if [ "$a" -ne "$b" ]
-
-gt 大于 if [ "$a" -gt "$b" ]
-
-ge 大于等于 if [ "$a" -ge "$b" ]
-
-lt 小于 if [ "$a" -lt "$b" ]
-
-le 小于等于 if [ "$a" -le "$b" ]
-
< 小于(需要双括号) (( "$a" < "$b" ))
-
<= 小于等于(...) (( "$a" <= "$b" ))
-
> 大于(...) (( "$a" > "$b" ))
-
>= 大于等于(...)
|
-
实例取偶数
-
$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"
阅读(4549) | 评论(0) | 转发(0) |