2017-02-16 67 views
0

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

有什么建议吗?输出数组似乎是我正在抓住问题的东西。

[email protected]() 

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 

回答

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 
+0

我需要用这个替换最后一行? –

+0

我刚刚开始工作,我能够测试这个。感谢您的帮助。 –