log查詢

This commit is contained in:
CodyZhang
2020-04-23 14:46:53 +08:00
commit db4ba7274f
2 changed files with 214 additions and 0 deletions

50
readme.md Normal file
View File

@@ -0,0 +1,50 @@
## 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
```