
Brad Carey (Customer) asked a question.
I am trying to make a script to convert ODS files to CSV.
Here is the basic code I am using for testing and development at this time:
- $excelObj = New-Object -com excel.application
-
- $excelWb = $excelObj.Workbooks.Open("D:\MOVEitTemp\ods_input.ods")
-
- $excelWb.SaveAs("D:\MOVEitTemp\ods_converted.csv",6)
-
- $excelWb.Close($false)
-
- $excelObj.Quit()
-
- [void][System.Runtime.Interopservices.Marshal]::ReleaseComObject($excelWb)
-
- [void][System.Runtime.Interopservices.Marshal]::ReleaseComObject($excelObj)
-
- [GC]::Collect()
If I run the above code via Powershell on the MOVEit Automation server, it produces the converted file ods_converted.csv
If I attempt to run the same code via a MOVEit Automation PS1 script:
- $inputFile = $miaclient.MICacheFilename()
-
- $tempFile = "D:\MOVEitTemp\ods_input.ods"
-
- Copy-Item -Path $inputFile -Destination $tempFile
-
- D:\MOVEitTemp\ods2csv.ps1
I get the following error (and no file is produced):
Task "Script Testing": Script Testing returned error 10000: Error: Microsoft Excel cannot access the file 'D:\MOVEitTemp\ods_input.ods'. There are several possible reasons:
• The file name or path does not exist.
• The file is being used by another program.
• The workbook you are trying to save has the same name as a currently open workbook.
I am confident none of the several possible reasons is true.
Does anyone know why Excel doesn't have access to the file when the PS1 code is run via MOVEit Automation, but it does when run natively with Powershell?
The MOVEit Automation service account has full access to file D:\MOVEitTemp\ods_input.ods.
Alternatively, I am open to another idea on how to convert ODS to CSV.
XLSX to CSV was much easier to accomplish:
- #get the cache filename
- $inputFile = $miaclient.MICacheFilename()
-
- #get a new cache filename
- $outputFile = $miaclient.MINewCacheFilename()
-
- #import module
- import-module -name "c:\program files\windowspowershell\modules\ImportExcel"
-
- #Perform conversion
- Import-Excel -Path $inputFile | Export-Csv $outputFile -NoTypeInformation
-
- #Create final file
- $miaclient.MIReplaceCacheFile($outputFile)
Frustratingly enough, step 1 was the cure to my problem:
Yes, that is correct, I simply had to create the folder "Desktop" under C:\Windows\System32\config\systemprofile\.
Here is the code I have thus far landed on: