I have a powershell script that is converting CSV to XLSX. It works as intended when outputting to local disk. It runs for a few seconds and then an XLSX file is generated in $files path.
$files = Get-ChildItem c:\test\*.csv
Write "Loading Files..."
$Excel = New-Object -ComObject Excel.Application
ForEach ($file in $files)
{
$WorkBook = $Excel.Workbooks.Open($file.Fullname)
$NewFilepath = $file.Fullname -replace ".{4}$"
$NewFilepath = $NewFilepath + ".xlsx"
$Workbook.SaveAs($NewFilepath,51)
}
$Excel.Quit()
Stop-Process -processname EXCEL
But when I change it to output to a file share, it immediately completes with no error, but no output file is generated.
$files = Get-ChildItem \\fileserver\path\*.csv
Write "Loading Files..."
$Excel = New-Object -ComObject Excel.Application
ForEach ($file in $files)
{
$WorkBook = $Excel.Workbooks.Open($file.Fullname)
$NewFilepath = $file.Fullname -replace ".{4}$"
$NewFilepath = $NewFilepath + ".xlsx"
$Workbook.SaveAs($NewFilepath,51)
}
$Excel.Quit()
Stop-Process -processname EXCEL
I would suspect this is a permissions issue, but the logged in account has write access the share. Does a powershell script change the user/account context? What can I add to this script to capture errors and identify the problem?