3cx API and powershell

Status
Not open for further replies.

webturtle

Joined
May 28, 2015
Messages
3
Reaction score
0
Good morning.

I use a powershell script to monitor the status of my trunks, because i have an issue with my firewall and have to empty its connection table after a reconnect sometimes.

The thing seems to work, but one small problem:
I can only connect to 3 CX from one version of the script. A second connect is only possible after a reboot of the server.
For example:
I try to develop the script in the Powershell ISE and everything works.
If I start the script as a service, i get a not connected error.
If i reboot, the service works.

If i restart the service or have to change something inside the script after some days, i have to reboot the server.

I cannot figure out how to disconnect cleanly.

Here is the 3CX Part of the Script:

Code:
$3CXInstallDir=(Get-WmiObject -Class Win32_Product | where {$_.name -like "3cx*Phone*System*"}).installLocation
        
    [void][System.Reflection.Assembly]::LoadFile("$3CXInstallDir\Instance1\Bin\3cxpscomcpp2.dll") 
    [void][TCX.Configuration.PhoneSystem]::set_cfgserverhost("127.0.0.1") 
    [void][TCX.Configuration.PhoneSystem]::set_cfgserverport("5485") 
    [void][TCX.Configuration.PhoneSystem]::set_ApplicationName("CallViewer") 
    [void][TCX.Configuration.PhoneSystem]::set_cfgserveruser("cfguser_default")
    [void][TCX.Configuration.PhoneSystem]::set_cfgserverpassword("**********")
    
    $global:My3CX = [TCX.Configuration.PhoneSystem]::get_Root() 
    
    $global:Tenant = [TCX.Configuration.PhoneSystem]::Root.GetTenants()
    
    if (( $Tenant[0].GetExternalLines() | where {($_.Number -eq "10002") -and (!$_.IsRegistered)}))
        {
            echo Nicht-Registriert

            cd "C:\Program Files (x86)\PuTTY\"
            Start-Sleep -Seconds 30
            .\plink.exe "does a command to empty the connection tracking in my firewall"

        }
        else
        {
            echo Registriert
        }

    #$My3CX.Disconnect()

I tried the disconnect command, but that freezes the whole thing and after that a reconnect is not possible.
 
That is some bad a$$ code. Would you consider posting and sharing? With some community involvement and testing we could probably get that figured out and extended.

Nice work.
 
Status
Not open for further replies.