Jan Pichrt

Royal TS & PowerShell: Dynamic Folder Ping Discovery

In this blog post, we’re going to explore a powerful feature of Royal TS – dynamic folders. Dynamic folders in Royal TS allow you to automatically populate connections based on a script. We’ll guide you through a simple yet effective PowerShell script that pings all devices within a specified IP range and returns only the live devices. This script can be used to create a dynamic folder in Royal TS, providing you with an up-to-date view of all active devices in your network. Whether you’re a network administrator or an IT professional, this script will be a valuable addition to your toolkit. Let’s get started!

Royal TS is a comprehensive software solution designed to centralize and simplify remote management. Whether you’re dealing with a handful of devices or managing a large-scale network, Royal TS provides a unified interface for seamless access to your systems. It supports a wide range of protocols, including RDP, VNC, SSH, and many more. One of its standout features is the ability to create dynamic folders using scripts, which automatically populate connections based on your criteria. This makes Royal TS an invaluable tool for IT professionals seeking efficient, organized, and secure remote management.

Script bellow will ping devices in specified IP range and create connections in your Royal TS dynamic folder. The result will be similar to what you see in the picture below. The names are generated automatically based on the IP address and prefix defined in the script variables.

Note that the script below is written using the Test-Connection cmdlet and its TimeoutSeconds parameter, which is only available in PowerShell 7.x.!

Update variables or IP definition according to your needs.

# Define variables
$site = 45
$prefix = "PRAGUE-SW-"
$ipStart = 1
$ipEnd = 100

# Create an empty array to store the results
$results = @()

# Loop through the IP range
for ($i = $ipStart; $i -le $ipEnd; $i++) {
    # Construct the IP address
    $ip = "192.168.$site.$i"

    # Ping the IP address
    $ping = Test-Connection -ComputerName $ip -Count 1 -Quiet -TimeoutSeconds 1 -ErrorAction SilentlyContinue

    # Check if the ping was successful
    if ($ping) {
        # Create a new object with the required properties for Royal TS
        $result = New-Object PSObject -Property @{
            Type = 'TerminalConnection'
            Name = $prefix+([string]$i).PadLeft(2,'0')
            ComputerName = $ip
			      CredentialName = 'name_of_your_credentials_stored_in_royalts'
        }

        # Add the result to the array
        $results += $result
    }
}

# Output the results as a single JSON object
$output = New-Object PSObject -Property @{
    Objects = $results
}

# Convert the output to JSON
$output | ConvertTo-Json

Leave a Comment