christaylorcodes / ConnectWiseControlAPI

PowerShell wrapper for ConnectWise Control
MIT License
71 stars 38 forks source link

GetHostSessionInfo changed to GetLiveData #23

Open meanturtle opened 10 months ago

meanturtle commented 10 months ago

It looks like in the latest version of Connectwise Control the following endpoint has changed name.

$Endpoint = 'Services/PageService.ashx/GetHostSessionInfo'

$Endpoint = 'Services/PageService.ashx/GetLiveData'

I have updated the Get-CWCSession.ps1 to see can I get it to work but receiving an error index out of range.

Possibly due to action center in the payload: [{"HostSessionInfo":{"sessionType":2,"sessionGroupPathParts":["All Machines"],"filter":"","findSessionID":"GUIDKEY","sessionLimit":1000},"ActionCenterInfo":{}},340713519]

Have tried changing $Body = ConvertTo-Json @($Number,@($Group),$Search,$null,$Limit)

to

$Body = ConvertTo-Json @($Number,@($Group),$Search,$null,$Limit),($null) and different variations but my knowledge of how that works is limited

meanturtle commented 10 months ago

Line | 33 | $Data = Invoke-CWCWebRequest -Arguments $WebRequestArguments | ~~~~~~~~~~~~ | An error has been thrown. --> --> {"errorType":"ArgumentException","message":"Unable to process arguments: | Index was out of range. Must be non-negative and less than the size of the collection.\r\nParameter name: | index","detail":null} at Invoke-CWCWebRequest, | C:\Users\Documents\PowerShell\Modules\ConnectWiseControlAPI\0.3.5.0\Private\Invoke-CWCWebRequest.ps1: line 25 at Get-CWCSession, C:\Users\Documents\PowerShell\Modules\ConnectWiseControlAPI\0.3.5.0\Public\PageService\Get-CWCSession.ps1: line 33 at , C:\: line 123 at , : line 1

twistedpro commented 9 months ago

It's not pretty, but I found updating Get-CWCSession.ps1 with the below has worked for me with the same results as previously. So no modification to any implementations you have already coded :).

function Get-CWCSession {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory=$True)]
        [ValidateSet('Support','Access','Meeting')]
        $Type,
        [string]$Group = $script:defaultGroup,
        [string]$Search,
        [int]$Limit
    )

    $Endpoint = 'Services/PageService.ashx/GetLiveData'

    switch($Type){
        'Support' { $Number = 0 }
        'Meeting' { $Number = 1 }
        'Access' { $Number = 2 }
        default { return Write-Error "Unknown Type, $Type" }
    }

    #$Body = ConvertTo-Json @($Number,@($Group),$Search,$null,$Limit)

    Write-Debug $Group

    $Body = @"
[
    {
        `"HostSessionInfo`": {
            `"sessionType`": 2,
            `"sessionGroupPathParts`": [
                `"$Group`"
            ],
            `"filter`": `"$Search`",
            `"findSessionID`": null,
            `"sessionLimit`": 1000
        },
        `"ActionCenterInfo`": {}
    },
    0
]
"@

    Write-Verbose $Body

    $WebRequestArguments = @{
        Endpoint = $Endpoint
        Body = $Body
        Method = 'Post'
    }

    $Data =  Invoke-CWCWebRequest -Arguments $WebRequestArguments
    $Data.ResponseInfoMap.HostSessionInfo.sessions
    #$Data.sessions
}
meanturtle commented 9 months ago

Thank you. That works perfectly. Im back in action.

Kry07 commented 9 months ago

Thank you alot !

CitybookServicesLTD commented 7 months ago

Thank you @twistedpro You resolved my issue too.