Nachfolgendes Powershell-Script exportiert ACD Daten aus einer Avaya ACD. Dabei wird eine Verbindung via plink (*1) zur ACD aufgebaut und via OSSI-Protokoll der gewünschte Befehl übergeben. Die Ausgabe der ACD wird dann kommasepariert in ein Textfile geschrieben.

#------------------------------------------------------------------------------------------------------
# Powershell-Script for exporting ACD-data using plink (*)
#
# version: 1.0
# date:    01.05.2015
# author:  Andre Röder
#
# (*) http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
#------------------------------------------------------------------------------------------------------

# plink.exe-path
$plink_path = "C:\Temp\plink.exe"

# check if plink.exe exists in plink_path
# if not, download plink.exe and save it
If (-Not(Test-Path $plink_path)){
$webclient = New-Object System.Net.WebClient
$url = "http://the.earth.li/~sgtatham/putty/latest/x86/plink.exe"
$webclient.DownloadFile($url,$plink_path)
Start-Sleep -s 10
}

# ACD ip and port
$acd_ip = "192.168.178.1"
$acd_port = "5022"

# user and password
$user=Read-Host -Prompt "Please insert user!"
$response = Read-host "Please insert your password!" -AsSecureString
$password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($response))

# ACD-command
$command=Read-Host -Prompt "Please insert ACD-command!"

# output textfile-path
$output_path = "C:\Temp\output.txt"

# define plink.exe process and forward input and output
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = $plink_path + """ -ssh" + " " + $acd_ip + " -P " + $acd_port + """"
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.RedirectStandardInput = $true
$pinfo.UseShellExecute = $false
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$stdin = $p.StandardInput
$stdin.AutoFlush = $true
$stdout = $p.StandardOutput
$stderr = $p.StandardError
Start-Sleep -s 2

# Is there already a sshhostkey in the registry?
$sshhostkey_exists = get-itemproperty HKCU:\Software\SimonTatham\PuTTY\SshHostKeys ("rsa2@" + $acd_port + ":" + $acd_ip) -ErrorAction SilentlyContinue
if (($sshhostkey_exists -eq $null) -or ($sshhostkey_exists.Length -eq 0))
{
   $stdin.WriteLine("n")
}
Start-Sleep -s 1

# start login in to the ACD
$stdin.WriteLine($user)
Start-Sleep -s 1
$stdin.WriteLine($password)
Start-Sleep -s 1
$stdin.WriteLine("ossi")
Start-Sleep -s 1

# send command
$stdin.WriteLine("c" + $command)
$stdin.WriteLine("t")
Start-Sleep -s 2

# get output before c+command and ignore it
$temp
do{
   $temp = $stdout.ReadLine()   
}
until ($temp.startswith("c" + $command))

# clear variable for the needed output
clear-variable -name temp

# write needed output in variable
$output = ""
do{
   $temp = $stdout.ReadLine()
   $output = $output + "`r`n" + $temp
}
until ($temp.startswith("t"))
clear-variable -name temp

# find first dataset and delete all data before
$index_first_dataset = $output.IndexOf("`r`n" + "d")
$datarows = $output.Remove(0, $index_first_dataset)

# delete "t"-row
$datarows = $datarows.Replace("`r`n" + "t", "")

# replace "n" with CrLf and "d" with ","
$datarows = $datarows.Replace("`r`n" + "d", ",")
$datarows = $datarows.Replace("`r`n" + "n", "`r`n")

# replace TAB within the dataset with ","
$datarows = $datarows.Replace("`t", ",")

# write datarows to textfile
$datarows > $output_path

# logoff and close plink process
$stdin.WriteLine("logoff")
Start-Sleep -s 1
$stdin.WriteLine("y")
Start-Sleep -s 1
$stdin.Close()
$stdout.Close()
$stderr.Close()
$p.Kill()
$p.Close()















(*1) plink - http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html