{"id":256217,"date":"2024-05-17T15:23:43","date_gmt":"2024-05-17T15:23:43","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=256217"},"modified":"2024-05-17T15:23:43","modified_gmt":"2024-05-17T15:23:43","slug":"automatiser-le-deploiement-de-connectwise-screenconnect-avec-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/fr\/script-hub\/automatiser-le-deploiement-de-connectwise-screenconnect-avec-powershell\/","title":{"rendered":"Automatiser le d\u00e9ploiement de ConnectWise ScreenConnect avec PowerShell"},"content":{"rendered":"<h2>Principaux points \u00e0 retenir<\/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>Efficacit\u00e9 automatis\u00e9e<\/strong>: Le script PowerShell pour l&rsquo;installation de ConnectWise ScreenConnect automatise et simplifie le processus de d\u00e9ploiement, am\u00e9liorant ainsi l&rsquo;efficacit\u00e9 op\u00e9rationnelle.<\/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>Installation personnalisable<\/strong>: Il prend en charge la cr\u00e9ation d&rsquo;URL dynamiques pour des installations personnalis\u00e9es bas\u00e9es sur des param\u00e8tres tels que le nom de l&rsquo;organisation, le lieu et le type d&rsquo;appareil.<\/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>Grande applicabilit\u00e9<\/strong>: Id\u00e9al pour les MSP et les professionnels de l&rsquo;informatique qui g\u00e8rent plusieurs appareils sur diff\u00e9rents sites.<\/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>Fonctionnalit\u00e9s avanc\u00e9es<\/strong>: Il offre des fonctionnalit\u00e9s telles que la v\u00e9rification de l&rsquo;\u00e9tat de l&rsquo;installation et la journalisation des erreurs, surpassant ainsi les m\u00e9thodes manuelles traditionnelles ou les scripts 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\u00e9 et limites<\/strong>: Fonctionne au mieux avec Windows 8 et Server 2012, avec des limitations potentielles sur les versions plus anciennes.<\/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>Questions relatives \u00e0 la s\u00e9curit\u00e9<\/strong>\u00a0: Les utilisateurs doivent examiner et comprendre le script pour garantir la s\u00e9curit\u00e9, en particulier dans les environnements 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>Int\u00e9gration de NinjaOne<\/strong>: Ce script s&rsquo;aligne bien avec l&rsquo;approche de gestion informatique unifi\u00e9e de NinjaOne, offrant une solution fiable pour les professionnels de l&rsquo;informatique.<\/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>Adaptation continue<\/strong>: Des mises \u00e0 jour r\u00e9guli\u00e8res et des modifications du script peuvent \u00eatre n\u00e9cessaires pour s&rsquo;aligner sur les derni\u00e8res versions de ConnectWise ScreenConnect.<\/li>\n<\/ul>\n<p>Dans le monde dynamique de l&rsquo;informatique, l&rsquo;efficacit\u00e9 et l&rsquo;automatisation sont essentielles pour conserver un avantage concurrentiel. Les scripts sont devenus un outil essentiel, permettant aux professionnels de l&rsquo;informatique de rationaliser des processus complexes. Le script PowerShell pour l&rsquo;installation de ConnectWise ScreenConnect en est un exemple, offrant une solution sophistiqu\u00e9e pour la gestion et l&rsquo;assistance \u00e0 distance.<\/p>\n<h2>Contexte<\/h2>\n<p><a href=\"https:\/\/www.ninjaone.com\/integrations\/connectwise-screenconnect\/\">ConnectWise ScreenConnect<\/a>, un outil d&rsquo;assistance et de gestion \u00e0 distance tr\u00e8s populaire, est largement utilis\u00e9 par les professionnels de l&rsquo;informatique et les <a href=\"https:\/\/www.ninjaone.com\/what-is-an-msp\/\">fournisseurs de services g\u00e9r\u00e9s (MSP)<\/a>. Sa capacit\u00e9 \u00e0 faciliter l&rsquo;acc\u00e8s \u00e0 distance aux appareils est essentielle dans les environnements de travail, \u00e9tant de plus en plus d\u00e9centralis\u00e9s de nos jours. Ce script PowerShell simplifie le processus de d\u00e9ploiement de ScreenConnect, en r\u00e9pondant \u00e0 un challenge classique auquel sont confront\u00e9es les \u00e9quipes informatiques : l&rsquo;installation efficace, \u00e9volutive et automatis\u00e9e de logiciels.<\/p>\n<h2>Le script PowerShell\u00a0:<\/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>Acc\u00e9dez \u00e0 plus de 700 scripts dans le Dojo NinjaOne<\/p>\n<p><a href=\"https:\/\/www.ninjaone.com\/fr\/phase-de-test-gratuit\/\">Obtenir l&rsquo;acc\u00e8s<\/a><\/p>\n<\/div>\n<h2>Description d\u00e9taill\u00e9e<\/h2>\n<p>Le script fonctionne de mani\u00e8re simple :<\/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>Initialisation des param\u00e8tres<\/strong>\u00a0: Il commence par d\u00e9finir des param\u00e8tres tels que le nom du fichier MSI, le dossier de destination et le domaine 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>V\u00e9rifications avant ex\u00e9cution<\/strong>\u00a0: Il v\u00e9rifie les privil\u00e8ges d&rsquo;administrateur et l&rsquo;existence du dossier de destination.<\/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>Cr\u00e9ation d&rsquo;URL dynamiques<\/strong>: Une caract\u00e9ristique importante est sa capacit\u00e9 \u00e0 cr\u00e9er dynamiquement une URL de t\u00e9l\u00e9chargement bas\u00e9e sur des param\u00e8tres tels que le nom de l&rsquo;organisation, le lieu et le type d&rsquo;appareil.<\/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>Processus de t\u00e9l\u00e9chargement<\/strong>: Le script t\u00e9l\u00e9charge ensuite le programme d&rsquo;installation de ScreenConnect \u00e0 partir de l&rsquo;URL con\u00e7ue.<\/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>Installation<\/strong>: Apr\u00e8s le t\u00e9l\u00e9chargement, il v\u00e9rifie si ScreenConnect est d\u00e9j\u00e0 install\u00e9. Si ce n&rsquo;est pas le cas, ou si le param\u00e8tre \u00ab\u00a0Force\u00a0\u00bb est utilis\u00e9, l&rsquo;installation se poursuit.<\/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>Enregistrement<\/strong>: Tout au long du processus, les journaux sont tenus \u00e0 jour pour le d\u00e9pannage.<\/li>\n<\/ul>\n<h2>Cas d&rsquo;utilisation potentiels<\/h2>\n<p>Imaginez une entreprise MSP charg\u00e9e de g\u00e9rer l&rsquo;infrastructure informatique de plusieurs sites clients. L&rsquo;installation manuelle de ScreenConnect sur chaque appareil prendrait beaucoup de temps. Gr\u00e2ce \u00e0 ce script, le MSP peut automatiser les installations, en personnalisant les param\u00e8tres tels que l&#8217;emplacement et le type d&rsquo;appareil pour chaque client, ce qui permet de gagner du temps et de r\u00e9duire les erreurs.<\/p>\n<h2>Comparaisons<\/h2>\n<p>Traditionnellement, l&rsquo;installation d&rsquo;un logiciel implique un t\u00e9l\u00e9chargement manuel et une configuration sur chaque appareil ou l&rsquo;utilisation de scripts batch basiques, sans possibilit\u00e9 de personnalisation. Ce script PowerShell d\u00e9passe ces m\u00e9thodes en offrant des fonctionnalit\u00e9s avanc\u00e9es telles que la construction d&rsquo;URL dynamiques et la v\u00e9rification de l&rsquo;\u00e9tat de l&rsquo;installation, ce qui permet des d\u00e9ploiements plus efficaces et sans erreur.<\/p>\n<h2>FAQ<\/h2>\n<p><strong>Q\u00a0: Le script est-il compatible avec toutes les versions de Windows ?\u00a0<\/strong><br \/>\nR\u00a0: Il prend en charge Windows 8 et Server 2012, bien que les versions plus anciennes puissent fonctionner avec certaines limitations.<\/p>\n<p><strong>Q\u00a0: Peut-il g\u00e9rer des installations \u00e0 grande \u00e9chelle ?\u00a0<\/strong><br \/>\nR\u00a0: Oui, il est con\u00e7u pour \u00eatre \u00e9volutif et peut g\u00e9rer des installations sur de nombreux appareils.<\/p>\n<p><strong>Q\u00a0: L&rsquo;utilisation de ce script est-elle s\u00fbre ?\u00a0<\/strong><br \/>\nR\u00a0: Le script est s\u00e9curis\u00e9, mais il faut toujours examiner et comprendre un script avant de l&rsquo;ex\u00e9cuter dans votre environnement.<\/p>\n<h2>Implications<\/h2>\n<p>Bien que ce script simplifie consid\u00e9rablement le processus d&rsquo;installation, les utilisateurs doivent \u00eatre conscients des implications en mati\u00e8re de s\u00e9curit\u00e9. Une utilisation ou une modification incorrecte peut entra\u00eener des vuln\u00e9rabilit\u00e9s, en particulier dans les environnements de MSP o\u00f9 une seule violation peut avoir un impact sur plusieurs clients.<\/p>\n<h2>Recommandations<\/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>R\u00e9vision et test<\/strong>: Examinez et testez toujours soigneusement le script dans un environnement contr\u00f4l\u00e9.<\/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>Personnaliser avec soin<\/strong>: Modifiez les param\u00e8tres du script en fonction de vos besoins sp\u00e9cifiques.<\/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>Rester inform\u00e9<\/strong>: Tenez-vous au courant des mises \u00e0 jour de ConnectWise ScreenConnect et adaptez le script si n\u00e9cessaire.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>NinjaOne, qui met l&rsquo;accent sur les <a href=\"https:\/\/www.ninjaone.fr\/\" target=\"_blank\" rel=\"noopener\">op\u00e9rations informatiques unifi\u00e9es<\/a>, compl\u00e8te ce type de script. Il offre une plateforme o\u00f9 ces scripts peuvent \u00eatre int\u00e9gr\u00e9s et g\u00e9r\u00e9s efficacement, am\u00e9liorant ainsi les capacit\u00e9s de gestion informatique des professionnels. Ce script PowerShell, ainsi que des outils tels que NinjaOne, d\u00e9montrent que l&rsquo;automatisation et les outils intelligents sont indispensables \u00e0 la gestion moderne de l&rsquo;informatique.<\/p>\n","protected":false},"author":35,"featured_media":193964,"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":[4281],"class_list":["post-256217","script_hub","type-script_hub","status-publish","has-post-thumbnail","hentry","script_hub_category-windows"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/script_hub\/256217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/comments?post=256217"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/media\/193964"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/media?parent=256217"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/operating_system?post=256217"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/use_cases?post=256217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}