zoukankan      html  css  js  c++  java
  • powershell例子

    例子如下:

    $ErrorActionPreference="Stop"
    
    function getlist{
        ls D:	mp2|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"
  • 相关阅读:
    登录保存用户信息
    GRIDVIEW单击事件
    GRIDVIEW单击双击事件
    gridview打印
    水晶报表
    CRYSTAL net样式
    Web Server 在IIS上部署ASP.NET Core项目
    MVC MVC+EF快速搭建
    MVC MVC常见错误及解决办法
    Open Interface Service WCF三种通信模式
  • 原文地址:https://www.cnblogs.com/zhizhou/p/3657719.html
Copyright © 2011-2022 走看看