我正在尝试将离线计算机记录在文本文件中,以便我可以在以后再次运行它们.似乎没有记录或陷入捕获.
function Get-ComputerNameChange {
[CmdletBinding()]
Param(
[Parameter(Mandatory=$True,ValueFromPipeline=$True,ValueFromPipelinebyPropertyName=$True)]
[string[]]$computername,
[string]$logfile = 'C:\PowerShell\offline.txt'
)
PROCESS {
Foreach($computer in $computername) {
$continue = $true
try { Test-Connection -computername $computer -Quiet -Count 1 -ErrorAction stop
} catch [System.Net.NetworkInformation.PingException]
{
$continue = $false
$computer | Out-File $logfile
}
}
if($continue){
Get-EventLog -LogName System -ComputerName $computer | Where-Object {$_.EventID -eq 6011} |
select machinename, Time, EventID, Message }}}
Run Code Online (Sandbox Code Playgroud) 我正在使用get-eventlog来提取和过滤系统事件日志数据.我发现,get-event日志无法正确返回与某些条目相关的消息.这些条目通常出现在事件日志查看器中.例如
get-eventlog -logname system | ? { $_.source -eq "Microsoft-Windows-Kernel-General" }
Run Code Online (Sandbox Code Playgroud)
返回8个条目,所有条目都有以下格式的消息:
The description for Event ID '12' in Source 'Microsoft-Windows-Kernel-General' cannot be found.
The local computer may not have the necessary registry information or message DLL files to display the message, or you may not have permission to access them.
The following information is part of the event:'6', '1', '7601', '18798', '1', '0', '2015-06-13T08:33:32.359599800Z'
Run Code Online (Sandbox Code Playgroud)
如果我过滤同一来源的系统事件日志,我可以清楚地看到完整形成的消息.例如
The operating system started at system time ?2015?-?06?-?13T08:33:32.359599800Z.
Run Code Online (Sandbox Code Playgroud)
我运行以下命令以查看是否有任何其他提供程序无法返回有效的事件消息:
get-eventlog -LogName system | ? …Run Code Online (Sandbox Code Playgroud) 我试图通过 powershell 找到安全事件日志中最旧的保留事件。
使用以下命令:(Get-EventLog Security | Sort-Object -Property Time -Descending)
这将返回一个根本没有排序的列表。我在这里做错了什么?