50 lines
1.3 KiB
Markdown
50 lines
1.3 KiB
Markdown
## PowerShell 常用的指令
|
||
|
||
|
||
### Log 查詢
|
||
|
||
#### 顯示內容
|
||
```powershell
|
||
Get-Content -Path C:\Windows\System32\LogFiles\HTTPERR\httperr1.log
|
||
```
|
||
|
||
#### 分頁顯示內容
|
||
```powershell
|
||
Get-Content -Path C:\Windowns\System32\LogFiles\HTTPERR\httperr1.log | Out-Host -Paging
|
||
```
|
||
|
||
#### 顯示最後幾行
|
||
```powershell
|
||
Get-Content -Path C:\Windows\Logs\DISM\dism.log -Tail 50
|
||
```
|
||
|
||
#### 持續監控
|
||
以下指令會先顯示最後5筆,然後持續監控檔案,只要一更新,馬上顯示。
|
||
```powershell
|
||
Get-Content -Path C:\Windows\WindowsUpdate.log -Tail 5 -Wait
|
||
```
|
||
|
||
|
||
#### 顯示符合條件的 log
|
||
以下會顯示最後20筆符合 Drop 的 log 行
|
||
```powershell
|
||
Select-String -Path C:\Windows\System32\LogFiles\Firewall\pfirewall.log -Pattern 'Drop' | Select-Object -Last 20
|
||
```
|
||
|
||
#### 多個條件
|
||
```powershell
|
||
Select-String -Path C:\Windows\WindowsUpdate.log -Pattern 'error','warning'
|
||
```
|
||
|
||
#### 顯示連同符合條件的上下行
|
||
以下指令會顯示符合條的的資料行和前面的0行,後面的3行
|
||
```powershell
|
||
Select-String -Path C:\Windows\WindowsUpdate.log -Pattern 'error' -Conteext 0,3
|
||
```
|
||
|
||
|
||
#### 查看log檔特定行號間的紀錄
|
||
以下查詢會顯示 log 檔從 30 到 45 行之間的資料。
|
||
```powershell
|
||
Get-Content C:\Windows\debug\netlogon.log | Select-Object -First 30 -Skip 45
|
||
``` |