CrestronSession Module

The CrestronSession module enables a communication channel with the Crestron devices via the CTP port 41795 or the secure port 41797 to send and receive the console commands. It does not require Crestron Toolbox, a COM server, or any Crestron Toolbox scripting.

Use the following cmdlet to import the CrestronSession module in the current PowerShell session:

Copy
Import-Module PSCrestron

The following cmdlets are available for the CrestronSession module:

  • Open-CrestronSession
  • Invoke-CrestronSession
  • Close-CrestronSession
  • Invoke-CrestronCommand

For example:

Use the following syntax to obtain the device version:

Copy
$s = Open-CrestronSession 'CP3-7F123456'
Invoke-CrestronSession $s '' | Out-Null
Invoke-CrestronSession $s 'ECHO OFF' | Out-Null
$x = Invoke-CrestronSession $s 'VER -V'
Close-CrestronSession $s
$ver = [Regex]::Match($x,'(?<=(\[v))[\d\.]+').Value

NOTE: The Invoke-CrestronSession $s '' clears the buffer and the Invoke-CrestronSession $s 'ECHO OFF' prevents the command from being echoed back in the response.

The Open-CrestronSession cmdlet supports authentication. It is recommended to use named parameters in the call.

For example:

Copy
$s = Open-CrestronSession -Secure -Username 'admin' -Password 'Pa$$w0rd'

The Invoke-CrestronCommand cmdlet function is used to open a socket, send the command, and close the socket. It accepts an array of commands via the pipeline. If a single command is used, a scalar is displayed. If there is a collection of commands, an array of responses is displayed in the same order of commands.

For example:

Copy
$x = 'VER -V','INFO','FREE' | Invoke-CrestronCommand -Device 'CP3-7F123456'