• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >PowerShell > PowerShell时间记录脚本

PowerShell时间记录脚本

作者:hebedich 字体:[增加 减小] 来源:互联网

hebedich 通过本文主要向大家介绍了powershell脚本,powershell 运行脚本,powershell执行脚本,powershell脚本下载,powershell常用脚本等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

#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"}
  }

</div>

为了解技术思路,研究了一下powershell.
整个开发与部署过程如下:

1.下载WindowsXP-KB926139-v2-x86-ENU

安装powershell环境;

2.按照代码要求,写一个简单的脚本;

3. 运行powershell时,同 bat是有区别的.注意以下方法:

1) 解除限制:

set-executionpolicy Unrestricted
</div>

2) 将文件名保存为ps1
3) 通过以下方法运行(假如文件名是c:a.ps1)
PS C:> .a
[@more@]

示例代码:

function foo ( [int] $x)
{
$x = $x + 1
echo $x
}
foo (1 )
</div>

</div>

您可能想查找下面的文章:

  • PowerShell因为在此系统中禁止执行脚本的解决方法
  • PowerShell时间记录脚本
  • Powershell实现编写和运行脚本
  • PowerShell脚本反引号用法实例:随时随地给代码换行
  • Powershell脚本的4种执行权限介绍
  • PowerShell中获取当前运行脚本路径的方法
  • PowerShell实现动态获取当前脚本运行时消耗的内存
  • PowerShell实现的文件同步脚本分享
  • Powershell实现获取电脑序列号功能脚本分享
  • Powershell脚本中使用条件断点实例

相关文章

  • Powershell学习笔记--使用正则表达式查找文件
  • PowerShell小技巧之配置机器的静态IP
  • PowerShell中的变量基础知识介绍
  • PowerShell脚本开发之对指定IP进行端口扫描
  • PowerShell中获取Windows系统序列号的脚本分享
  • Powershell小技巧之获取对象可变的特征
  • Powershell小技巧之找出脚本中的错误
  • PowerShell 读取性能计数器二进制文件(.blg)记录并汇总计算
  • PowerShell查看Windows功能选项的方法
  • PowerShell中运行CMD命令的技巧总结(解决名称冲突和特殊字符等问题)

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • PowerShell是什么?
    • PowerShell判断某天是星期几的方法
    • powershell操作word详解
    • Powershell打印文本文档例子
    • Powershell小技巧--远程对比服务配置
    • Powershell实现获取电脑序列号功能脚本分享
    • Powershell错误处理之what-if
    • PowerShell添加本地账户脚本分享
    • PowerShell 4.0实现自动化设置服务器
    • PowerShell连接SQL SERVER数据库进行操作的实现代码

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有