1.在powershell世界裡都是由物件組成,包含property與method
2.善用 pipeline: | Out-Host -Paging,以下兩種指令對於CPU與Memory的消耗有很大的差異:
Get-ChildItem C:\Windows -Recurse
Get-ChildItem C:\Windows -Recurse | Out-Host -Paging
3.分析物件有什麼屬性與方法可以透過將輸出pipe到Get-Member指令,如:
Get-Service | Get-Member | Out-Host -Paging ,當然可以進一步篩選出想要的MemberType:
Get-Service | Get-Member - MemberType Properties | Out-Host -Paging
4.善用Format: Format-List, Format-Table, Format-Wide
5.將Data Redirect,預設是 | Out-Host將Data輸出到powershell視窗, | Out-Null可以將不需要的Data丟棄,Out-File可以將檔案輸出:
Get-Process | Out-File -FilePath C:\Temp\process.txt
6.使用變數時會將資料存進記憶體裡,若已不需要利用這些資料,可以使用$null變數釋放記憶體資源:
$Service = Get-Service | Where-Object {$_.Status = 'Running'} => $Service = $Null
7.存取目前系統內的環境變數:
Get-ChildItem env:
存取變數值: $env:AppData
8.可以透過WMI使用CIM(Common Information Model)去建立class代表硬碟,應用程式等以便後續資料的擷取與更改
9.善用Sort-Object進行排序 與運算子(-contains, -match -like -eq)