我正在使用SSIS Process任务执行Powershell脚本。 .PS1代码将.xlsx文件转换为.csv文件。该程序包在使用BIDS的本地计算机上正常运行,但是通过使用代理程序作业,程序包将生成0KB的CSV文件。
$strFileName = "\\Server\Data\Test.xlsx"
$strSheetName = 'Page 1$'
$strProvider = "Provider=Microsoft.ACE.OLEDB.12.0"
$strDataSource = "Data Source = $strFileName"
$strExtend = "Extended Properties='Excel 12.0 Xml;HDR=Yes;IMEX=1';"
$strQuery = "Select * from [$strSheetName]"
$objConn = New-Object System.Data.OleDb.OleDbConnection("$strProvider;$strDataSource;$strExtend")
$sqlCommand = New-Object System.Data.OleDb.OleDbCommand($strQuery)
$sqlCommand.Connection = $objConn
$objConn.open()
$da = New-Object system.Data.OleDb.OleDbDataAdapter($sqlCommand)
$dt = New-Object system.Data.datatable
[void]$da.fill($dt)
$dt | Export-Csv \\Server\Data\Test.csv -NoTypeInformation
$objConn.close()