【问题标题】:i cannot get PowerShell to add the LogName to the csv我无法让 PowerShell 将 LogName 添加到 csv
【发布时间】:2016-02-23 11:49:13
【问题描述】:

我无法让 PowerShell 将 LogName 添加到 csv。我正在运行这个命令:

Invoke-Command -ComputerName Server -Credential $cred -Authentication Default -ScriptBlock { 
    Get-EventLog -LogName System -EntryType Error | 
        Select-Object -Property PSComputerName, Site,TimeGenerated, EventID, Message, Source, EntryType
} | Export-Csv -NoTypeInformation -Path C:/output.csv

任何帮助将不胜感激

【问题讨论】:

  • | export-csv 应该在脚本块内。
  • 如果我这样做,它将存储在服务器上,我不想要,我需要将它存储在本地
  • 您是否只是希望将“系统”添加到每个条目下的每个条目中?由于您只查看系统日志,因此不会假设? Select-Object -Property PSComputerName,Site,TimeGenerated, EventID, Message, Source, EntryType, @{name="LogName";expression={"System"}}
  • 您可以在脚本块中使用“ | Export-Csv -Path Microsoft.PowerShell.Core\FileSystem::\\servername\share\output.csv”。
  • 好吧,我无法在我的工作站上用| export-csv 测试Invoke-Command,因为我们没有在我们的公司中设置 WinRM,但对我来说这似乎令人困惑,因为你没有任何东西可以导出到 csv,如果您不在脚本块中使用它。

标签: csv powershell export-to-csv invoke-command


【解决方案1】:

Matt 有正确答案,经过测试,他简单优雅的方法完美运行。非常感谢马特。非常感激。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-05
    • 1970-01-01
    • 2016-12-31
    • 2020-06-28
    • 2020-12-23
    • 2012-04-06
    • 1970-01-01
    相关资源
    最近更新 更多