Brad Carey (Customer) asked a question.

Problem with MOVEit Automation Script to Convert ODS to CSV

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:

 

D:\MOVEitTemp\ods2csv.ps1:

  1. $excelObj = New-Object -com excel.application
  2.  
  3. $excelWb = $excelObj.Workbooks.Open("D:\MOVEitTemp\ods_input.ods")
  4.  
  5. $excelWb.SaveAs("D:\MOVEitTemp\ods_converted.csv",6)
  6.  
  7. $excelWb.Close($false)
  8.  
  9. $excelObj.Quit()
  10.  
  11. [void][System.Runtime.Interopservices.Marshal]::ReleaseComObject($excelWb)
  12.  
  13. [void][System.Runtime.Interopservices.Marshal]::ReleaseComObject($excelObj)
  14.  
  15. [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:

  1. $inputFile = $miaclient.MICacheFilename()
  2.  
  3. $tempFile = "D:\MOVEitTemp\ods_input.ods"
  4.  
  5. Copy-Item -Path $inputFile -Destination $tempFile
  6.  
  7. 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:

  1. #get the cache filename
  2. $inputFile = $miaclient.MICacheFilename()
  3. #get a new cache filename
  4. $outputFile = $miaclient.MINewCacheFilename()
  5.  
  6. #import module
  7. import-module -name "c:\program files\windowspowershell\modules\ImportExcel"
  8. #Perform conversion
  9. Import-Excel -Path $inputFile | Export-Csv $outputFile -NoTypeInformation
  10. #Create final file
  11. $miaclient.MIReplaceCacheFile($outputFile)

 

 


  • Brad Carey (Customer)

    Frustratingly enough, step 1 was the cure to my problem:

    Capture 

    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:

    1. try
    2. {
    3. #get the cache filename
    4. $inputFile = $miaclient.MICacheFilename()
    5.  
    6. #get a new cache filename
    7. $outputFile = $miaclient.MINewCacheFilename()
    8. #make a log entry
    9. $miaclient.MILogMsg("Started converting from ODS to CSV.")
    10.  
    11. $excelObj = New-Object -comobject excel.application
    12.  
    13. $excelWb = $excelObj.Workbooks.Open($inputFile)
    14. $excelWb.SaveAs($outputFile,6)
    15. $excelWb.Close($false)
    16.  
    17. $excelObj.Quit()
    18.  
    19. [void][System.Runtime.Interopservices.Marshal]::ReleaseComObject($excelWb)
    20. [void][System.Runtime.Interopservices.Marshal]::ReleaseComObject($excelObj)
    21. [GC]::Collect()
    22.  
    23. #Create final file
    24. $miaclient.MIReplaceCacheFile($outputFile)
    25.  
    26. $miaclient.MILogMsg("Ended converting from ODS to CSV.")
    27. }
    28. catch
    29. {
    30. #make a log entry
    31. $miaclient.MISetErrorCode(10000)
    32. $miaclient.MISetErrorDescription("Error: " + $_)
    33. }

     

    Selected as Best
  • Brad Carey (Customer)

    Frustratingly enough, step 1 was the cure to my problem:

    Capture 

    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:

    1. try
    2. {
    3. #get the cache filename
    4. $inputFile = $miaclient.MICacheFilename()
    5.  
    6. #get a new cache filename
    7. $outputFile = $miaclient.MINewCacheFilename()
    8. #make a log entry
    9. $miaclient.MILogMsg("Started converting from ODS to CSV.")
    10.  
    11. $excelObj = New-Object -comobject excel.application
    12.  
    13. $excelWb = $excelObj.Workbooks.Open($inputFile)
    14. $excelWb.SaveAs($outputFile,6)
    15. $excelWb.Close($false)
    16.  
    17. $excelObj.Quit()
    18.  
    19. [void][System.Runtime.Interopservices.Marshal]::ReleaseComObject($excelWb)
    20. [void][System.Runtime.Interopservices.Marshal]::ReleaseComObject($excelObj)
    21. [GC]::Collect()
    22.  
    23. #Create final file
    24. $miaclient.MIReplaceCacheFile($outputFile)
    25.  
    26. $miaclient.MILogMsg("Ended converting from ODS to CSV.")
    27. }
    28. catch
    29. {
    30. #make a log entry
    31. $miaclient.MISetErrorCode(10000)
    32. $miaclient.MISetErrorDescription("Error: " + $_)
    33. }

     

    Selected as Best