{"id":208169,"date":"2024-01-22T11:29:09","date_gmt":"2024-01-22T11:29:09","guid":{"rendered":"https:\/\/www.ninjaone.com\/script-hub\/automatizzare-la-distribuzione-di-connectwise-screenconnect-con-powershell\/"},"modified":"2024-03-04T18:12:06","modified_gmt":"2024-03-04T18:12:06","slug":"automatizzare-la-distribuzione-di-connectwise-screenconnect-con-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/it\/script-hub\/automatizzare-la-distribuzione-di-connectwise-screenconnect-con-powershell\/","title":{"rendered":"Automatizzare la distribuzione di ConnectWise ScreenConnect con PowerShell"},"content":{"rendered":"<h2>Punti chiave<\/h2>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"1\" data-aria-level=\"1\"><strong>Efficienza automatizzata<\/strong>: Lo script PowerShell per automatizzare la distribuzione di ConnectWise ScreenConnect semplifica il processo installazione, migliorando l&#8217;efficienza operativa.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"2\" data-aria-level=\"1\"><strong>Installazione personalizzabile<\/strong>: Lo script per automatizzare la distribuzione di ConnectWise ScreenConnect supporta la costruzione di URL dinamici per installazioni personalizzate basate su parametri come il nome dell&#8217;organizzazione, la posizione e il tipo di dispositivo.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"1\"><strong>Ampia applicabilit\u00e0<\/strong>: Lo script per automatizzare la distribuzione di ConnectWise ScreenConnect \u00e8 ideale per gli MSP e i professionisti IT che gestiscono pi\u00f9 dispositivi in diverse sedi.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"4\" data-aria-level=\"1\"><strong>Funzionalit\u00e0 avanzate<\/strong>: Lo script per automatizzare la distribuzione di ConnectWise ScreenConnect offre funzionalit\u00e0 come il controllo dello stato di installazione e la registrazione degli errori, superando in efficacia i tradizionali metodi manuali o di script batch.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"5\" data-aria-level=\"1\"><strong>Compatibilit\u00e0 e limitazioni<\/strong>: Lo script per automatizzare la distribuzione di ConnectWise ScreenConnect funziona al meglio con Windows 8 e Server 2012 e versioni successive, con possibili limitazioni sulle versioni precedenti.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"6\" data-aria-level=\"1\"><strong>Considerazioni sulla sicurezza<\/strong>: Gli utenti devono controllare e comprendere lo script per automatizzare la distribuzione di ConnectWise ScreenConnect per garantire la sicurezza, soprattutto negli ambienti MSP.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"7\" data-aria-level=\"1\"><strong>Integrazione con NinjaOne<\/strong>: Questo script per automatizzare la distribuzione di ConnectWise ScreenConnect si allinea bene con l&#8217;approccio unificato alla gestione IT di NinjaOne, offrendo una soluzione coesa per i professionisti IT.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"8\" data-aria-level=\"1\"><strong>Adattamento continuo<\/strong>: Potrebbero essere necessari aggiornamenti e modifiche regolari dello script per automatizzare la distribuzione di ConnectWise ScreenConnect per allinearsi alle ultime versioni di ConnectWise ScreenConnect.<\/li>\n<\/ul>\n<p>Nel panorama dinamico dell&#8217;IT, l&#8217;efficienza e l&#8217;automazione sono fondamentali per mantenere un vantaggio competitivo. Lo scripting \u00e8 emerso come uno strumento cruciale, che consente ai professionisti IT di semplificare processi complessi. Lo script PowerShell per automatizzare la distribuzione di ConnectWise ScreenConnect ne \u00e8 un esempio, dato che permette di velocizzare l&#8217;implementazione di una soluzione sofisticata per la gestione e l&#8217;assistenza in remoto.<\/p>\n<h2>Background<\/h2>\n<p><a href=\"https:\/\/www.ninjaone.com\/it\/integrazioni\/connectwise-screenconnect\/\">ConnectWise ScreenConnect<\/a>, un popolare strumento di supporto e gestione remota, \u00e8 ampiamente utilizzato dai professionisti IT e dai <a href=\"https:\/\/www.ninjaone.com\/what-is-an-msp\/\">Managed Service Provider (MSP)<\/a>. La sua capacit\u00e0 di facilitare l&#8217;accesso remoto ai dispositivi \u00e8 essenziale negli ambienti di lavoro odierni, sempre pi\u00f9 decentralizzati. Questo script PowerShell per automatizzare la distribuzione di ConnectWise ScreenConnect\u00a0 risponde a una sfida comune dei team IT: riuscire a installare e distribuire il software in modo efficiente, scalabile e automatizzato.<\/p>\n<h2>Lo script per per automatizzare la distribuzione di ConnectWise ScreenConnect:<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">&lt;#\r\n.SYNOPSIS\r\nDownload and Install ConnectWise ScreenConnect from the domain used for ScreenConnect. Supports automatic customization of the device type, location and other ScreenConnect Fields.\r\n\r\n.DESCRIPTION\r\nDownload and Install ConnectWise ScreenConnect from the domain used for ScreenConnect. Supports automatic customization of the device type, location and other ScreenConnect Fields.\r\n\r\n.EXAMPLE\r\n-ScreenConnectDomain \"testscreen.screenconnect.com\" -UseOrgName -UseLocation -UseDeviceType\r\n\r\nInstaller Log File location will be: C:WindowsTEMPtmp9A50.tmp\r\nScreenConnect Client (abcd123456) is not installed and will be installed.\r\nAttempting to build from domain...\r\nURL Built: https:\/\/testscreen.screenconnect.com\/Bin\/Test Company.ClientSetup.msi?e=Access&amp;y=Guest&amp;c=Kyle - OOB&amp;c=Main Office&amp;c=&amp;c=Workstation&amp;c=&amp;c=&amp;c=&amp;c=\r\nURL Given, Downloading the file...\r\nDownload Attempt 1\r\nExit Code: 0\r\nSuccess\r\n\r\nPRESET PARAMETER: -ScreenConnectDomain \"your.domain.com\"\r\nYour ScreenConnect instance's domain name. The script will use this to construct a download URL from scratch with the options you selected.\r\n\r\nPRESET PARAMETER: -UseOrgName\r\nModifies your URL to use the organization name in the Company Name Field in ScreenConnect.\r\n\r\nPRESET PARAMETER: -UseLocation\r\nModifies your URL to use the Location Name in the Site Name Field in ScreenConnect.\r\n\r\nPRESET PARAMETER: -UseDeviceType\r\nModifies your URL to include the type of device in ScreenConnect. (Server, Workstation, Laptop etc.)\r\n\r\nPRESET PARAMETER: -Department \"Your Department Name Here\"\r\nModifies your URL to include your desired department name in ScreenConnect.\r\n\r\nPRESET PARAMETER: -SkipSleep\r\nBy default the script sleeps for a random interval between 3 and 60 seconds prior to downloading the file. This parameter skips the sleep.\r\n\r\nPRESET PARAMETER: -Force\r\nIf ScreenConnect is already installed attempt to install it anyways.\r\n\r\n.NOTES\r\nMinimum OS Architecture Supported: Windows 8, Windows Server 2012\r\nCan work on lower versions of Windows, provided that the OS\/.NET is able to download the file. PowerShell 2.0 might face issues due to its lack of TLS support in .NET 2.0.\r\n\r\nAdapted from Chris White's script: https:\/\/ninjarmm.zendesk.com\/hc\/en-us\/community\/posts\/7549797399821-Connectwise-Control-Installer\r\n\r\nRelease Notes: Initial Release\r\nBy 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.\r\n    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. \r\n    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. \r\n    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. \r\n    Warranty Disclaimer: The script is provided \u201cas is\u201d and \u201cas available\u201d, 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. \r\n    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. \r\n    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. \r\n    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).\r\n#&gt;\r\n#&gt;\r\n\r\n[CmdletBinding()]\r\nparam (\r\n    # Change the defaults if you don't wish to use parameters when running this script\r\n    [Parameter()]\r\n    [String]$MSI = \"ClientSetup.msi\",\r\n    [Parameter()]\r\n    [String]$DestinationFolder = \"$env:TEMP\",\r\n    [Parameter()]\r\n    [String]$ScreenConnectDomain,\r\n    [Parameter()]\r\n    [String]$InstanceID,\r\n    [Parameter()]\r\n    [Switch]$UseOrgName = [System.Convert]::ToBoolean($env:useNinjaOrganizationName),\r\n    [Parameter()]\r\n    [Switch]$UseLocation = [System.Convert]::ToBoolean($env:useNinjaLocationName),\r\n    [Parameter()]\r\n    [Switch]$UseDeviceType = [System.Convert]::ToBoolean($env:addDeviceType),\r\n    [Parameter()]\r\n    [String]$Department,\r\n    [Parameter()]\r\n    [Switch]$SkipSleep = [System.Convert]::ToBoolean($env:skipSleep),\r\n    [Parameter()]\r\n    [Switch]$Force = [System.Convert]::ToBoolean($env:force)\r\n)\r\nbegin {\r\n    # If Script Form is used replace the parameters with what was filled in.\r\n    if ($env:screenconnectDomainName -and $env:screenconnectDomainName -notlike \"null\") { $ScreenConnectDomain = $env:screenconnectDomainName }\r\n    if ($env:department -and $env:department -notlike \"null\") { $Department = $env:department }\r\n\r\n    # Some means of installing the file is required.\r\n    if (-not ($ScreenConnectDomain)) { Write-Error \"A domain is required to install control.\"; exit 1 }\r\n\r\n    if ($ScreenConnectDomain -match \"^http(s)?:\/\/\") {\r\n        Write-Warning \"http(s):\/\/ is not part of the domain name. Removing http(s):\/\/ from your input....\"\r\n        $ScreenConnectDomain = $ScreenConnectDomain -replace \"^http(s)?:\/\/\"\r\n        Write-Warning \"New Domain Name $ScreenConnectDomain.\"\r\n    }\r\n\r\n    if ($ScreenConnectDomain -match \"^C:\/\") {\r\n        Write-Error \"It looks like you entered in a file path by mistake. We actually need the domain name used to reach your ScreenConnect website for example 'companyname.screenconnect.com'\"\r\n        exit 1\r\n    }\r\n    \r\n    #### Helper functions used throughout the script ####\r\n\r\n    function Test-IsElevated {\r\n        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()\r\n        $p = New-Object System.Security.Principal.WindowsPrincipal($id)\r\n        $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)\r\n    }\r\n\r\n    # Extract the ProductName from the msi\r\n    function Get-ControlPanelName {\r\n        [CmdletBinding()]\r\n        param (\r\n            [Parameter()]\r\n            [string]$msiPath\r\n        )\r\n        $windowsInstaller = New-Object -ComObject WindowsInstaller.Installer\r\n        $database = $windowsInstaller.GetType().InvokeMember(\"OpenDatabase\", \"InvokeMethod\", $null, $windowsInstaller, @($msiPath, 0))\r\n        $query = \"SELECT `Value` FROM `Property` WHERE `Property` = 'ProductName'\"\r\n\r\n        $view = $database.GetType().InvokeMember(\"OpenView\", \"InvokeMethod\", $null, $database, $query)\r\n        $view.GetType().InvokeMember(\"Execute\", \"InvokeMethod\", $null, $view, $null)\r\n\r\n        $record = $view.GetType().InvokeMember(\"Fetch\", \"InvokeMethod\", $null, $view, $null)\r\n        if ($record) {\r\n            return $record.GetType().InvokeMember(\"StringData\", \"GetProperty\", $null, $record, 1)\r\n        }\r\n\r\n        [System.Runtime.InteropServices.Marshal]::ReleaseComObject($windowsInstaller) | Out-Null\r\n        [System.GC]::Collect()\r\n    }\r\n\r\n    # Is it a Server or Desktop OS?\r\n    function Get-ProductType {\r\n        if ($PSVersionTable.PSVersion.Major -ge 5) {\r\n            $OS = Get-CimInstance -ClassName Win32_OperatingSystem | Select-Object ProductType -ExpandProperty ProductType\r\n        }\r\n        else {\r\n            $OS = Get-WmiObject -Class Win32_OperatingSystem | Select-Object ProductType -ExpandProperty ProductType\r\n        }\r\n        \r\n        return $OS\r\n    }\r\n\r\n    # Check the Chassis type to find out if it's a laptop or not.\r\n    function Test-IsLaptop {\r\n        if ($PSVersionTable.PSVersion.Major -ge 5) {\r\n            $Chassis = Get-CimInstance -ClassName win32_systemenclosure | Select-Object ChassisTypes -ExpandProperty ChassisTypes\r\n        }\r\n        else {\r\n            $Chassis = Get-WmiObject -Class win32_systemenclosure | Select-Object ChassisTypes -ExpandProperty ChassisTypes\r\n        }\r\n\r\n        switch ($Chassis) {\r\n            9 { return $True }\r\n            10 { return $True }\r\n            14 { return $True }\r\n            default { return $False }\r\n        }\r\n    }\r\n\r\n    # Check's the two uninstall registry keys to see if the app is installed. Needs the name as it would appear in Control Panel.\r\n    function Find-UninstallKey {\r\n        [CmdletBinding()]\r\n        param (\r\n            [Parameter(ValueFromPipeline = $True)]\r\n            [String]$DisplayName,\r\n            [Parameter()]\r\n            [Switch]$UninstallString\r\n        )\r\n        process {\r\n            $UninstallList = New-Object System.Collections.Generic.List[Object]\r\n\r\n            $Result = Get-ChildItem HKLM:SoftwareWow6432NodeMicrosoftWindowsCurrentVersionUninstall* | Get-ItemProperty | Where-Object { $_.DisplayName -like \"*$DisplayName*\" }\r\n            if ($Result) { $UninstallList.Add($Result) }\r\n\r\n            $Result = Get-ChildItem HKLM:SoftwareMicrosoftWindowsCurrentVersionUninstall* | Get-ItemProperty | Where-Object { $_.DisplayName -like \"*$DisplayName*\" }\r\n            if ($Result) { $UninstallList.Add($Result) }\r\n\r\n            # Programs don't always have an uninstall string listed here so to account for that I made this optional.\r\n            if ($UninstallString) {\r\n                $UninstallList | Select-Object -ExpandProperty UninstallString -ErrorAction SilentlyContinue\r\n            }\r\n            else {\r\n                $UninstallList\r\n            }\r\n        }\r\n    }\r\n\r\n    # Handy download function\r\n    function Invoke-Download {\r\n        param(\r\n            [Parameter()]\r\n            [String]$URL,\r\n            [Parameter()]\r\n            [String]$Path,\r\n            [Parameter()]\r\n            [Switch]$SkipSleep\r\n        )\r\n        Write-Host \"URL given; downloading the file...\"\r\n\r\n        $SupportedTLSversions = [enum]::GetValues('Net.SecurityProtocolType')\r\n        if ( ($SupportedTLSversions -contains 'Tls13') -and ($SupportedTLSversions -contains 'Tls12') ) {\r\n            [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol::Tls13 -bor [System.Net.SecurityProtocolType]::Tls12\r\n        }\r\n        elseif ( $SupportedTLSversions -contains 'Tls12' ) {\r\n            [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12\r\n        }\r\n        else {\r\n            # Not everything requires TLS 1.2, but we'll try anyways.\r\n            Write-Warning \"TLS 1.2 and or TLS 1.3 isn't supported on this system. This download may fail!\"\r\n            if ($PSVersionTable.PSVersion.Major -lt 3) {\r\n                Write-Warning \"PowerShell 2 \/ .NET 2.0 doesn't support TLS 1.2.\"\r\n            }\r\n        }\r\n\r\n        $i = 1\r\n        While ($i -lt 4) {\r\n            if (-not ($SkipSleep)) {\r\n                $SleepTime = Get-Random -Minimum 3 -Maximum 30\r\n                Start-Sleep -Seconds $SleepTime\r\n            }\r\n\r\n            Write-Host \"Download Attempt $i\"\r\n\r\n            try {\r\n                $WebClient = New-Object System.Net.WebClient\r\n                $WebClient.DownloadFile($URL, $Path)\r\n                $File = Test-Path -Path $Path -ErrorAction SilentlyContinue\r\n            }\r\n            catch {\r\n                Write-Warning \"An error has occurred while downloading!\"\r\n                Write-Warning $_.Exception.Message\r\n            }\r\n\r\n            if ($File) {\r\n                $i = 4\r\n            }\r\n            else {\r\n                $i++\r\n            }\r\n        }\r\n\r\n        if (-not (Test-Path $Path)) {\r\n            Write-Error \"Failed to download file!\"\r\n            Exit 1\r\n        }\r\n    }\r\n\r\n    # This will build our screenconnect download url if only given a domain name or if modification is needed to include the device type, location, org name etc.\r\n    function Build-URL {\r\n        param(\r\n            [Parameter()]\r\n            [String]$BaseURL,\r\n            [Parameter()]\r\n            [String]$Domain,\r\n            [Parameter()]\r\n            [String]$MSI,\r\n            [Parameter()]\r\n            [String]$Department,\r\n            [Parameter()]\r\n            [Switch]$UseOrgName,\r\n            [Parameter()]\r\n            [Switch]$UseLocation,\r\n            [Parameter()]\r\n            [Switch]$UseDeviceType\r\n        )\r\n\r\n        Write-Host \"Attempting to build from domain...\"\r\n        $URL = \"https:\/\/$Domain\/Bin\/$env:NINJA_COMPANY_NAME.ClientSetup.msi`?e=Access&amp;y=Guest\"\r\n\r\n        if ($UseOrgName) { $URL = $URL + \"&amp;c=$env:NINJA_ORGANIZATION_NAME\" }else { $URL = $URL + \"&amp;c=\" }\r\n        if ($UseLocation) { $URL = $URL + \"&amp;c=$env:NINJA_LOCATION_NAME\" }else { $URL = $URL + \"&amp;c=\" }\r\n        if ($Department) { $URL = $URL + \"&amp;c=$Department\" }else { $URL = $URL + \"&amp;c=\" }\r\n        if ($UseDeviceType) {\r\n            switch (Get-ProductType) {\r\n                1 { if (Test-IsLaptop) { $URL = $URL + \"&amp;c=Laptop&amp;c=&amp;c=&amp;c=&amp;c=\" }else { $URL = $URL + \"&amp;c=Workstation&amp;c=&amp;c=&amp;c=&amp;c=\" } }\r\n                2 { $URL = $URL + \"&amp;c=Domain Controller&amp;c=&amp;c=&amp;c=&amp;c=\" }\r\n                3 { $URL = $URL + \"&amp;c=Server&amp;c=&amp;c=&amp;c=&amp;c=\" }\r\n            }\r\n        }\r\n        else {\r\n            $URL = $URL + \"&amp;c=&amp;c=&amp;c=&amp;c=&amp;c=\"\r\n        }\r\n\r\n        Write-Host \"URL Built: $URL\"\r\n\r\n        return $URL\r\n    }\r\n\r\n    if (-not (Test-IsElevated)) {\r\n        Write-Error -Message \"Access Denied. Please run with Administrator privileges.\"\r\n        exit 1\r\n    }\r\n\r\n    if (-not (Test-Path $DestinationFolder -ErrorAction SilentlyContinue)) {\r\n        Write-Host \"Destination Folder does not exist! Creating directory...\"\r\n        New-Item $DestinationFolder -ItemType Directory\r\n    }\r\n\r\n    #Set the log file as a temporary file, it will be created in the temp folder of the context the script runs in (c:windowstemp or c:usersusernameappdatatemp)\r\n    $InstallerLogFile = [IO.Path]::GetTempFileName()\r\n    Write-Host \"Installer Log File location will be: $InstallerLogFile\"\r\n}\r\nprocess {\r\n    # Arguments required to download the file\r\n    $DownloadArgs = @{ Path = \"$DestinationFolder$MSI\" }\r\n    if ($SkipSleep) { $DownloadArgs[\"SkipSleep\"] = $True }\r\n\r\n    # Build the arguments needed to create the url\r\n    $ArgumentList = @{ Domain = $ScreenConnectDomain }\r\n    if ($UseOrgName) { $ArgumentList[\"UseOrgName\"] = $True }\r\n    if ($UseLocation) { $ArgumentList[\"UseLocation\"] = $True }\r\n    if ($UseDeviceType) { $ArgumentList[\"UseDeviceType\"] = $True }\r\n    if ($Department) { $ArgumentList[\"Department\"] = $Department }\r\n\r\n    # Build the URL and get it ready for download\r\n    $DownloadArgs[\"URL\"] = Build-Url @ArgumentList\r\n\r\n    # Download the installer\r\n    Invoke-Download @DownloadArgs\r\n\r\n    # Grab the installer file\r\n    $InstallerFile = Join-Path -Path $DestinationFolder -ChildPath $MSI -Resolve\r\n\r\n    # Define the name of the software we are searching for and look for it in both the 64 bit and 32 bit registry nodes\r\n    $ProductName = \"$(Get-ControlPanelName -msiPath $InstallerFile)\".Trim()\r\n    if (-not $ProductName) { \r\n        Write-Error \"Failed to fetch the product name from the MSI at path '$InstallerFile'. Ensure the MSI path is correct and the MSI contains the necessary product information.\"\r\n        exit 1\r\n    }\r\n\r\n    # If already installed, exit.\r\n    $IsInstalled = Find-UninstallKey -DisplayName $ProductName\r\n    if ($IsInstalled -and -not ($Force)) {\r\n        Write-Host \"$ProductName is already installed; exiting...\"\r\n        exit 0\r\n    }\r\n\r\n    # ScreenConnect install arguments\r\n    $Arguments = \"\/c msiexec \/i \"\"$InstallerFile\"\" \/qn \/norestart \/l \"\"$InstallerLogFile\"\" REBOOT=REALLYSUPPRESS\"\r\n\r\n    # Install and let the user know the exit code\r\n    $Process = Start-Process -Wait cmd -ArgumentList $Arguments -PassThru\r\n    Write-Host \"Exit Code: $($Process.ExitCode)\";\r\n\r\n    # Interpret the exit code\r\n    switch ($Process.ExitCode) {\r\n        0 { Write-Host \"Success\" }\r\n        3010 { Write-Host \"Success. Reboot required to complete installation\" }\r\n        1641 { Write-Host \"Success. Installer has initiated a reboot\" }\r\n        default {\r\n            Write-Error \"Exit code does not indicate success\"\r\n            Get-Content $InstallerLogFile -ErrorAction SilentlyContinue | Select-Object -Last 50 | Write-Host\r\n        }\r\n    }\r\n\r\n    exit $Process.ExitCode\r\n    \r\n}\r\nend {\r\n    \r\n    \r\n    \r\n}<\/pre>\n<p>&nbsp;<\/p>\n\n<div class=\"in-context-cta\"><p>Accedi a oltre 700 script nel Dojo di NinjaOne<\/p>\n<p><a href=\"https:\/\/www.ninjaone.com\/it\/prova-gratuita\/\">Ottieni l&#8217;accesso<\/a><\/p>\n<\/div>\n<h2>Analisi dettagliata dello script per automatizzare la distribuzione di ConnectWise ScreenConnect<\/h2>\n<p>Lo script per automatizzare la distribuzione di ConnectWise ScreenConnect funziona in modo semplice:<\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"1\" data-aria-level=\"1\"><strong>Inizializzazione dei parametri<\/strong>: Si inizia definendo parametri come il nome del file MSI, la cartella di destinazione e il dominio ScreenConnect.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"2\" data-aria-level=\"1\"><strong>Controlli pre-esecuzione<\/strong>: Lo script per automatizzare la distribuzione di ConnectWise ScreenConnect in questa fase controlla i privilegi di amministratore e l&#8217;esistenza della cartella di destinazione.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"1\"><strong>Creazione di URL dinamici<\/strong>: Una caratteristica importante dello script per automatizzare la distribuzione di ConnectWise ScreenConnect \u00e8 la capacit\u00e0 di costruire dinamicamente un URL di download in base a parametri come il nome dell&#8217;organizzazione, la posizione e il tipo di dispositivo.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"1\"><strong>Processo di download<\/strong>: Lo script per automatizzare la distribuzione di ConnectWise ScreenConnect scarica quindi il programma di installazione di ScreenConnect dall&#8217;URL costruito.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"1\"><strong>Installazione<\/strong>: Dopo il download, lo script per automatizzare la distribuzione di ConnectWise ScreenConnect controlla se ScreenConnect \u00e8 gi\u00e0 installato. In caso contrario, o se viene utilizzato il parametro Force, si procede con l&#8217;installazione.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"3\" data-aria-level=\"1\"><strong>Registrazione<\/strong>: Durante l&#8217;intero processo, i log vengono conservati per la risoluzione dei problemi.<\/li>\n<\/ul>\n<h2>Casi d&#8217;uso potenziali dello script per automatizzare la distribuzione di ConnectWise ScreenConnect<\/h2>\n<p>Immagina un MSP responsabile della gestione dell&#8217;infrastruttura IT su pi\u00f9 sedi di clienti. L&#8217;installazione manuale di ScreenConnect su ogni dispositivo richiederebbe molto tempo. Con questo script, l&#8217;MSP pu\u00f2 automatizzare le installazioni, personalizzando le impostazioni come la posizione e il tipo di dispositivo per ogni cliente, risparmiando tempo e riducendo gli errori.<\/p>\n<h2>Confronti<\/h2>\n<p>Tradizionalmente, l&#8217;installazione del software pu\u00f2 comportare il download e l&#8217;impostazione manuale su ogni dispositivo o l&#8217;utilizzo di script batch di base senza possibilit\u00e0 di personalizzazione. Questo script PowerShell supera tali metodi offrendo funzionalit\u00e0 avanzate come la costruzione di URL dinamici e il controllo dello stato dell&#8217;installazione, che portano a distribuzioni pi\u00f9 efficienti e prive di errori.<\/p>\n<h2>Domande frequenti<\/h2>\n<p><strong>D: Lo script \u00e8 compatibile con tutte le versioni di Windows?\u00a0<\/strong><br \/>\nR: Supporta Windows 8 e Server 2012 in poi, anche se pu\u00f2 funzionare con le versioni precedenti con alcune limitazioni.<\/p>\n<p><strong>D: \u00c8 in grado di gestire installazioni su larga scala?\u00a0<\/strong><br \/>\nR: S\u00ec, \u00e8 progettato per la scalabilit\u00e0 e pu\u00f2 gestire installazioni su numerosi dispositivi.<\/p>\n<p><strong>D: \u00c8 sicuro utilizzare questo script?\u00a0<\/strong><br \/>\nR: Lo script \u00e8 sicuro, ma controlla e comprendi il funzionamento di qualsiasi script prima di eseguirlo nel tuo ambiente.<\/p>\n<h2>Implicazioni<\/h2>\n<p>Sebbene questo script semplifichi notevolmente il processo di installazione, gli utenti devono essere consapevoli delle implicazioni per la sicurezza. L&#8217;uso o la modifica non corretti possono portare a vulnerabilit\u00e0, soprattutto negli ambienti MSP dove una singola violazione pu\u00f2 avere un impatto su pi\u00f9 clienti.<\/p>\n<h2>Raccomandazioni<\/h2>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"4\" data-aria-level=\"1\"><strong>Verifica e testa<\/strong>: Controlla e testa sempre accuratamente lo script in un ambiente controllato.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"5\" data-aria-level=\"1\"><strong>Personalizza con cura<\/strong>: Modifica i parametri dello script in base alle tue esigenze specifiche.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&quot;335559685&quot;:720,&quot;335559991&quot;:360,&quot;469769226&quot;:&quot;Symbol&quot;,&quot;469769242&quot;:[8226],&quot;469777803&quot;:&quot;left&quot;,&quot;469777804&quot;:&quot;\uf0b7&quot;,&quot;469777815&quot;:&quot;hybridMultilevel&quot;}\" data-aria-posinset=\"6\" data-aria-level=\"1\"><strong>Resta sempre aggiornato<\/strong>: Tieniti informato sugli aggiornamenti di ConnectWise ScreenConnect e modifica lo script se necessario.<\/li>\n<\/ul>\n<h2>Considerazioni finali<\/h2>\n<p>NinjaOne, con il suo focus sulle <a href=\"https:\/\/www.ninjaone.com\/it\/\">operazioni IT unificate<\/a>, integra queste soluzioni di scripting. Offre una piattaforma in cui gli script possono essere integrati e gestiti in modo efficiente, migliorando ulteriormente le capacit\u00e0 di gestione IT dei professionisti. Questo script PowerShell, insieme a strumenti come NinjaOne, dimostra come l&#8217;automazione e gli strumenti intelligenti siano indispensabili nella gestione IT moderna.<\/p>\n","protected":false},"author":35,"featured_media":207447,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"_acf_changed":false,"_relevanssi_hide_post":"","_relevanssi_hide_content":"","_relevanssi_pin_for_all":"","_relevanssi_pin_keywords":"","_relevanssi_unpin_keywords":"","_relevanssi_related_keywords":"","_relevanssi_related_include_ids":"","_relevanssi_related_exclude_ids":"","_relevanssi_related_no_append":"","_relevanssi_related_not_related":"","_relevanssi_related_posts":"","_relevanssi_noindex_reason":"","_lmt_disableupdate":"no","_lmt_disable":""},"operating_system":[4212],"use_cases":[4269],"class_list":["post-208169","script_hub","type-script_hub","status-publish","has-post-thumbnail","hentry","script_hub_category-windows"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/script_hub\/208169","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/comments?post=208169"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/media\/207447"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/media?parent=208169"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/operating_system?post=208169"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/use_cases?post=208169"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}