powershell 编写event log
2015-07-24 09:41
381 查看
PowerShell是个很牛逼的命令行工具,在Windows 7以后的系统里都默认自带。学会了PowerShell就可以提升逼格,让妹子崇拜。今天就教大家用PowerShell操作Windows的Event Log。首先,启动PowerShell很简单,只需要在开始菜单里输入Power,就能找到了(Windows 8用户可以直接在开始屏幕里搜索Power)。
启动PowerShell后,你可以看到一个这样的界面。和CMD不同,它是深蓝色背景的,并且路径前多了PS前缀。看起来很厉害的样子:
有用程序写过Windows Event Log的童鞋都知道,我们的首要任务是创建一个Log和一个Source。PowerShell里语法如下:new-eventlog -LogName 日志名称 -Source 源名称比如,我们创建一个Name为Game,Source为CS的Log,可以这样写:new-eventlog -LogName Game -Source CS。执行后在事件查看器里就能找到了。
写入日志也很方便:write-eventLog -LogName Game -Message " Edi Killed GayShyFool with AWP " -Source CS -id 1
默认写入的是Information级别的Log。如果想要制定Level,就要加上EntryType参数: write-eventLog -LogName Game -Message "GayShyFool invoked 'My Dad is a Gang' method." -Source CS -id 2 -EntryType Warning
要直接在PowerShell里面读取EventLog,用的是get-eventlog命令: get-eventlog -LogName Game -Source CS
要删除整个Log(包括分类),用的是Remove-EventLog命令。注意大小写敏感。在不指定参数的情况下,PowerShell也会询问我们参数。在LogName[0]:后输入Game,按两下回车,就可以移除整个Game的Log了。PS C:\Users\Edi_Wang> Remove-EventLogcmdlet Remove-EventLog at command pipeline position 1Supply values for the following parameters:LogName[0]: Gam
启动PowerShell后,你可以看到一个这样的界面。和CMD不同,它是深蓝色背景的,并且路径前多了PS前缀。看起来很厉害的样子:
有用程序写过Windows Event Log的童鞋都知道,我们的首要任务是创建一个Log和一个Source。PowerShell里语法如下:new-eventlog -LogName 日志名称 -Source 源名称比如,我们创建一个Name为Game,Source为CS的Log,可以这样写:new-eventlog -LogName Game -Source CS。执行后在事件查看器里就能找到了。
写入日志也很方便:write-eventLog -LogName Game -Message " Edi Killed GayShyFool with AWP " -Source CS -id 1
默认写入的是Information级别的Log。如果想要制定Level,就要加上EntryType参数: write-eventLog -LogName Game -Message "GayShyFool invoked 'My Dad is a Gang' method." -Source CS -id 2 -EntryType Warning
要直接在PowerShell里面读取EventLog,用的是get-eventlog命令: get-eventlog -LogName Game -Source CS
要删除整个Log(包括分类),用的是Remove-EventLog命令。注意大小写敏感。在不指定参数的情况下,PowerShell也会询问我们参数。在LogName[0]:后输入Game,按两下回车,就可以移除整个Game的Log了。PS C:\Users\Edi_Wang> Remove-EventLogcmdlet Remove-EventLog at command pipeline position 1Supply values for the following parameters:LogName[0]: Gam
相关文章推荐
- Bash shell下命令换行输入
- Microsoft.Windows.TimedPowerShell.DiscoveryProvider 的介绍
- shell脚本中一些特殊符号
- shell脚本-----按行读取文件
- linux shell 数组建立及使用技巧
- shell,linux
- Linux Shell脚本面试25问
- 自动登录ssh的shell脚本
- shell 脚本调试工具
- shell 脚本调试(使用shell的执行选项)
- shell序列和nohup &
- Shell 学习笔记 (org-mode制作)
- shell脚本:shell的基本元素-2 变量
- shell学习
- Mac OS X 执行shell以及bash shell的区别。
- 【BASH】自己主动清理rman脚本备份文件
- 功能强大的Windows PowerShell
- Scrapy Shell访问jandan被拒解决方法
- [linux][shell]控制进程不定时重启
- Java调用Shell命令的方法