【问题标题】:Display output on new lines? Not all on the same line?在新行上显示输出?不是都在同一条线上吗?
【发布时间】:2022-11-14 07:43:54
【问题描述】:

我有这个脚本,它返回我机器的重启时间。

有谁知道如何让输出在每个条目的新行上返回?现在,它显示在一行中并被切断。

$rebootTimes = @( get-eventlog system | where-object {$_.eventid -eq 6006} | select-object -ExpandProperty Timegenerated )$output = "" | Select-Object 'Rebooted at';$output.'Rebooted at' = $rebootTimes;Write-Output $output;

我试过使用数组,但同样适用!

【问题讨论】:

    标签: powershell


    【解决方案1】:

    我认为您正在寻找 calculated propertySelect-Object。值得注意的是,Get-WinEvent 替换了 Get-EventLog 并且应该是您应该用于事件日志的 cmdlet:

    Get-WinEvent -FilterHashtable @{
        Id      = 6006
        LogName = 'System'
    } | Where-Object TimeCreated | Select-Object @{ N='Rebooted at'; E={ $_.TimeCreated }}
    

    【讨论】:

      猜你喜欢
      • 2018-09-28
      • 1970-01-01
      • 2012-12-08
      • 2022-08-02
      • 1970-01-01
      • 1970-01-01
      • 2018-09-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多