PowerShell Time Logging Script _powershell

Source: Internet
Author: User
Tags save file

#initialization $timeInterval = #监测间隔 $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]::P arse ($groups [2].
    Value); #start to monitor while ($true) {$titles = PS |? {$_. MainWindowTitle} | Select MainWindowTitle $titles |
      % {if ($_-match "Google reader-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"]++} $count = ($count + 1)% #为了防止数据丢失, write a file every 10 times if ($count-eq 0) {$reco}}}}}}

 Rd > "D:\temp\timeRecord$date.txt"}}

In order to understand the technical thinking, studied the PowerShell.
The entire development and deployment process is as follows:

1. Download Windowsxp-kb926139-v2-x86-enu

Install PowerShell environment;

2. Write a simple script as required by the Code;

3. When running PowerShell, the same bat is different. Note the following methods:

1) Lifting Restrictions:

Set-executionpolicy Unrestricted

2 Save file name as PS1
3) Run (if the filename is C:a.ps1) by the following method
PS C:>. A
[@more @]

Sample code:

function foo ([int] $x)
{
$x = $x + 1
echo $x
}
foo (1)

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.