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