使用 Powershell 从 Avaya 导出数据

杰瑞克·什奇格

我在 Access 数据库(32 位)中有一个宏,用于从 Avaya CMS 下载数据,但由于某些软件更改,我无法再使用它。我考虑过使用 Powershell(以 32 位模式运行)来获取所需的数据,但无论出于何种原因它都不起作用......

Access 数据库中的宏过去看起来像这样:

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

我已经在 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()

对象 $cvsSrv 根本看不到连接。它在 $cvsSrv.Reports.ACD = "1" 行失败,说“在此对象上找不到属性 'ACD'。验证该属性是否存在并且可以设置。” 脚本使用 $cvsSrv 的任何行都会返回错误。

我尝试在网上查找,但我觉得我是地球上唯一一个试图将 Avaya 和 Powershell 结合的人......

任何帮助将不胜感激。

杰瑞克·什奇格

经过多次试验和错误,我无法使其工作,所以我放弃并尝试了不同的方法。这是我使用 PowerShell 将数据从 Avaya 上传到 SQL Server 所运行的整个脚本:

if(Get-Module -ListAvailable -Name SqlServer) {} else {Install-Module -Name SqlServer -AllowClobber -Confirm:$False -Force} #installs SqlServer module if not installed

function Get-CallRecordDates {
Invoke-Sqlcmd -Query “SELECT [Date],[Time],[Commentary] FROM [CallRecords].[dbo].[ForSQLload] order by [Date],[Time]” -ServerInstance "myserver"
}

$dates = @(Get-CallRecordDates)

#declare where the csv files will be saved
$csv = "G:\SQLDataLoad\Avaya"

#declare where the .acsauto file will be saved
$acsauto = "G:\SQLDataLoad\Avaya\CallRecordsJS.acsauto"

#These will format the acsauto file just right
$blockstart = "'LANGUAGE=ENU
'SERVERNAME=AvayaServerAddress
Public Sub Main()

On Error Resume Next

cvsSrv.Reports.ACD = 1
Set Info = cvsSrv.Reports.Reports(`"Historical\Designer\Call Records SL`")

If Info Is not Nothing Then
"

$blockend = "If Not cvsSrv.Interactive Then cvsSrv.ActiveTasks.Remove Rep.TaskID
Set Rep = Nothing

End If
Set Info = Nothing

End Sub"

#Start creating the content for acsauto file
$contentacsauto = $blockstart

#looping through the missing records. If there are none, it will only download the latest data.
for($i=0; $i -lt $dates.Count; $i++)
{
    $maindate = Get-Date "$(Get-Date $dates.Item($i).Date -Format 'dd/MM/yyyy') $(Get-Date $dates.Item($i).Time -Format 'HH:mm')"

    if($dates.Item($i).Commentary -eq "Last"){
        $startdatetime = $maindate.AddHours(-3)
        $enddatetime = Get-Date
        Write-Host "Adding time range to the script; from $startdatetime to $enddatetime `nIt will be exported to $csv\CallRecords-$i.csv`nTime is $(Get-Date) now."
        }else{
        $startdatetime = $maindate.AddHours(-1)
        $enddatetime = $maindate.AddHours(1)
        Write-Host "Adding time range to the script as some CallID is missing in that period; from $startdatetime to $enddatetime `nIt will be exported to $csv\CallRecords-$i.csv"
    }

    #formating the dates and times for the parameters
    $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"

    $MiddleBlock = "
If cvsSrv.Reports.CreateReport(Info,Rep) Then
Rep.TimeZone = `"default`"
Rep.SetProperty `"Start Date`",`"$startdate`"
Rep.SetProperty `"Start Time`",`"$starttime`"
Rep.SetProperty `"Stop Date`",`"$enddate`"
Rep.SetProperty `"Stop Time`",`"$endtime`"
b = Rep.ExportData(`"$csv\CallRecords-$i.csv`", 44, 0, True, True, True)
Rep.Quit
End If
"

    $contentacsauto = $contentacsauto + $MiddleBlock
}

$contentacsauto = $contentacsauto + $blockend

$contentacsauto | Out-File $acsauto -Encoding ascii

& $acsauto

$stop = (Get-Date).AddMinutes(10)

while (((Get-ChildItem $csv -Filter "CallRecord*.csv").Count -lt $i) -and ($(Get-Date) -lt $stop)) {Start-Sleep -Seconds 2}

if($(Get-Date) -ge $stop) {
    Write-Host "This thing timed out as it took longer than 10 minutes to export, at $(Get-Date)"
    Get-Process "acs*" | Stop-Process -PassThru | Out-Null}
else{
Write-Host "Saved $((Get-ChildItem $csv -Filter "CallRecord*.csv").Count) file(s) at $(Get-Date)"

Start-Sleep -Seconds 2

$csvfiles = Get-ChildItem $csv -Filter "CallRecord*.csv"

$callrecords = Import-Csv -Path $csvfiles | Sort-Object 'Call ID','Segment' -Unique

Remove-Item $csvfiles -Force | Out-Null

Invoke-Sqlcmd -Query "delete from CallRecords.dbo.TempCallDataTemp" -ServerInstance "myserver"

Write-SqlTableData -InputData $callrecords -ServerInstance "myserver" -DatabaseName "CallRecords" -SchemaName "dbo" -TableName "TempCallDataTemp" -force
}

基本上,我创建了一个“CallRecords.acsauto”文件,然后运行该文件,等待所有文件准备就绪(检查一下,以防它冻结 10 分钟将其关闭),导入它们并上传到 sql server。然后我调用一堆sql命令对其进行格式化并将其复制到主表中。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

我正在尝试使用来自 Avaya office manager API 的数据。CertificateValidationCallback 导致错误

来自分类Dev

使用Powershell导出Csv

来自分类Dev

可以使用ImportExcel Powershell模块以XLS格式(与XLSX相对)导出数据吗?

来自分类Dev

Powershell CSV命令使用特定列导出

来自分类Dev

如何使用Powershell从门户导出AzureVM配置

来自分类Dev

导入Excel,使用PowerShell导出CSV

来自分类Dev

如何使用 Powershell 正确导出到 CSV

来自分类Dev

我想使用PowerShell同时将脚本的数据导出到2个文本文件中

来自分类Dev

使用New-AzSqlDatabaseExport在Powershell中导出Azure数据库不会总是返回OperationStatusLink,从而导致异常

来自分类Dev

使用JMSSerializerBundle导出大量数据

来自分类Dev

使用CouchbaseCLI cbexport导出数据

来自分类Dev

如何使用JSON导出数据

来自分类Dev

如何从Avaya数据库访问和检索实时数据?

来自分类Dev

是否可以使用Avaya DMCC .NET获取来电的UUI或AAI?

来自分类Dev

使用Powershell从PostgreSQL检索数据

来自分类Dev

使用Powershell从excel选择数据

来自分类Dev

使用Powershell获取MySQL数据

来自分类Dev

使用PowerShell处理CSV数据

来自分类Dev

如何在PowerShell中将数据导出到CSV?

来自分类Dev

Powershell:在* .txt文件中搜索数据以导出到* .csv

来自分类Dev

Powershell:在* .txt文件中搜索数据以导出到* .csv

来自分类Dev

如何在PowerShell中将数据导出到CSV?

来自分类Dev

将捕获的Powershell数据导出到CSV文件

来自分类Dev

Powershell 导出到 csv(保持数据的原始顺序)

来自分类Dev

如何使用Adminer导出数据库?

来自分类Dev

使用maven导出数据库Oracle

来自分类Dev

使用nzsql将数据导出到CSV

来自分类Dev

如何使用fpdf导出变量数据

来自分类Dev

如何使用codeigniter以QIF格式导出数据?

Related 相关文章

  1. 1

    我正在尝试使用来自 Avaya office manager API 的数据。CertificateValidationCallback 导致错误

  2. 2

    使用Powershell导出Csv

  3. 3

    可以使用ImportExcel Powershell模块以XLS格式(与XLSX相对)导出数据吗?

  4. 4

    Powershell CSV命令使用特定列导出

  5. 5

    如何使用Powershell从门户导出AzureVM配置

  6. 6

    导入Excel,使用PowerShell导出CSV

  7. 7

    如何使用 Powershell 正确导出到 CSV

  8. 8

    我想使用PowerShell同时将脚本的数据导出到2个文本文件中

  9. 9

    使用New-AzSqlDatabaseExport在Powershell中导出Azure数据库不会总是返回OperationStatusLink,从而导致异常

  10. 10

    使用JMSSerializerBundle导出大量数据

  11. 11

    使用CouchbaseCLI cbexport导出数据

  12. 12

    如何使用JSON导出数据

  13. 13

    如何从Avaya数据库访问和检索实时数据?

  14. 14

    是否可以使用Avaya DMCC .NET获取来电的UUI或AAI?

  15. 15

    使用Powershell从PostgreSQL检索数据

  16. 16

    使用Powershell从excel选择数据

  17. 17

    使用Powershell获取MySQL数据

  18. 18

    使用PowerShell处理CSV数据

  19. 19

    如何在PowerShell中将数据导出到CSV?

  20. 20

    Powershell:在* .txt文件中搜索数据以导出到* .csv

  21. 21

    Powershell:在* .txt文件中搜索数据以导出到* .csv

  22. 22

    如何在PowerShell中将数据导出到CSV?

  23. 23

    将捕获的Powershell数据导出到CSV文件

  24. 24

    Powershell 导出到 csv(保持数据的原始顺序)

  25. 25

    如何使用Adminer导出数据库?

  26. 26

    使用maven导出数据库Oracle

  27. 27

    使用nzsql将数据导出到CSV

  28. 28

    如何使用fpdf导出变量数据

  29. 29

    如何使用codeigniter以QIF格式导出数据?

热门标签

归档