Powershell中可以简单记录脚本执行的记录:

Start-Transcript: 开始记录

Stop-Transcript:停止记录

 

(1)输入以下命令,将运行的日志记录在D:\powershelllog.txt

Start-Transcript -path d:\powershelllog.txt -Force -Append –NoClobber

(2)分别输入:

get-service -InputObject -Status "starting"
get-service

PowerShell记录脚本运行过程_start-transcript 

(3)输入以下命令停止记录;

stop-transcript

查看记录命令的日志:

PowerShell记录脚本运行过程_start-transcript_02 

PowerShell记录脚本运行过程_stop-transcript_03

参数说明:

-path:指定日志记录的位置;

-force: 强制将日志写入只读文件;

-append:将日志添加到日志文件末尾,而不是覆盖其内容;

-noclobber:如果同名的日志文件存在,则停止命令并告警;


参考网址:http://technet.microsoft.com/zh-CN/library/dd347721.aspx