一个相对实用的PowerShell时间记录脚本
2010-02-26 14:15
357 查看
#initialization $timeInterval = 30 #监测间隔 $record = @{"Coding" = 0; "Outlook Email" = 0; "Gmail" = 0; "Google Reader" = 0; "BBS" = 0; "Other Internet" = 0; "Documents" = 0;} $count = 0 $date = date -format "yyyyMMdd" #try to resume if (test-path "d:\temp\timeRecord$date.txt") { gc "d:\temp\timeRecord$date.txt" | % {if ($_ -match "\w+\s+\d+") { $groups = [Regex]::Match($_, "^(\w+\s?\w+)\s+(\d+)").Groups; $record[$groups[1].Value] = [int]::Parse($groups[2].Value); }} } #start to monitor while ($true) { $titles = ps | ? {$_.MainWindowTitle} | select MainWindowTitle $titles | % { if ($_ -match "Google 阅读器 - Windows Internet Explorer") {$record["Google Reader"]++;} else {if ($_ -match "Gmail - Windows Internet Explorer") {$record["Gmail"]++;} else {if ($_ -match "Internet Explorer") {$record["Other Internet"]++;} else {if ($_ -match "Visual Studio") {$record["Coding"]++;} else {if ($_ -match "Microsoft Word") {$record["Documents"]++;} else {if ($_ -match "Microsoft Office OneNote") {$record["Documents"]++;} else {if ($_ -match "Microsoft PowerPoint") {$record["Documents"]++;} else {if ($_ -match "Message (HTML)") {$record["Outlook Email"]++;} else {if ($_ -match "bbs") {$record["BBS"]++;} }}}}}}}} } sleep($timeInterval) $count = ($count + 1) % 10 #为了防止数据丢失,每10次记录写入文件一次 if ($count -eq 0) {$record > "d:\temp\timeRecord$date.txt"} }
相关文章推荐
- 一个奇特的脚本输出日志方式-----记录时间方式
- 记录一个用PowerShell来获得UserProfile的某个属性的脚本
- PowerShell时间记录脚本
- 分享一个R语言的脚本【时间记录】
- 记录一个测试用的PowerShell脚本
- 记录系统当前时间到一个文件中
- 脚本文件中使用变量(得到当前时间,用来生成一个文件夹)
- 记录一个利用winscp script 自动上传的脚本
- SQLSERVER记录登录用户的登录时间(自写脚本)
- oracle取最近一个时间的记录
- 一个获取指定目录下一定格式的文件名称和文件修改时间并保存为文件的python脚本
- 一个基于时间注入的perl小脚本
- javascript入门·脚本执行的时间的四种类型(赠送一个转换的小例题)
- javascript入门·脚本执行的时间的四种类型(赠送一个转换的小例题)
- 最近编写一个日历控件,对包含有日期及时间记录的数据查询很方便
- Linux---分享一个有关dig的实用脚本
- 一个用Spring AOP实现异常处理和记录程序执行时间的实例(一)
- 通过脚本实现从日志文件中提取时间最近的几条记录
- 【Powershell】【CPU使用率】脚本实时获取所有cpu使用时间非0的进程
- 《Advanced Bash-scripting Guide》学习(四):一个显示时间日期登录用户的脚本