Automate DMT upload – Powershell script

adminEpicor Administration

Requirement

I was doing some work recently with forecasts.

My client was wanting to disable forecasts prior to a weekly run of MRP on a Sunday night.

After a few weeks of manually doing this every Sunday :-(, I decided to schedule the task.

After digging around I found some useful resources that documented how to do it using Powershell and the Task Scheduler.

Since writing the script to deactivate forecast, I have also used it to log out any users who have forgotten to log out of MES at the 23.58 on a working day.

The script below is the one for deactivating forecasts.

Hope this is useful.

<#
 .DESCRIPTION
  Two calls via DMT, on generates a list of employees still clocked on
  This uses the BAQDEACTFORECAST BAQ
  The file is generated in the c:\temp directory
  The file is used as the source file a command line import on the 'TE Labor Combined'
  upload
.PARAMETER <Parameter_Name>
   None
.INPUTS
 $DMTPath  - location of the DMT path
 $User - dmt upload user
 $Pass - dmt upload password
 $Env =- location of the config file
 $DMTLoad - name of the DMT load (needs 2 quotes to allow for spaces in the name)
 $Config - name of the config file
 $Source - file name of the CSV generated by the BAQ 
 $Log - names of the log file
 $completeLog - name of the completed log file
.OUTPUTS
  Log file stored in c:\temp\DeactivateForecasts.csv.CompleteLog
.NOTES
  Version:        1.0
  Author:         Andrew Clements
  Creation Date:  10/01/2018
  Purpose/Change: Initial script development

#>
 
 #Extract Data From From BAQ -> CSV File -> Load in with DMT 
 
 
 $DMTPath = "C:\Epicor\ERP10.1Client\Client\DMT.exe" 
 $User = "******" 
 $Pass = "******" 
 $Env = "net.tcp://*******/EpicorERP”
 $DMTLoad = "Forecast"
 $Config = "EpicorERP"
 
 $Source = "C:\Powershell\DeactivateForecasts.csv" 
 $Log = "C:\Powershell\DeactivateForecasts.log" 
 $completeLog = "C:\Powershelgl\DeactivateForecasts.csv.CompleteLog.txt" 
 
 
 Write-Output "Extracting Data via BAQ $(get-date)" 
 
 
 Start-Process -Wait -FilePath $DMTPath -ArgumentList "-ConnectionUrl $Env -User $User -Pass $Pass -Export -BAQ BAQDEACTFORECAST -Target  $Source -NoUI  -ConfigValue $Config" 
 Write-Output "Loading Data $(get-date) " $Source  
 

 #Load Data $
 Start-Process -Wait -FilePath $DMTPath -ArgumentList "-ConnectionUrl $Env -User $User -Pass $Pass -Add=false -Update=true -Import ""Forecast"" -Source $Source -NoUI -ConfigValue $Config -logfile $Log" 
 
 
 #Check Results 
 select-string -Path $completeLog -Pattern "Records:\D*(\d+\/\d+)" -AllMatches | % { $_.Matches.Groups[0].Value } 
 select-string -Path $completeLog -Pattern "Errors:\D*(\d+)" -AllMatches | % { $_.Matches.Groups[0].Value }