Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Search Powershell脚本导出Csv怪异_Search_Powershell_Export To Excel - Fatal编程技术网

Search Powershell脚本导出Csv怪异

Search Powershell脚本导出Csv怪异,search,powershell,export-to-excel,Search,Powershell,Export To Excel,我创建了一个小脚本来提取文件夹及其子文件夹中指定字符串的所有行。在我想将行导出到excel(csv)之前,它的行为与预期一致。此时,它只导出两行(至少每次都是相同的两行)。实际上,它应该有大约40行exportet。工作脚本如下所示: [string]$pathSource = "D:\Projects\test" [string]$pathTarget = "D:\Projects\test\searchpattern-sql.csv" [string[]]$excludeFileTypes

我创建了一个小脚本来提取文件夹及其子文件夹中指定字符串的所有行。在我想将行导出到excel(csv)之前,它的行为与预期一致。此时,它只导出两行(至少每次都是相同的两行)。实际上,它应该有大约40行exportet。工作脚本如下所示:

[string]$pathSource = "D:\Projects\test"
[string]$pathTarget = "D:\Projects\test\searchpattern-sql.csv"

[string[]]$excludeFileTypes = "*.dll","*.pdb","*.gif","*.dat","*.bin","*.msi","*.epi4","*.png","*.tlog","*.gif","*.cache","*.csproj","*.config","*.user","*.txt"

[string]$searchPattern = "sqlCommand"

Get-ChildItem $pathSource -Exclude $excludeFileTypes  -Recurse | Select-String $searchPattern | Sort-Object Path | Select-Object Path, LineNumber, Line

使用export cmdlet(| export Csv-path$pathTarget)添加新管道会以某种方式破坏搜索。我做错了什么?

就我个人而言,我在使用
导出CSV时发现了问题。我发现工作正常的方法是通过管道连接到
convrttocsv
,然后连接到
设置内容
,或者使用重定向将内容输出到文件。

我个人发现使用
导出CSV
时出现问题。我发现,通过管道传输到
convrttocsv
,然后再到
设置内容
,或者使用重定向将内容输出到文件,效果很好。

只需测试一下:

[string]$pathSource = "D:\Projects\test"
[string]$pathTarget = "D:\Projects\test\searchpattern-sql.csv"

[string[]]$excludeFileTypes = "*.dll","*.pdb","*.gif","*.dat","*.bin","*.msi","*.epi4","*.png","*.tlog","*.gif","*.cache","*.csproj","*.config","*.user","*.txt"

[string]$searchPattern = "sqlCommand"

$a = Get-ChildItem $pathSource -Exclude $excludeFileTypes  -Recurse | Select-String $searchPattern | Sort-Object Path | Select-Object Path, LineNumber, Line
$a | Export-Csv yourfile.csv -NoTypeInformation
$a变量只包含我导出的行数组。

只需测试一下:

[string]$pathSource = "D:\Projects\test"
[string]$pathTarget = "D:\Projects\test\searchpattern-sql.csv"

[string[]]$excludeFileTypes = "*.dll","*.pdb","*.gif","*.dat","*.bin","*.msi","*.epi4","*.png","*.tlog","*.gif","*.cache","*.csproj","*.config","*.user","*.txt"

[string]$searchPattern = "sqlCommand"

$a = Get-ChildItem $pathSource -Exclude $excludeFileTypes  -Recurse | Select-String $searchPattern | Sort-Object Path | Select-Object Path, LineNumber, Line
$a | Export-Csv yourfile.csv -NoTypeInformation

$a var只包含我导出的行数组。

不,这样做得到的结果是一样的。ConvertTo CSV工作正常,但当我将其导入Set-Content cmdlet时,它返回到相同的两行…真正的问题是Excel,脚本执行了它应该执行的操作。不,我通过这种方式获得了相同的结果。ConvertTo CSV工作正常,但当我将其导入Set-Content cmdlet时,它返回到相同的两行…真正的问题是Excel,脚本执行了它应该执行的操作。您可以通过编辑问题来显示这两行吗?您是否有任何示例输入/输出来演示此问题?@zdan,真正的问题是Excel,脚本本身运行得很好。你能通过编辑你的问题来显示这两行吗?你有任何示例输入/输出来演示问题吗?@zdan,真正的问题是Excel,脚本本身运行得很好。谢谢,这在Excel中起了作用,但仍然不正确。这不可能,肯定还有别的事情发生。还有一个是Excel。Excel在打开.csv文件时试图变得聪明,但失败了。只有在使用记事本++打开文件时才注意到这一点。尝试我的原始脚本,并在Notepad++中打开结果,信息都在那里。所以我想真正的答案是“打开.csv文件时不要总是信任Excel”。谢谢,这在Excel中起了作用,但仍然不正确。这不可能,肯定还有别的事情发生。还有一个是Excel。Excel在打开.csv文件时试图变得聪明,但失败了。只有在使用记事本++打开文件时才注意到这一点。尝试我的原始脚本,并在Notepad++中打开结果,信息都在那里。所以我想真正的答案是“打开.csv文件时不要总是相信Excel”。