powershellscriptingcontent-management-systemavaya

Modifying an Avaya CMS script (.acsauto) with Powershell and the resulting script won't run


I have an avaya CMS script that is setup to extract team data so it can be imported into Power BI. The script is working fine, but I have to go in and manually edit the file in Notepad ++ each month so that it exports to a new file name and gets the correct dates reporting. I am trying to write a Powershell script that will automatically update the relevant information in the Avaya script and run the Avaya script to output my data. The powershell script that I wrote appears to work, it outputs an Avaya script that matches my original working script exactly with every character matching when viewed in notepad++. However the script that is output won't run in Avaya. Also I noticed that the file size is 6KB when the original is 3KB. But when viewed in Notepad there is not a single difference. Is something in my powershell script breaking the Avaya script? Putting the scripts below for reference.

Power Shell Script:

$content = Get-Content -path "C:\Users\MM24363\OneDrive - MassMutual\QA\Tools scripts etc\power bi export file test.acsauto" -Raw
$month = get-date -format "MM"
$day = get-date -format "dd"
$year = get-date -format "yyyy"
$today = get-date
$lastday = [DateTime]::DaysInMonth($today.year, $today.Month)
$datesstart = $content.LastIndexof("Dates")
$datesstart = $datesstart +8
$datessub = $content.Substring($datesstart,21)
$quote = write-output '"'
$datesnew = Write-Output "$month/1/$year-$month/$lastday/$year$quote"
$content.replace($datessub,$datesnew) > "C:\Users\MM24363\OneDrive - MassMutual\QA\Tools scripts etc\powershell scripting target.acsauto"
$content = Get-Content -path "C:\Users\MM24363\OneDrive - MassMutual\QA\Tools scripts etc\powershell scripting target.acsauto" -Raw
$pathstart = $content.lastindexof("Stats\")
$pathstart = $pathstart +6
$pathsub  = $content.substring($pathstart,7)
$pathnew = write-output "$month-$year"
$content.replace($pathsub,$pathnew) > "C:\Users\MM24363\OneDrive - MassMutual\QA\Tools scripts etc\powershell scripting target.acsauto"
$retro=(get-date).date.addmonths(-1)
$lastmonth = $retro.tostring("MM")
$lastmonthyear = $retro.year
$content = Get-Content -path "C:\Users\MM24363\OneDrive - MassMutual\QA\Tools scripts etc\powershell scripting target.acsauto" -Raw
$lmpathnew = write-output "$lastmonth-$lastmonthyear"

$endoflastmonth = (Get-Date -Day 1).AddDays(-1).ToString("dd")
$lmdatenew = write-Output "$lastmonth/1/$lastmonthyear-$lastmonth/$endoflastmonth/$lastmonthyear"
$content.replace($pathnew,$lmpathnew).replace($datesnew,$lmdatenew) > "C:\Users\MM24363\OneDrive - MassMutual\QA\Tools scripts etc\last month.acsauto"

Avaya Script

'LANGUAGE=ENU
'SERVERNAME=170.6.243.18
Public Sub Main()

'## cvs_cmd_begin
'## ID = 2001
'## Description = "Report: Historical: Designer: Field Group Daily Summary: Export Data"
'## Parameters.Add "Report: Historical: Designer: Field Group Daily Summary: Export Data","_Desc"
'## Parameters.Add "Reports","_Catalog"
'## Parameters.Add "2","_Action"
'## Parameters.Add "1","_Quit"
'## Parameters.Add "Historical\Designer\Field Group Daily Summary","_Report"
'## Parameters.Add "1","_ACD"
'## Parameters.Add "-180","_Top"
'## Parameters.Add "255","_Left"
'## Parameters.Add "28335","_Width"
'## Parameters.Add "16575","_Height"
'## Parameters.Add "default","_TimeZone"
'## Parameters.Add "The report Historical\Designer\Field Group Daily Summary was not found on ACD 1.","_ReportNotFound"
'## Parameters.Add "*","_BeginProperties"
'## Parameters.Add "Erroll Team","Agent Group"
'## Parameters.Add "6/1/2022-6/30/2022","Dates"
'## Parameters.Add "*","_EndProperties"
'## Parameters.Add "*","_BeginViews"
'## Parameters.Add "*","_EndViews"
'## Parameters.Add "C:\Users\mm24363\OneDrive - MassMutual\QA\Avaya Reportin\june export.csv","_Output"
'## Parameters.Add "9","_FldSep"
'## Parameters.Add "0","_TextDelim"
'## Parameters.Add "True","_NullToZero"
'## Parameters.Add "True","_Labels"
'## Parameters.Add "False","_DurSecs"

   On Error Resume Next

   cvsSrv.Reports.ACD = 1
   Set Info = cvsSrv.Reports.Reports("Historical\Designer\Field Group Daily Summary")

   If Info Is Nothing Then
      If cvsSrv.Interactive Then
          MsgBox "The report Historical\Designer\Field Group Daily Summary was not found on ACD 1.", vbCritical Or vbOKOnly, "Avaya CMS Supervisor"
      Else
          Set Log = CreateObject("ACSERR.cvsLog") 
          Log.AutoLogWrite "The report Historical\Designer\Field Group Daily Summary was not found on ACD 1."
          Set Log = Nothing
      End If
   Else

       b = cvsSrv.Reports.CreateReport(Info,Rep)
       If b Then
    
          Rep.Window.Top = -180
          Rep.Window.Left = 255
          Rep.Window.Width = 28335
          Rep.Window.Height = 16575        
    

                        Rep.TimeZone = "default"


    
          Rep.SetProperty "Agent Group","Erroll Team"
    
          Rep.SetProperty "Dates","07/1/2022-07/31/2022"
    
    
    

          b = Rep.ExportData("C:\Users\mm24363\OneDrive - MassMutual\Brians Folder\Field Individual Avaya Stats\07-2022 export.csv", 9, 0, True, True, False)

    

    

          Rep.Quit

    

              If Not cvsSrv.Interactive Then cvsSrv.ActiveTasks.Remove Rep.TaskID
          Set Rep = Nothing
       End If

   End If
   Set Info = Nothing
'## cvs_cmd_end

End Sub

Solution

  • @TheMadTechnician thank you, this was the issue. Powershell had no issue reading the file into a string so it never occurred to me there might be an encoding issue. The working script was using UTF-8 but powershell was outputting in UTF-16 LE BOM. I added a line at the start of the script to change the default to UTF-8 and now the output scripts run as expected. Thank you.