使用Powershell从Avaya导出数据

使用Powershell从Avaya导出数据,powershell,vbscript,avaya,Powershell,Vbscript,Avaya,我在Access数据库中有一个宏(32位),用于从Avaya CMS下载数据,但由于一些软件更改,我无法再使用它。我考虑过使用Powershell(在32位模式下运行)来获取所需的数据,但无论出于什么原因,它都不起作用 Access数据库中的宏通常如下所示: Option Compare Database Option Explicit Dim cvsApp As cvsApplication Dim cvsCon As cvsConnection Dim cvsSrv

我在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
对象$cvsSrv根本看不到连接。 它在第$cvsSrv.Reports.ACD=“1”行失败,表示“在此对象上找不到属性‘ACD’。请验证该属性是否存在并可以设置。” 脚本使用$cvsSrv的任何行都只返回错误

我试着在网上寻找,但我觉得我是地球上唯一一个想娶Avaya和Powershell的人


任何帮助都将不胜感激。

该消息意味着,
$csvSrv
从未分配任何值

创建COM对象时,它们是空的。当调用函数并将变量作为参数传递给它时,必须传递变量,以便函数获取对象并填充它。i、 e

$cvsApp = New-Object -ComObject "ACSUP.cvsApplication"
$cvsCon = New-Object -ComObject "ACSCN.cvsConnection"
$cvsSrv = New-Object -ComObject "ACSUPSRV.cvsServer"
$Rep = New-Object -ComObject "ACSREP.cvsReport"

...

$cvsApp.CreateServer("login", "password", "", "server", $False, "ENU", [ref] $cvsSrv, [ref] $cvsCon)
同样,(从注释中)您必须对
$Rep
对象执行相同的操作:

...

$Info = $cvsSrv.Reports.Reports("Historical\Designer\Call Records SL")

...

If($cvsSrv.Reports.CreateReport($Info, [ref] $Rep)){
    $Rep.TimeZone = "default"
    ...

注意,在这种情况下,您没有通过引用传递
$Info
。这是因为您直接将函数的返回值分配给
$Info
变量。但是对于
$Rep
,因为它是作为参数传递的,所以您必须通过
[ref]
传递它才能使用它。

经过多次尝试和错误后,我无法使它工作,所以我放弃了,尝试了另一种方法。以下是我使用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命令对其进行格式化并将其复制到主表。

您能否提供
$cvsSrv.Reports | Get Member
的输出?您可能需要传递变量。i、 e.
$cvsApp.CreateServer(“登录”、“密码”、“服务器”、“假”、“ENU”、[ref]$cvsSrv、[ref]$cvsCon)
,因为消息暗示,
$csvSrv
从未分配任何值。@AdminOfThings在
$cvsSrv.Reports
中没有任何内容,我收到错误“get Member:您必须为get Member cmdlet指定一个对象。”@HAL9256您可能对某些内容感兴趣,因为我注意到当我分配
$cvsSrv=New Object-ComObject“ACSUPSRV.cvsServer”
时,一个进程“acsSRV.exe”显示在我的进程列表上。然后,当它到达行
$cvsApp.CreateServer
@HAL9256时,第二个出现了“$cvsSrv”现在可以工作了,谢谢。尽管如此,我还是在
$cvsSrv.Reports.CreateReport($Info,$Rep)
上遇到了错误。错误消息说
无效的过程调用或参数
,但至少我有进展了。它仍然给我
无效的过程调用或参数
错误。我将回到原始代码,因为我跳过了“csvCatalog”对象,认为我不需要它,但也许我需要它?我认为问题在于这种引用。我在查询开始时创建了对象,但在VBA中只创建了一个对象
Set-cvsApp=CreateObject(“acsup.cvsApplication”)
您是否可以在不在powershell中为变量创建对象的情况下将一个Comobject分配给变量?因为即使我指定了
CreateReport($Info,[ref]$Rep)
,当我在process manager中查看时,
acsRep.exe
的一个新实例也会出现一秒钟。通常,您只创建一个对象(例如
cvsApp
),然后从那里执行所有工作。您是对的,通过执行
新建对象-ComObject…
您正在创建一个新的COM对象实例,而不是定义变量类型。您可以通过引用传递空的泛型“对象”来绕过它,它们可能会作为正确的“acsup.x”对象返回。
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
}