A relatively practical PowerShell time record script

Source: Internet
Author: User

 

 1 # initialization
2 $ timeInterval = 30 # monitoring interval
3 $ record = @ {"Coding" = 0; "Outlook Email" = 0; "Gmail" = 0; "Google Reader" = 0; "BBS" = 0; "Other Internet" = 0; "Documents" = 0 ;}
4 $ count = 0
5 $ date = date-format "yyyyMMdd"
6 # try to resume
7 if (test-path "d: \ temp \ timerecord=date.txt "){
8 gc "d: \ temp \ timerecord1_date.txt" |%{ if ($ _-match "\ w + \ s + \ d + "){
9 $ groups = [Regex]: Match ($ _, "^ (\ w + \ s? \ W +) \ s + (\ d +) "). Groups;
10 $ record [$ groups [1]. Value] = [int]: Parse ($ groups [2]. Value );
11 }}
12}
13 # start to monitor
14 while ($ true)
15 {
16 $ titles = ps |? {$ _. MainWindowTitle} | select MainWindowTitle
17 $ titles | % {
18 if ($ _-match "Google Reader-Windows Internet Explorer") {$ record ["Google Reader"] ++ ;}
19 else {if ($ _-match "Gmail-Windows Internet Explorer") {$ record ["Gmail"] ++ ;}
20 else {if ($ _-match "Internet Explorer") {$ record ["Other Internet"] ++ ;}
21 else {if ($ _-match "Visual Studio") {$ record ["Coding"] ++ ;}
22 else {if ($ _-match "Microsoft Word") {$ record ["events"] ++ ;}
23 else {if ($ _-match "Microsoft Office OneNote") {$ record ["events"] ++ ;}
24 else {if ($ _-match "Microsoft PowerPoint") {$ record ["events"] ++ ;}
25 else {if ($ _-match "Message (HTML)") {$ record ["Outlook Email"] ++ ;}
26 else {if ($ _-match "bbs") {$ record ["BBS"] ++ ;}
27 }}}}}}}}
28}
29 sleep ($ timeInterval)
30 $ count = ($ count + 1) % 10 # To prevent data loss, write files every 10 times
31 if ($ count-eq 0) {$ record> "d: \ temp \ timerecord1_date.txt "}
32}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.