<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      架構人生

      PowerShell學習筆記[分享]

      數組其實在任何語言里都是一個比較頭疼的學習對象,在學習PowerShell的空余時間,做了以下簡單整理:

       

      1. 在PowerShell中,只要把不同的對象用逗號“,”連接起來,就可以構造出數組對象。

      例如:520,'abc',2MB,0xFFFE

      520

      abc

      2097152

      65534

      上面的小例子輸出了4個對象:數值“520”、字符串“abc”、數值“2MB”和十六進制數值“0xFFFE”。

      2. 關于數組對象更多的特性:

      $array = 1,2,3,4,5

      $int = 1

      $array.count

      5 

      "$array"

      1 2 3 4 5

      $int.count

      "$int"

      1

      以上$int是一個整數,而不是數組。

      3. PowerShell是基于對象的shell,現在讓我們來看看數組究竟是什么對象:

      $array.GetType().FullName

      System.Object[]

      其實Powershell實際操作的對象還是.Net類庫中的對象。使用數組時,需要大家記住數組的第一個元素的下標是“0”、數組的最后一個元素下標是數組長度減去1。例如:

      $array = 1,2,3

      $array.Length

      3

      $array[0]

      1

      $array[2]

      3

       

      實際上,當數組訪問越界時,PowerShell是不會給出任何錯誤信息的,只會得到一個$null對象,如$array[4]

      3. 如何向這個數組中添加新的元素呢

      $a = " I ", " am "

      $a[0]

      I 

      $a[1]

      am

      $a[2] = " Lihua "

      Array assignment failed because index '2' was out of range.
              At line:1 char:4
              + $a[2 <<<< ]=" Lihua "

      雖然如此,但PowerShell可以通過$a[0]="we"來修改數組元素值。另外添加則需要:

      $a = $a + " Lihua "

      $a

      I am Lihua

       

       最后補充一下學習PowerShell中的系統cmdlets技巧:

      我寫了一個批量輸出幫助文件,并只輸出Examples的例子,希望對你學習有幫助。

      $d = Get-Command -CommandType Cmdlet
      "Total:" + $d.Count
      $i = 0
      $d | ForEach-Object -process{
          
      $i++
          
      "Printing" + $i
          
      $cmdlet = $_.Name
          
      $path = ".\EXAMPLE\"+$cmdlet + ".ps1"
          Get
      -Help -Examples $cmdlet > $path
      }
      "Successfully"
      #test

      以下是執行上面腳本后輸出的結果:

      然后我們打開其中一個文件看一下:


      NAME
          
      ForEach-Object
          
      SYNOPSIS
          Performs an operation against each of a set of input objects.
          
          
      -------------------------- EXAMPLE 1 --------------------------
          
          C:\PS
      >30000,56798,12432 | foreach-object -process {$_/1024}
          
          
          This command accepts an array of integers, divides each one of them by 
      1024, and displays the r
          esults.
          
          
          
          
          
      -------------------------- EXAMPLE 2 --------------------------
          
          C:\PS
      >get-childitem C:\ | foreach-object -process { $_.length / 1024 }
          
          
          This command retrieves the files and directories 
      in the root of the C: drive and returns and di
          splays the size of each of them. The zeroes represent directories where no file size was availa
          ble.
          
          
          
          
          
      -------------------------- EXAMPLE 3 --------------------------
          
          C:\PS
      >$events = get-eventlog -logname system -newest 1000
          
      $events |
          
      foreach-object -begin {get-date}
          
      -process {out-file -filepath events.txt -append -inputobject $_.message}
          
      -end {get-date}
          
          
          This command retrieves the 
      1000 most recent events from the system log and stores them in the $
          events variable. It then pipes the events to the 
      ForEach-Object cmdlet. The Begin parameter dis
          plays the current date and time. Next, the 
      Process parameter uses the Out-File cmdlet to create
           a text file named events.txt and stores the message property of each of the events 
      in that fil
          e. Last, the 
      End parameter is used to display the date and time after all of the processing has
           completed.
          
          
          
          
          
      -------------------------- EXAMPLE 4 --------------------------
          
          C:\PS
      >get-itemproperty -path hkcu:\Network\* |
           
      foreach-object {set-itemproperty -path $_.pspath -name RemotePath 
          
      -value $_.RemotePath.ToUpper();}
          
          
          This command updates a set of registry entries by using the Set
      -ItemProperty cmdlet. The regist
          ry entries specify the UNC path of mapped network drives on the computer. This command changes 
          the characters 
      in the UNC path to uppercase. In a real scenario, you might need to change the s
          erver name or another component of the path. 
          
          Because the Set
      -ItemProperty cmdlet acts on a single property, the ForEach-Object cmdlet is use
          d to call Set
      -ItemProperty for each property (registry entries in this case) being changed. The
           name of the registry entries is RemotePath and they are located 
      in HKCU\Network\<mapped drive 
          letter
      >. The entries are retrieved by using the Get-ItemProperty cmdlet and piped as input to F
          orEach
      -Object. In the call to Set-ItemProperty within ForEach-Object, the $_ variable holds a r
          eference to the current registry entry being processed. The value of the PSPath property is the
           registry key containing the current entry. The RemotePath property is of type System.String, w
          hich includes the ToUpper method used to change the value of the entry to uppercase.
          

      你會發現這對我們學習陌生的cmdlets非常實用。 由于我的系統是英文的,Powershell也是英文版的,所以例子與解說都是英文的。

       

      另外,如果你需要對自定義的cmdlets作以上的輸出,而不需要輸出系統的cmdlets,可以做如下改進:

      #This is a patch output for only customized cmdlets
      $d =  Get-Command -PSSnapin Zivsoft.PowerShell.Cmdlets
      "Total:" + $d.Count
      $i = 0
      $d | ForEach-Object -process{
          
      $i++
          
      "Printing" + $i
          
      $cmdlet = $_.Name
          
      $path = ".\CmdletsUsage\"+$cmdlet + ".ps1"
          Get
      -Help -Examples $cmdlet > $path
      }
      "Successfully"

      執行后,會將系統的過濾掉不輸出。

      最后,細心人可以看出我的腳本還是有很多漏洞,比如直接用"successfully"判斷成功,其實不對的,但我想不到其它好的辦法,由于不影響大局,代碼沒做過多改進。

      posted on 2009-04-27 16:48  智艾悅  閱讀(2308)  評論(5)    收藏  舉報

      導航

      主站蜘蛛池模板: 久久欧洲精品成av人片| 亚洲日韩在线中文字幕第一页 | 国产成人高清精品亚洲| 国产精品亚洲精品日韩已满十八小| 男女爽爽无遮挡午夜视频| 老司机午夜福利视频| 动漫AV纯肉无码AV电影网| 久久成人 久久鬼色| 人妻系列中文字幕精品| 亚洲一二三区精品与老人| 国产一级r片内射免费视频| Y111111国产精品久久久| 久热这里有精品免费视频| 国产成人午夜福利在线播放| 东京热人妻无码一区二区av| 日韩淫片毛片视频免费看| 国产精品二区中文字幕| 国精品无码一区二区三区左线| аⅴ天堂中文在线网| 亚洲线精品一区二区三区| 亚洲精品久久一区二区三区四区| 亚洲最大福利视频网| 国产精品一区二区日韩精品| 成全影院电视剧在线观看| 苍井空毛片精品久久久| 国产国产精品人体在线视| 久久精品国产亚洲av热一区| 亚洲人成电影网站 久久影视| 国产一区在线播放无遮挡| 亚洲精品国偷拍自产在线观看蜜臀| 中国熟妇毛多多裸交视频| 亚洲国产精品美日韩久久| 91青青草视频在线观看的| 最近免费中文字幕大全| 国产极品粉嫩尤物一线天| 国产精品一二三区蜜臀av| 最新国产AV最新国产在钱| 久久亚洲国产欧洲精品一| 日韩精品一区二区三区中文无码| 夜夜添狠狠添高潮出水| 久久亚洲女同第一区综合|