DMT via PowerShell

So I’m trying to automate DMT via PowerShell. I already created a script but when I paste it, I need to hit the “enter” key on my keyboard to execute. I already tried different methods to make it work but unfortunately is not working.

Any experts here that can take a look at it and let me know what I’m doing wrong or what is missing?

Thanks all

# ===============================
# Epicor DMT Automated Script
# ===============================

# -------------------------------
# Configuration
# -------------------------------
$DMTPath = “C:\Epicor\ERP12\LocalClients\Kinetic\DMT.exe” # Change to your DMT path
$User = “” # Epicor username
$Pass = “” # Epicor password
$Config = “C:\Epicor\ERP12\LocalClients\Kinetic\config\Kinetic.sysconfig” # Epicor client config
$ImportName = “Customer” # Name of the DMT import
$SourceDir = “C:\Users\Administrator\Desktop\Epicor DMT\Data” # Folder with CSV files to import
$ProcessedDir = “C:\Users\Administrator\Desktop\Epicor DMT\Archive” # Folder for successfully processed files
$ErrorDir = “C:\Users\Administrator\Desktop\Epicor DMT\Errors” # Folder for failed files
$LogFile = “C:\Users\Administrator\Desktop\Epicor DMT\Logs\DMT_Run_$(Get-Date -Format ‘yyyyMMdd_HHmmss’).log”

# Create folders if they don’t exist
foreach ($folder in @($ProcessedDir, $ErrorDir, (Split-Path $LogFile))) {

  • if (!(Test-Path $folder)) { New-Item -ItemType Directory -Path $folder | Out-Null }*
    }

# -------------------------------
# Start Logging
# -------------------------------
“===== DMT Run Started: $(Get-Date) =====” | Out-File -FilePath $LogFile -Encoding UTF8

# -------------------------------
# Process each CSV file
# -------------------------------
*Get-ChildItem -Path $SourceDir -Filter .csv | ForEach-Object {

  • $file = $_.FullName*
  • “Processing file: $file” | Out-File -FilePath $LogFile -Append*
  • try {*
  •    $arguments = "-User $User -Pass $Pass -ConfigValue $Config -NoUI -DisableUpdateService -Add -Update -Import `"$ImportName`" -Source `"$file`""*
    
  •    *
    
  •    $process = Start-Process -FilePath $DMTPath -ArgumentList $arguments -Wait -PassThru -NoNewWindow*
    
  •    if ($process.ExitCode -eq 0) {*
    
  •        "SUCCESS: $file processed successfully." | Out-File -FilePath $LogFile -Append*
    
  •        Move-Item -Path $file -Destination $ProcessedDir*
    
  •    } else {*
    
  •        "ERROR: $file failed with exit code $($process.ExitCode)." | Out-File -FilePath $LogFile -Append*
    
  •        Move-Item -Path $file -Destination $ErrorDir*
    
  •    }*
    
  • } catch {*
  •    "EXCEPTION: Failed to process $file. $_" | Out-File -FilePath $LogFile -Append*
    
  •    Move-Item -Path $file -Destination $ErrorDir*
    
  • }*
    }

“===== DMT Run Completed: $(Get-Date) =====`n” | Out-File -FilePath $LogFile -Append

1 Like

Hi Mauricio,

Can you share a quick list of what you tried already?

2 Likes

You havnt said what you want that’s not working

If you’re pasting the entire script on a command line then yes enter to execute would be expected

You could save the script with .ps1 file extension then open in PowerShell ISE and click the run button. Or schedule a task to run the ps1 script periodically.

2 Likes

Tried doing this in PowerShell in different ways, BUT the good news is that I was able to convert all this into a simple CMD script and seems to be working as expected without any issues. Also, the scheduled task is working as well.

Sharing the script in case helps anyone, thanks all who tried to help :slight_smile: :heart:

C:\Epicor\ERP12\LocalClients\Kinetic\DMT.exe -NoUI -User=**** -Pass=***** -Import=“Customer” -Source=“C:\Users\Administrator\Desktop\Epicor DMT\Data\Customer.csv” -Add -Update

1 Like