• 用PowerShell寫Event Log
    • $a = new-object -type system.diagnostics.eventlog -argumentlist system   #寫到事件紀錄器的系統
    • $a.source = "Windows PowerShell Week"  #事件來源
    • $a.writeentry("This is just a test.","Information") #前者為事件內容 後者為事件的種類(包含 Error,FailureAudit,Information,SuccessAudit,Warning)
    • 一個source只能連結一種事件(應用程式,系統,安全性)
    • Remote Computer
      • $a = new-object -type system.diagnostics.eventlog -argumentlist system,ComputerName
  • PowerShell Formating Files
    • 一樣的get-process 得到不同的output
    • $PSHOME中的dotnettypes.format.ps1xml
    • <View>
          <Name>process</Name>
              <ViewSelectedBy>
                <TypeName>.NET Class Name</TypeName>
              </ViewSelectedBy>.....
      • System.Diagnostics.Process
    • <View>
          <Name>process</Name>
              <ViewSelectedBy>
                <TypeName>.NET Class#WMI namespace</TypeName>
              </ViewSelectedBy>.....
      • System.Management.ManagementObject#root\cimv2\Win32_BIOS
    • <TableControl>
        <TableHeaders>
           <TableColumnHeader>
              <Label>自訂欄位名稱</Label>
              <Width>寬度</Width>              #字元數
              <Alignment>對齊</Alignment> # left,right,center
           </TableColumnHeader>
       </TableHeaders>
    • <TableRowEntries>
          <TableRowEntry>
            <TableColumnItems>
              <TableColumnItem>
                <PropertyName>欄位名</PropertyName>
              </TableColumnItem>
            </TableColumnItems>
          </TableRowEntry>
      </TableRowEntries>
      • 如何得到真實欄位名
        • get-process | get-member
    • <TableColumnItem>
         <PropertyName>欄位名</PropertyName> 
          <ScriptBlock>[math]::round(($_.欄位名)/1024)</ScriptBlock>
      </TableColumnItem>
    • Adding a Custom Format File #增加客制化格式檔案
      • update-formatdata -prependpath 檔案路徑 # look this first
  • PowerGadgets
    • www.PowerGadgets.com
    • add-pssnapin PowerGadgets
      • get-wmiobject win32_perfformatteddata_perfdisk_logicaldisk | select-object name,percentfreespace | where-object {$_.Name -eq "_Total"} | out-gauge
    • 有很多漂亮的UI以顯示PowerShell的結果
創作者介紹

PowerShell@HungYuWu

ayowu 發表在 痞客邦 PIXNET 留言(0) 人氣()