我正在創建一個腳本來獲取服務器上的用戶登錄資訊。我通過 powershell 和事件查看器來完成。問題是腳本回傳系統的用戶和其他“用戶”,我只需要真正的用戶。
______
User
______
AR01
system
dvm-01
system
AR01
AR04
AR15
system
我想過創建一個條件,讓它只選擇以 AR 開頭的用戶,但我不知道該怎么做。
有任何想法嗎?謝謝!
Get-WinEvent -Computer MyServerName -FilterHashtable @{Logname='Security';ID=4624} -MaxEvents 2000|
select @{N='User';E={$_.Properties[5].Value}}, TimeCreated | export-csv -Path C:\Users\AR001\Desktop\filename.csv -NoTypeInformation
uj5u.com熱心網友回復:
從訊息中提取資料后,您可以簡單地使用 Where-Object。
只需添加以下內容:
Where-Object -Property User -Match -Value "AR"
在您嘗試匯出到 CSV 之前。
試試這個完整的命令:
Get-WinEvent -Computer MyServerName -FilterHashtable @{Logname='Security';ID=4624} -MaxEvents 2000 | Where-Object -Property User -Match -Value "AR"
select @{N='User';E={$_.Properties[5].Value}}, TimeCreated | export-csv -Path C:\Users\AR001\Desktop\filename.csv -NoTypeInformation
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/478626.html
上一篇:檢查值是否在特定范圍內
下一篇:從字串中獲取2個字符之間的值
