powershell例子

例子如下:

$ErrorActionPreference="Stop"

function getlist{
    ls D:\tmp2|select name,extension,fullname|export-csv -encoding oem list.csv
}

function do_continue{
    $xx=0
    while( $xx -lt 10){
        $xx++
        if($xx -eq 5){
            continue
        }
        write-host $xx   
    }
}

function do_break{
    $xx=0
    while($true){
        write-host $xx
        $xx++
        if($xx -gt 5){
            break
        }
    }
}

function do_for{
    for($ii=0;$ii -lt 10;$ii++){
        write-host $ii
    }
}

function do_foreach{
    foreach ($i in 1,2,3){
        write-host $i
    }
}

function do_logic{
    write-host (1+1) (2*3) (2/2)
    write-host (1 -lt 2);
    write-host (1 -gt 2);
    write-host (1,2,3 -contains 2);
    write-host (1,2,3 -notcontains 2);
    write-host ('one two' -match 'one')
    write-host ('one two' -notmatch 'one')
}

function do_function{

    Begin{
        write-host "begin"
    }
    
    Process{
        write-host "$_"
    }
    
    End{
        write-host "end"
    }
}

function do_input{
    1,2,3 |do_function
}

function do_hashtable{
    $hashx=@{msg1="message 1";meg2="message 2";msg3="message 3"}
    write-host $hashx["msg1"]
    $hashx
}

function do_switch{
    $ii=4
    switch($ii){
        1 {"one";break}
        2 {"two";break}
        3 {"three";break}
        Default{"default"}
    }
}

do_switch

#read-host "please enter to exit"

 

转载于:https://www.cnblogs.com/zhizhou/p/3657719.html

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值