我想知道我们的计算机在任意一个日历日内处于开机(即非待机)模式的时间有多长。是否有一个(免费)程序可以从 Windows 系统事件日志中提取此信息并将其转换为 CSV 格式,并且适用于 Windows XP?
答案1
2 个选择,第一个比较简单,但不能导出到 CSV。
选项1
从开始菜单中单击运行,然后键入 cmd,然后按键盘上的 Enter 键。
在命令提示符窗口中输入
系统信息 | 查找“正常运行时间”
请注意,上面的代码区分大小写。
选项 2
另外,以下 powershell 脚本也可以执行此操作。
<#
.SYNOPSIS
Collects uptime information and exports to csv-file.
.DESCRIPTION
Collects information about uptime and last reboot date from one or more computers and exports result to a csv-file located in logged on users "Documents" special folder. If this file already exists (the command has been run earlier the same day) it will append the new information to the same file.
.PARAMETER ComputerName
Gets information from specified computers. Type the name of one or more computers in a comma-separated list. Default is localhost.
.PARAMETER Credential
Specifies credentials that has permission to perform WMI-queries on remote machines. Use the object returned by the Get-Credential cmdlet as argument. For local access impersonation level 3 is always used (see Get-WMIObject). Default is current user.
.LINK
2012 Scripting Games:
https://2012sg.poshcode.org
.NOTES
Author : Jesper Strandberg
Date : 2012-04-15
#>
function Export-Uptime {
[CmdletBinding()]
param (
[parameter(ValueFromPipeline = $true)]
[string[]]$ComputerName = $Env:COMPUTERNAME,
[Management.Automation.PSCredential]
$Credential
)
begin {
$LocalMachineAliases = $Env:COMPUTERNAME,'localhost','127.0.0.1','::1','.'
$Result = @()
}
process {
foreach ($Computer in $ComputerName) {
Write-Verbose "Building parameters for $Computer"
$WmiParam = @{ Class = "Win32_OperatingSystem";
Property = "LastBootUpTime";
ComputerName = $Computer }
if (-not ($LocalMachineAliases -contains $Computer) -and $Credential) {
Write-Verbose "Adding credentials for $Computer"
$WmiParam.Add("Credential", $Credential)
}
Write-Verbose "Accessing $Computer"
try { $OS = Get-WmiObject @WmiParam -ErrorAction Stop }
catch { Write-Warning $_; continue }
Write-Verbose "Calculating uptime"
$BootUpTime = $OS.ConvertToDateTime($OS.LastBootUpTime)
$Uptime = New-TimeSpan -Start $BootUpTime -End "8 am"
if ($Uptime -lt 0) { $Uptime = New-TimeSpan }
Write-Verbose "Building custom object"
$Properties = @{ ComputerName = $Computer;
Days = $Uptime.Days;
Hours = $Uptime.Hours;
Minutes = $Uptime.Minutes;
Seconds = $Uptime.Seconds;
Date = (Get-Date -Format d -Date $BootUpTime) }
$Result += New-Object PSCustomObject -Property $Properties
} # foreach
} # process
end {
Write-Verbose "Exporting results to CSV"
$CSV = $Result | Select-Object -Property ComputerName,Days,Hours,Minutes,Seconds,Date |
ConvertTo-Csv -NoTypeInformation -Delimiter ';'
$OutFile = "$([System.Environment]::GetFolderPath('Personal'))\$(Get-Date -UFormat %Y%m%d)_Uptime.csv"
try {
if (-not (Test-Path $OutFile)) {
Write-Verbose "Creating $OutFile"
$CSV | Out-File $OutFile -Encoding ASCII -ErrorAction Stop
} else {
Write-Verbose "Appending to $OutFile"
$CSV | Select-Object -Skip 1 | Out-File $OutFile -Encoding ASCII -Append -ErrorAction Stop
}
} # try
catch { Write-Warning $_ }
} # end
} # function
编辑
现在,在重新阅读你的问题后,我认为答案是使用事件日志 XP因为很多人说它是可定制的(但我以前没有用过它)。
关于软件: 事件日志资源管理器可帮助您快速浏览、查找和报告 Windows 中生成的问题、安全警告和所有其他事件。借助事件日志资源管理器,可以更快速、更有效地监控和分析 Microsoft Windows 操作系统的安全、系统、应用程序、目录服务、DNS 和其他日志中记录的事件。