I am executing a Powershell script using a SSIS Process task. The .PS1 code converts .xlsx file to .csv file. The package is running fine in local machine using BIDS, but by using the agent job the package is generating CSV file with 0KB.
$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()