[英]importing csv file in powershell
I have an issue with importing csv files in powershell. 我在Powershell中导入csv文件时遇到问题。 I am using following commands for read csv files. 我正在使用以下命令读取csv文件。
$CsvFilePath=“D:\MyShareOuts\*.csv”
$DataImport=Import-Csv -Path (Get-ChildItem $CsvFilePath)|Out-DataTable
Write-DataTable -ServerInstance $server -Database $Database -TableName $Table -Username $Username -Password $Password -Data $DataImport
Since the CsvFilePath
contain thousands of files with large size, importing taking long time and powershell stop working or hang for long time on import-csv
code line. 由于CsvFilePath
包含数千个大文件,因此导入需要很长时间,而powershell会停止工作或在import-csv
代码行上长时间挂起。 Finally importing not happen. 最后导入不会发生。 Can any one suggest valuable solution for make it happen successfully. 任何人都可以提出有价值的解决方案以使其成功实现。
What about trying to process files one by one instead of 1000s in on go? 尝试一次处理一个文件而不是1000个文件怎么办?
$CsvFilePath=“D:\MyShareOuts\*.csv”
Get-ChildItem $CsvFilePath | Foreach-Object {
$DataImport = Import-Csv $_.FullName | Out-DataTable
Write-DataTable -ServerInstance $server -Database $Database -TableName $Table -Username $Username -Password $Password -Data $DataImport
}
I haven't used Out-/Write-Datable
, but it might also support something like this(very untested): 我没有用过Out-/Write-Datable
,但它可能也支持这样的东西(非常未经测试):
$CsvFilePath=“D:\MyShareOuts\*.csv”
Get-ChildItem $CsvFilePath |
Import-Csv |
Out-DataTable | Foreach-Object {
Write-DataTable -ServerInstance $server -Database $Database -TableName $Table -Username $Username -Password $Password -Data $_
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.