I had a macro in Access database (32 bit) that used to download data from Avaya CMS but due to some software changes I cannot use it anymore. I considered using Powershell (run in 32 bit mode) to get the required data but it doesn't work for whatever reason...
The macro in Access Database used to look like this:
Option Compare Database
Option Explicit
Dim cvsApp As cvsApplication
Dim cvsCon As cvsConnection
Dim cvsSrv As cvsServer
Dim cvsacd As cvsacd
Dim cvsCatalog As cvsCatalog
Dim cvsRpt As cvsReport
Dim b As Object
Dim Info As Object
Global Const myAppName As String = "CMS Agent Data"
Global Const myPath As String = "\\Data\Avaya\TempFiles\"
Sub AvayaLogin()
Set cvsApp = CreateObject("acsup.cvsApplication")
If cvsApp.CreateServer("login", "password", "", "server", False, "ENU", cvsSrv, cvsCon) Then
If cvsCon.Login("login", "password", "server", "ENU") Then
End If
End If
End Sub
Sub AvayaLogout()
On Error Resume Next
'Closes out all Avaya
cvsCon.Logout
cvsCon.Disconnect
Set cvsSrv = Nothing
Set cvsCon = Nothing
Set cvsApp = Nothing
End Sub
Sub AbnCallsData()
On Error Resume Next
Dim MyStartDate, MyStartTime(4), MyStopDate, MyStopTime(4), LastUpdateDate, LastUpdateTime, TimeZoneCounter As Integer, NNow, CNow
Dim TEXT1 As String
Dim FSO
Const TimeZone = 4
'Mop up previous days with this query
LastUpdateDate = DMin("Date", "SQL_LastUpdate")
LastUpdateTime = DMin("Time", "SQL_LastUpdate")
If LastUpdateDate = Date Then
LastUpdateDate = DMax("Date", "SQL_LastUpdate")
LastUpdateTime = DMax("Time", "SQL_LastUpdate")
End If
NNow = Format(Now(), "yyyy/mm/dd hh:nn:ss")
MyStartDate = LastUpdateDate
MyStartTime(1) = "00:00:00"
MyStopTime(1) = "10:00:00"
MyStartTime(2) = "10:00:00"
MyStopTime(2) = "12:00:00"
MyStartTime(3) = "12:00:00"
MyStopTime(3) = "15:00:00"
MyStartTime(4) = "15:00:00"
MyStopTime(4) = "23:59:59"
DoCmd.OpenForm "FrmPleaseWait"
'Forms!FrmUpdatecms.Visible = False
DoCmd.RepaintObject acForm, "FrmPleaseWait"
Do Until MyStartDate = Date + 1
MyStopDate = MyStartDate
For TimeZoneCounter = 1 To TimeZone
If LastUpdateDate = Date And Format(LastUpdateTime, "hh:mm:ss") > MyStopTime(TimeZoneCounter) Then
'Skip first few time zones if applicable
Else
CNow = Format(MyStartDate, "yyyy/mm/dd") & " " & MyStartTime(TimeZoneCounter)
'End if after last time zone
If NNow < CNow Then
cvsRpt.Quit
Exit For
End If
If LastUpdateDate = Date And Format(LastUpdateTime, "hh:mm:ss") >= MyStartTime(TimeZoneCounter) And Format(LastUpdateTime, "hh:mm:ss") <= MyStopTime(TimeZoneCounter) Then
' Go back 30 minutes from latest record for same day
MyStartTime(TimeZoneCounter) = (Format(LastUpdateTime - 1 / 48, "hh:mm:ss"))
End If
cvsSrv.Reports.ACD = "1"
Set cvsCatalog = cvsSrv.Reports
'OPENS THE AVAYA REPORT FOR CALL RECORDS
Set cvsRpt = New cvsReport
'cvsCatalog.CreateReport cvsCatalog.Reports.Item("Historical\Other\Call Records"), cvsRpt
Set Info = cvsSrv.Reports.Reports("Historical\Designer\Call Records SL")
b = cvsSrv.Reports.CreateReport(Info, cvsRpt)
'INPUTS THE REPORT CRITERIA
'STARTDATE
If cvsRpt.SetProperty("Start Date", MyStartDate) Then
Else
End If
'STARTTIME
If cvsRpt.SetProperty("Start Time", MyStartTime(TimeZoneCounter)) Then
Else
End If
'STOP DATE
If cvsRpt.SetProperty("Stop Date", MyStopDate) Then
Else
End If
'STOP TIME
If cvsRpt.SetProperty("Stop Time", MyStopTime(TimeZoneCounter)) Then
Else
End If
'Exports the Avaya report
cvsRpt.FastLoad = True
cvsRpt.ExportData myPath & "CallRecords" & ".CSV", 44, 0, True, True, True
'Copy to SQL Server Box
Set FSO = CreateObject("Scripting.FileSystemObject")
If (FSO.FileExists(TSQLPath & "CallRecords" & ".CSV")) Then FSO.DeleteFile (TSQLPath & "CallRecords" & ".CSV")
If (FSO.FileExists(myPath & "CallRecords" & ".CSV")) Then FSO.CopyFile myPath & "CallRecords" & ".CSV", TSQLPath & "CallRecords" & ".CSV"
'Update Data in TSQl Server
Call Update_SQL1
If (FSO.FileExists(TSQLPath & "CallRecords" & ".CSV")) Then FSO.DeleteFile (TSQLPath & "CallRecords" & ".CSV")
cvsRpt.Quit
End If
Next TimeZoneCounter
MyStartDate = MyStartDate + 1
Loop
DoCmd.Close acForm, "FrmPleasewait"
Call Update_SQL2
Call AvayaLogout
End Sub
I have transformed it into something like this in Powershell:
$cvsApp = New-Object -ComObject "ACSUP.cvsApplication"
$cvsCon = New-Object -ComObject "ACSCN.cvsConnection"
$cvsSrv = New-Object -ComObject "ACSUPSRV.cvsServer"
$Rep = New-Object -ComObject "ACSREP.cvsReport"
function Get-CallRecordDates {
some sql queries to get the dates I need to run it for
}
$dates = Get-CallRecordDates
$cvsCon.bAutoRetry = $true
$cvsApp.CreateServer("", "", "", "", $False, "ENU", [ref] $cvsSrv, [ref] $cvsCon) #Thank you HAL9256
$cvsCon.Login("", "", "", "ENU")
$cvsSrv.Reports.ACD = "1"
for($i=0; $i -lt $dates.Table.Rows.Count; $i++)
{
$maindate = Get-Date "$(Get-Date $dates.Table.Rows.Item($i).Date -Format 'dd/MM/yyyy') $(Get-Date $dates.Table.Rows.Item($i).Time -Format 'HH:mm')"
if($dates.Item($i).Commentary -eq "Last"){
$startdatetime = $maindate.AddHours(-2)
$enddatetime = Get-Date
}else{
$startdatetime = $maindate.AddHours(-1)
$enddatetime = $maindate.AddHours(1)
}
$startdate = Get-Date $startdatetime -Format "dd/MM/yyyy"
$starttime = Get-Date $startdatetime -Format "HH:mm"
$enddate = Get-Date $enddatetime -Format "dd/MM/yyyy"
$endtime = Get-Date $enddatetime -Format "HH:mm"
$Info = $cvsSrv.Reports.Reports("Historical\Designer\Call Records SL")
If($cvsSrv.Reports.CreateReport($Info,$Rep)){
$Rep.TimeZone = "default"
$Rep.SetProperty("Start Date",$startdate)
$Rep.SetProperty("Start Time",$starttime)
$Rep.SetProperty("Stop Date",$enddate)
$Rep.SetProperty("Stop Time",$endtime)
$Rep.FastLoad = $True
$Rep.ExportData("C:\Users\me\Desktop\CallRecords$($i).csv", 44, 0, $True, $True, $True)
}
$dates = Get-CallRecordDates
}
$Rep.Quit()
$cvsCon.Logout()
$cvsCon.Disconnect()
The object $cvsSrv just doesn't see the connection at all. It fails on line $cvsSrv.Reports.ACD = "1" saying "The property 'ACD' cannot be found on this object. Verify that the property exists and can be set." Any lines where the script is using $cvsSrv just returns error.
I tried looking online but I feel like I'm the only person on Earth who tried to marry Avaya and Powershell...
Any help will be appreciated.