[英]Output Array to CSV file is outputting the line length - powershell
I am working on a powershell script that outputs nmap scan data from a multitude of nmap .txt files to a CSV. 我正在研究一个Powershell脚本,该脚本将nmap扫描数据从多个nmap .txt文件输出到CSV。 Whenever I output the Data via Export-Csv C:\\file.csv it is outputting the length of the lines, and not the actual data.
每当我通过Export-Csv C:\\ file.csv输出数据时,它就是输出行的长度,而不是实际数据。
Any suggestions? 有什么建议么? Output Arrays seem to be something I am having issues grasping.
输出数组似乎是我遇到的问题。
$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
This behavior is because you are passing string array to export-csv
which is expecting object 这是因为您要将字符串数组传递给期望对象的
export-csv
if you want to force the behavior ,then you can try this example: 如果要强制执行该行为,则可以尝试以下示例:
$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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.