【问题标题】:Output Array to CSV file is outputting the line length - powershell输出数组到 CSV 文件正在输出行长 - powershell
【发布时间】:2017-02-16 13:51:07
【问题描述】:

我正在开发一个 powershell 脚本,该脚本将 nmap 扫描数据从大量 nmap .txt 文件输出到 CSV。每当我通过 Export-Csv C:\file.csv 输出数据时,它输出的是行的长度,而不是实际数据。

有什么建议吗?输出数组似乎是我难以掌握的东西。

$fulloutput=@()

foreach ($File in GCI C:\*.txt){
$output=$null
$output+=$file.name + ","
    foreach ($result in (gc $file)){
        $output+=$result | ?{$_ -like "OS details*" -or $_ -like "Aggressive OS*"}
    }
    $fulloutput+=$output
}
$fulloutput | Export-Csv C:\nmap.csv

【问题讨论】:

    标签: powershell


    【解决方案1】:

    这种行为是因为您将字符串数组传递给 export-csv 这是期望的对象

    如果你想强制行为,那么你可以试试这个例子:

    $c = @("dg","ert")                 
    #you can replace the below variable with your $fulloutput                                                                               
    $c| %{new-object psobject -property @{text=$_}} | Export-Csv test.csv  -NoTypeInformation                                              
    notepad .\test.csv 
    

    【讨论】:

    • 我需要用这一行替换最后一行吗?
    • 我刚开始工作,我能够对此进行测试。感谢您的帮助。
    猜你喜欢
    • 2014-09-16
    • 1970-01-01
    • 2017-12-15
    • 1970-01-01
    • 2015-01-17
    • 2013-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多