powershell - 结果只显示一列?

标签 powershell powershell-2.0

一个简单的问题,但如何在下面的代码中选择特定的列?

我只想显示 TIME 列,别无其他。我尝试输入 FORMAT_TABLE TIME 但它只是多次填充 TIME 而没有实际显示时间..

$server_event = Get-Content -Path "c:\Temp\Servers.txt"

foreach($servers in $server_event)
{

$event = Get-EventLog -computerName $servers -logname system | Where-Object {$_.EventID -eq 6009} | Select -First 1

$event

} 

结果:我只想显示时间列
   Index Time          EntryType   Source                 InstanceID Message                                                                                     
   ----- ----          ---------   ------                 ---------- -------                                                                                     
   78858 Jun 01 07:19  Information EventLog               2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Multiprocessor Free.                    
   46221 Jun 01 07:20  Information EventLog               2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Multiprocessor Free.                    
  214480 Jun 01 07:46  Information EventLog               2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Multiprocessor Free.                    
  461238 Jun 01 07:18  Information EventLog               2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Multiprocessor Free.                    
   70889 Jun 01 07:17  Information EventLog               2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Multiprocessor Free.                    
   52397 Jun 01 07:19  Information EventLog               2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Multiprocessor Free.                    
   42219 Jun 01 07:40  Information EventLog               2147489657 Microsoft (R) Windows (R) 5.02. 3790 Service Pack 2 Uniprocessor Free.     

最佳答案

尝试:

$event = Get-EventLog -computerName $servers -logname system | Where-Object {$_.EventID -eq 6009} | Select TimeGenerated -First 1

关于powershell - 结果只显示一列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16897659/

相关文章:

powershell - PowerShell正则表达式删除从Windows补丁程序提取到C驱动器根目录的文件夹

.net - 如何查询DOTNET_CLI_TELEMETRY_OPTOUT是否永久设置为TRUE?

.net - 使用存储在变量中的类型进行 PowerShell 类型转换

powershell - 在Powershell中格式化带有列的文本文件

powershell - 如何在 PowerShell 二进制模块中捕获外部 DLL 的控制台输出?

powershell - 什么安全设置阻止远程 PowerShell 2.0 访问 UNC 路径

node.js - 在 Windows 中发送 SIGUSR1 IPC

powershell - 使用 "Invoke-Command"在远程机器上运行本地文件

powershell-2.0 - 在powershell中使用相对路径进行点采购

powershell - 使用 powershell 获取缺少驱动程序的设备列表