[英]How to call a Powershell script using batch script and pass an object array
[英]Logon, logoff script analysing using PowerShell
我首先要解釋一下我想要實現的目標。
對於他們想要監控PC試驗組的項目。 他們想要以下信息:
所以我繼續創建了一個登錄和注銷腳本。 這些腳本的輸出每月都是一個txt文件。
例如:文件01-2017.txt
包含:
25-01-2017,09:29,lky9,WS257737,Logon
25-01-2017,10:37,lky9,WS257737,Logoff
25-01-2017,10:01,1f57,WS157954,Logon
25-01-2017,10:29,7df6,WS248751,Logon
25-01-2017,10:34,7df6,WS248751,Logoff
25-01-2017,10:48,1f57,WS157954,Logoff
現在我已經(不成功地)嘗試使用Get-Content
在數組中獲取所有這些Get-Content
。 因為當我能做到這一點時,我可以進一步嘗試。 PowerShell技能仍然很差,但我可以管理數組沒關系。 所以問題是;
任何人都可以向我解釋我是如何得到這個數組?
您需要的是使用Import-CSV
cmdlet Import-CSV
因為這將為您提供所有記錄作為對象數組:
$logList = Import-Csv -Path "Path_to_01-2017.txt" -Header @('Date', 'Time', 'User', 'PC', 'Type')
輸出:
Date : 25-01-2017
Time : 09:29
User : lky9
PC : WS257737
Type : Logon
Date : 25-01-2017
Time : 10:37
User : lky9
PC : WS257737
Type : Logoff
Date : 25-01-2017
Time : 10:01
User : 1f57
PC : WS157954
Type : Logon
Date : 25-01-2017
Time : 10:29
User : 7df6
PC : WS248751
Type : Logon
Date : 25-01-2017
Time : 10:34
User : 7df6
PC : WS248751
Type : Logoff
Date : 25-01-2017
Time : 10:48
User : 1f57
PC : WS157954
Type : Logoff
舉例說明如何使用它來回答您的問題:
#total unique users that logged on
$logList.User | select -Unique | Measure | select -ExpandProperty Count
#Total log on
$logList | where Type -eq LogOn | Measure | select -ExpandProperty Count
#Time of each session per user
# This is a bit tricky so I leave that up to you :p
我會用一種完全不同的方法。 事件查看器使用用戶ID保存登錄和注銷時間戳(我認為它是用戶的sid)。 然后,您只需要跟蹤意外的重新啟動,以確保對於那些僅具有該時間的登錄事件的會話,這是您的截止點。
然后,您可以在計划任務的任何給定時間運行腳本。 您不必在登錄/注銷期間運行,這可能會影響登錄時間(不多但仍然如此)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.