Skript-Leitfaden: Automatisieren der ConnectWise-URL-Erstellung für macOS

Die wichtigsten Erkenntnisse

  • Das Skript automatisiert den Abruf und die Speicherung von ConnectWise Control Launch-URLs unter macOS, was den Remote-Support erheblich vereinfacht.
  • Es bietet Anpassungsoptionen für Instanz-IDs, Domänen, Sitzungsgruppen und benutzerdefinierte Felder, die auf spezifische IT-Umgebungen zugeschnitten sind.
  • Eine integrierte Hilfefunktion und Fehlerbehandlung verbessert die Benutzerführung und Fehlerbehebung.
  • Der Ansatz des Skripts ist effizienter und übersichtlicher als die manuelle URL-Verwaltung oder einfache Skripting-Lösungen.
  • Sicherheit und kontrollierter Zugriff auf generierte URLs sind für die Aufrechterhaltung der IT-Sicherheit unerlässlich.
  • Es wird empfohlen, das Skript vor dem vollständigen Einsatz in einer bestimmten macOS-Umgebung zu testen.
  • Durch die Integration dieses Skripts in ein umfassenderes Toolset wie NinjaOne können Fernsupport- und IT-Managementaufgaben weiter optimiert werden.

Hintergrund

In der vernetzten IT-Landschaft von heute sind Effizienz und Zuverlässigkeit beim Remote-Support nicht nur Annehmlichkeiten, sondern eine Notwendigkeit. Die fortgeschrittene Skripterstellung, insbesondere im Zusammenhang mit der Verwaltung von Fernwartungssoftware, spielt eine zentrale Rolle bei der Erreichung dieser Ziele. Das Skript, das wir heute besprechen, ist ein Beispiel dafür und bietet einen optimierten Ansatz für die Verwaltung von ConnectWise Control (früher ScreenConnect) Sitzungen unter macOS.

Dieses Bash-Skript ist für IT-Fachleute und Managed Service Provider (MSPs ) gedacht, die ConnectWise Control für den Fernsupport verwenden. Seine Hauptfunktion besteht darin, ConnectWise Control Launch URLs abzurufen und zu speichern, eine entscheidende Komponente bei der Remote-Desktop-Unterstützung. Bei diesem Prozess werden spezifische Instanz-IDs, Domäneninformationen und Sitzungsgruppen verwendet, um genaue und zugängliche URLs zu erstellen. Seine Bedeutung liegt in der Automatisierung einer typischerweise manuellen und zeitaufwändigen Aufgabe, wodurch die Produktivität und die Reaktionszeiten der IT-Supportteams verbessert werden.

Das Skript:

#!/usr/bin/env bash
#
# Description: Retrieves the Connectwise ScreenConnect Launch URL and saves it to a custom field (defaults to screenconnectURL). Requires the domain used for ScreenConnect and a Session Group that all machines are a part of to successfully build the URL.
# By using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https://www.ninjaone.com/terms-of-use.
# Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. 
# Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. 
# Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. 
# Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. 
# Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. 
# Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. 
# EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).
#
# Preset Parameter: --instanceId "ReplaceMeWithYourInstanceId"
#   The Instance ID for your instance of ScreenConnect. Used to differentiate between multiple installed ScreenConnect instances.
#   To get the instance ID, you can see it in the program name, e.g., connectwisecontrol-yourinstanceidhere.
#   It's also available in the ScreenConnect Admin Center (Administration > Advanced > Server Information).
#
# Preset Parameter: --screenconnectDomain "replace.me"
#   The domain used for your ScreenConnect instance.
#
# Preset Parameter: --sessionGroup "ReplaceMe"
#   A session group that contains all of your machines (defaults to All Machines)
#
# Preset Parameter: --customField "ReplaceMeWithAnyMultilineCustomField"
#   The custom field you would like to store this information in.
#
# Preset Parameter: --help
#   Displays some help text.

# These are all our preset parameter defaults. You can set these = to something if you would prefer the script defaults to a certain parameter value.
_arg_instanceId=
_arg_screenconnectdomain=
_arg_sessiongroup="All Machines"
_arg_customfield="screenconnectURL"
_fieldValue=

# Help text function for when invalid input is encountered
print_help() {
  printf '\n\n%s\n\n' 'Usage: [--instanceId|-i <arg>] [--screenconnectDomain|-d <arg>] [--sessionGroup|-g <arg>] [--customField|-c <arg>] [--help|-h]'
  printf '%s\n' 'Preset Parameter: --instanceid "ReplaceWithYourInstanceID"'
  printf '\t%s\n' "Replace the text encased in quotes with your instance ID. You can see the instance ID in the ScreenConnect Admin Center (Administration > Advanced > Server Information). It's also usually present in the application name on any installed instance, e.g., connectwisecontrol-yourinstanceid."
  printf '\n%s\n' 'Preset Parameter: --screenconnectDomain "replace.me"'
  printf '\t%s' "Replace the text encased in quotes with the domain used for ConnectWise ScreenConnect, e.g., 'example.screenconnect.com'."
  printf '\n%s\n' 'Preset Parameter: --sessionGroup "Replace Me"'
  printf '\t%s' "Replace the text encased in quotes with the name of a Session Group in ConnectWise ScreenConnect that contains All Machines (defaults to All Machines). ex. 'All Machines'"
  printf '\n%s\n' 'Preset Parameter: --customField "replaceMe"'
  printf '\t%s' "Replace the text encased in quotes with the name of a custom field you'd like to store this information to (defaults to launchUrl). ex. 'screenconnectUrl'"
  printf '\n%s\n' 'Preset Parameter: --help'
  printf '\t%s\n' "Displays this help menu."
}

# Determines whether or not help text is necessary and routes the output to stderr
die() {
  local _ret="${2:-1}"
  echo "$1" >&2
  test "${_PRINT_HELP:-no}" = yes && print_help >&2
  exit "${_ret}"
}

# Grabbing the parameters and parsing through them.
parse_commandline() {
  while test $# -gt 0; do
    _key="$1"
    case "$_key" in
    --screenconnectdomain | --screenconnectDomain | --domain | -d)
      test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
      _arg_screenconnectdomain=$2
      shift
      ;;
    --screenconnectdomain=*)
      _arg_screenconnectdomain="${_key##--screenconnectdomain=}"
      ;;
    --instanceId | --instanceid | -i)
      test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
      _arg_instanceId=$2
      shift
      ;;
    --instanceid=*)
      _arg_instanceId="${_key##--instanceid=}"
      ;;
    --sessionGroup | --sessiongroup | -g)
      test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
      _arg_sessiongroup=$2
      shift
      ;;
    --sessiongroup=*)
      _arg_sessiongroup="${_key##--sessiongroup=}"
      ;;
    --customField | --customfield | -c)
      test $# -lt 2 && die "Missing value for the optional argument '$_key'." 1
      _arg_customfield=$2
      shift
      ;;
    --customfield=*)
      _arg_customfield="${_key##--customfield=}"
      ;;
    --help | -h)
      _PRINT_HELP=yes die 0
      ;;
    *)
      _PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
      ;;
    esac
    shift
  done
}

# Function to set a custom field
setCustomField() {
  echo "$_fieldValue" | /Applications/NinjaRMMAgent/programdata/ninjarmm-cli set --stdin "$_arg_customfield"
}

export PATH=$PATH:/usr/sbin:/usr/bin

parse_commandline "$@"

# If script form is used override commandline agruments
if [[ -n $screenconnectDomain ]]; then
  _arg_screenconnectdomain="$screenconnectDomain"
fi

if [[ -n $sessionGroup ]]; then
  _arg_sessiongroup="$sessionGroup"
fi

if [[ -n $instanceId ]]; then
  _arg_instanceId="$instanceId"
fi

if [[ -n $customFieldName ]]; then
  _arg_customfield="$customFieldName"
fi

# If we weren't given an instance id we should warn that this is not advised.
if [[ -z $_arg_instanceId ]]; then
  echo "WARNING: Without the instance id we will be unable to tell which ScreenConnect instance is yours (if multiple are installed). This may result in the wrong URL being displayed."
  echo "To get the instance id you can find it in ScreenConnect itself (Admin > Advanced > Server Information > Instance Identifier Fingerprint). It's also in the application name on every installed copy 'connectwisecontrol-yourinstanceidhere'"
fi

# --screenconnectDomain and --sessionGroup are required. We should also escape the session group given.
if [[ -z $_arg_screenconnectdomain || -z $_arg_sessiongroup ]]; then
  _PRINT_HELP=yes die "FATAL ERROR: Unable to build the URL without the Domain and Session Group!" 1
else
  _arg_sessiongroup=$(echo "$_arg_sessiongroup" | perl -MURI::Escape -ne 'chomp;print uri_escape($_),"\n"')
fi

# Double check ScreenConnect is installed
installedPkg=$(pkgutil --pkgs | grep "connectwisecontrol-$_arg_instanceId")
if [[ -z $installedPkg ]]; then
  _PRINT_HELP=no die "FATAL ERROR: It appears ConnectWise ScreenConnect is not installed!" 1
fi

# Lets start building some urls
for pkg in $installedPkg; do
  file="/Applications/$pkg.app/Contents/Resources/ClientLaunchParameters.txt.lproj/locversion.plist"
  id=$(grep -Eo 's=.{8}-.{4}-.{4}-.{4}-.{12}' "$file" | sed 's/s=//g' | sed 's/&e=Access//g')
  instanceid=${pkg//"connectwisecontrol-"/}
  # We shouldn't have multiple results but if we do we should warn the technician
  if [[ -n "$launchurls" ]]; then
    echo "WARNING: Multiple installed instances detected and no instance id was given. One of these urls will be incorrect."
    launchurls=$(
      printf '%s\n' "$launchurls"
      printf '%s\t' "$instanceid"
      printf '%s\n' "https://$_arg_screenconnectdomain/Host#Access/$_arg_sessiongroup//$id/Join"
    )
  else
    launchurls=$(
      printf '%s\t\t' "InstanceID"
      printf '%s\n' "LaunchURL"
      printf '%s\t' "$instanceid"
      printf '%s\t' "https://$_arg_screenconnectdomain/Host#Access/$_arg_sessiongroup//$id/Join"
    )
  fi
done

# Check that we were successful
if [[ -n $launchurls ]]; then
  echo "Launch URL(s) Created"
else
  _PRINT_HELP=no die "FATAL ERROR: Failed to create Launch URL(s)!" 1
fi

# Change how we output the results based on how many urls we received.
if [[ $(echo "$launchurls" | wc -l) -gt 2 ]]; then
  _fieldValue="$launchurls"
  echo "$_fieldValue"
else
  _fieldValue=$(echo "$launchurls" | tail -n 1 | awk '{print $2}')
  echo "$_fieldValue"
fi

echo "Setting Custom Field..."
setCustomField
exit 0

 

Zugriff auf über 300 Skripte im NinjaOne Dojo

Zugang erhalten

Detaillierte Aufschlüsselung

Das Skript arbeitet in mehreren Stufen:

  • Initialisierung der Parameter: Zunächst werden Standardwerte für verschiedene Parameter wie Instanz-ID, Domäne, Sitzungsgruppe und Name des benutzerdefinierten Feldes festgelegt.
  • Hilfe-Funktion: Es ist eine Hilfetextfunktion integriert, die den Benutzer durch die Verwendung des Skripts führt, insbesondere im Falle ungültiger Eingaben.
  • Befehlszeilenanalyse: Er analysiert die Befehlszeilenargumente, um Einstellungen wie Domain und Instanz-ID anzupassen.
  • Benutzerdefinierte Feldeinstellung: Das Skript enthält eine Funktion zum Festlegen eines benutzerdefinierten Feldes im NinjaOne-RMM-Tool, in dem die ConnectWise Control URL gespeichert wird.
  • Erstellen von Start-URLs: Die Kernfunktionalität besteht darin, die Start-URLs zu erstellen, indem die erforderlichen IDs aus installierten Paketen extrahiert und die URL basierend auf bereitgestellten Parametern konstruiert wird.
  • Ausgabeverarbeitung: Je nach Anzahl der generierten URLs speichert es diese entweder in einem benutzerdefinierten Feld oder gibt sie direkt aus.

Potenzielle Anwendungsfälle

Stell dir einen IT-Experten vor, der eine Flotte von Geräten in verschiedenen Kundenorganisationen verwaltet. Sie müssen rechtzeitig Remote-Support bereitstellen, aber die Verwaltung einzelner Sitzungs-URLs ist umständlich. Mit diesem Skript können sie diese URLs schnell generieren und speichern und so einen schnellen und organisierten Fernzugriff gewährleisten.

Vergleiche

Traditionell konfigurieren IT-Expert:innen jede Sitzungs-URL manuell oder verwenden weniger ausgefeilte Skripte. Dieses Skript automatisiert jedoch den gesamten Prozess und ist speziell auf ConnectWise Control unter macOS zugeschnitten, was eine effizientere und fehlerfreie Lösung darstellt.

FAQs:

  • Wie finde ich die Instanz-ID?
    • Überprüfen Sie das ScreenConnect Admin Center oder den Anwendungsnamen auf installierten Instanzen.
  • Ist es mit allen macOS-Versionen kompatibel?
    • Es ist für allgemeine Kompatibilität ausgelegt, aber testen Sie es immer zuerst mit Ihrer spezifischen Version.
  • Kann ich das Speicherfeld für URLs anpassen?
    • Ja, das Skript ermöglicht die Einstellung eines benutzerdefinierten Feldes Ihrer Wahl.

Auswirkungen

Auch wenn das Skript die Verwaltung von Remote-Sitzungen vereinfacht, müssen die Sicherheitsaspekte berücksichtigt werden. Für die IT-Sicherheit ist es von entscheidender Bedeutung, dass URLs sicher gespeichert werden und der Zugriff kontrolliert wird.

Empfehlungen

  • Aktualisieren Sie das Skript regelmäßig, um es an neue Updates in ConnectWise Control anzupassen.
  • Achten Sie auf die Sicherheitsberechtigungen für die gespeicherten URLs.
  • Testen Sie das Skript in einer kontrollierten Umgebung, bevor Sie es in großem Umfang einsetzen.

Abschließende Überlegungen

Die Einbindung solcher Skripte in ein umfassenderes Toolkit wie NinjaOne kann die Fähigkeit eines IT-Experten zur effizienten und sicheren Verwaltung des Remote-Supports erheblich verbessern. NinjaOnes umfassender Ansatz zur Fernüberwachung und -verwaltung ergänzt diese Skripte und bietet eine robuste Plattform für das IT-Management.

Nächste Schritte

Der Aufbau eines effizienten und effektiven IT-Teams erfordert eine zentralisierte Lösung, die als vereintes Tool für die Bereitstellung von Dienstleistungen fungiert. NinjaOne ermöglicht es IT-Teams, all ihre Geräte zu überwachen, verwalten, sichern und zu unterstützen, unabhängig von ihrem Ort und komplexer Infrastruktur vor Ort.

Erfahren Sie mehr über NinjaOne Endpoint Management schauen Sie sich eine Live-Tour an oder starten Sie Ihre kostenlose Testversion der NinjaOne Plattform.

Kategorien:

Das könnte Sie auch interessieren

Demo ansehen×
×

Sehen Sie NinjaOne in Aktion!

Mit dem Absenden dieses Formulars akzeptiere ich die Datenschutzerklärung von NinjaOne.

NinjaOne Terms & Conditions

By clicking the “I Accept” button below, you indicate your acceptance of the following legal terms as well as our Terms of Use:

  • Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms.
  • Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party.
  • Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library belonging to or under the control of any other software provider.
  • Warranty Disclaimer: The script is provided “as is” and “as available”, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations.
  • Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks.
  • Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script.
  • EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).