{"id":390736,"date":"2024-12-12T13:54:53","date_gmt":"2024-12-12T13:54:53","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=390736"},"modified":"2024-12-12T13:54:53","modified_gmt":"2024-12-12T13:54:53","slug":"verifier-les-versions-du-serveur-exchange-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/fr\/script-hub\/verifier-les-versions-du-serveur-exchange-powershell\/","title":{"rendered":"G\u00e9rer et v\u00e9rifier les versions du serveur Exchange avec PowerShell\u00a0"},"content":{"rendered":"<h2>Introduction<\/h2>\n<p>Pour les administrateurs informatiques et les <a href=\"https:\/\/www.ninjaone.com\/fr\/quest-ce-quun-msp\">fournisseurs de services g\u00e9r\u00e9s (MSP)<\/a>, il est essentiel de g\u00e9rer efficacement les environnements Exchange Server. Rester au fait des versions des serveurs garantit la compatibilit\u00e9, les performances et la s\u00e9curit\u00e9 au sein de l&rsquo;\u00e9cosyst\u00e8me de l&rsquo;entreprise. Ce script <a href=\"https:\/\/www.ninjaone.com\/it-hub\/endpoint-management\/what-is-powershell\/\">PowerShell<\/a> offre un moyen simplifi\u00e9 de v\u00e9rifier les versions du serveur Exchange, de valider leur conformit\u00e9 par rapport aux versions prises en charge et de prendre des mesures concr\u00e8tes pour maintenir un environnement \u00e0 jour.<\/p>\n<h2>Contexte<\/h2>\n<p>Microsoft Exchange reste la cl\u00e9 de vo\u00fbte des syst\u00e8mes de communication d&rsquo;entreprise. Cependant, les versions obsol\u00e8tes peuvent entra\u00eener des failles de s\u00e9curit\u00e9, des probl\u00e8mes de compatibilit\u00e9 et une d\u00e9gradation des performances. L&rsquo;identification de la version exacte d&rsquo;Exchange install\u00e9e dans les diff\u00e9rents environnements peut s&rsquo;av\u00e9rer fastidieuse, en particulier dans le cas de d\u00e9ploiements \u00e0 grande \u00e9chelle.<\/p>\n<p>Ce script automatise ce processus, permettant aux administrateurs de v\u00e9rifier les versions install\u00e9es d&rsquo;Exchange par rapport aux r\u00e9f\u00e9rences sp\u00e9cifi\u00e9es pour les versions 2010, 2013, 2016 et 2019. Il offre \u00e9galement une grande souplesse dans la gestion des champs personnalis\u00e9s, ce qui permet une int\u00e9gration transparente avec des outils de gestion tels que NinjaOne.<\/p>\n<h2>Le script\u00a0:<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">&lt;#\r\n.SYNOPSIS\r\n    Checks the version of Exchange installed and if it is outdated against the supplied versions.\r\n.DESCRIPTION\r\n    Checks the version of Exchange installed and if it is outdated against the supplied versions.\r\n    The version of Exchange that can be checked against are the following versions: 2010, 2013, 2016, and 2019.\r\n    \r\n    If the version is outdated, a warning is displayed.\r\n    The script will not alert if the version is up to date.\r\n\r\n    CheckboxCustomField can be used to skip the check, and the custom field must be a checkbox or a text field with a value of \"true\" or \"1\".\r\n\r\n    CustomFieldName can be used to save the version to a text custom field.\r\n\r\n    Exchange 2010 starts with 14.3, 2013 starts with 15.0, 2016 starts with 15.1, and 2019 starts with 15.2.\r\n\r\n    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.\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\r\n.EXAMPLE\r\n    (No Parameters)\r\n    ## EXAMPLE OUTPUT WITHOUT PARAMS ##\r\n    [Error] Exchange 2010, 2013, 2016, and 2019 versions are required to run this script.\r\n\r\nPARAMETER: -CustomFieldName \"ExchangeVersion\" -Exchange2010Version \"14.3.513.0\" -Exchange2013Version \"15.0.1497.48\" -Exchange2016Version \"15.1.0.0\" -Exchange2019Version \"15.2.0.0\"\r\n    Saves the Exchange version to a custom field named \"ExchangeVersion\"\r\n.EXAMPLE\r\n    -CustomFieldName \"ExchangeVersion\" -Exchange2010Version \"14.3.513.0\" -Exchange2013Version \"15.0.1497.48\" -Exchange2016Version \"15.1.0.0\" -Exchange2019Version \"15.2.0.0\"\r\n    ## EXAMPLE OUTPUT WITH CustomFieldName ##\r\n    [Info] Exchange version is up to date. Found version: 15.2.0.0\r\n    [Info] Attempting to set Custom Field 'ExchangeVersion'.\r\n    [Info] Successfully set Custom Field 'ExchangeVersion'!\r\n\r\nPARAMETER: -CheckboxCustomField \"SkipExchangeCheck\" -Exchange2010Version \"14.3.513.0\" -Exchange2013Version \"15.0.1497.48\" -Exchange2016Version \"15.1.0.0\" -Exchange2019Version \"15.2.0.0\"\r\n    Skips the Exchange version check if the checkbox custom field \"SkipExchangeCheck\" is checked or if a text custom field is set to \"true\" or \"1\".\r\n.EXAMPLE\r\n    -CheckboxCustomField \"SkipExchangeCheck\" -Exchange2010Version \"14.3.513.0\" -Exchange2013Version \"15.0.1497.48\" -Exchange2016Version \"15.1.0.0\" -Exchange2019Version \"15.2.0.0\"\r\n    ## EXAMPLE OUTPUT WITH CustomFieldName ##\r\n    [Info] Skipping Exchange version check.\r\n\r\n.NOTES\r\n    Minimum OS Architecture Supported: Windows Server 2008 R2\r\n    Release Notes: Initial Release\r\n#&gt;\r\n\r\n[CmdletBinding()]\r\nparam (\r\n    [String]$CustomFieldName,\r\n    [String]$Exchange2010Version,\r\n    [String]$Exchange2013Version,\r\n    [String]$Exchange2016Version,\r\n    [String]$Exchange2019Version,\r\n    [String]$CheckboxCustomField\r\n)\r\n\r\nbegin {\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    function Test-IsWorkstation {\r\n        $OS = Get-WmiObject -Class Win32_OperatingSystem\r\n        return $OS.ProductType -eq 1\r\n    }\r\n    function Set-NinjaProperty {\r\n        [CmdletBinding()]\r\n        Param(\r\n            [Parameter(Mandatory = $True)]\r\n            [String]$Name,\r\n            [Parameter()]\r\n            [String]$Type,\r\n            [Parameter(Mandatory = $True, ValueFromPipeline = $True)]\r\n            $Value,\r\n            [Parameter()]\r\n            [String]$DocumentName\r\n        )\r\n\r\n        $Characters = $Value | Measure-Object -Character | Select-Object -ExpandProperty Characters\r\n        if ($Characters -ge 10000) {\r\n            throw [System.ArgumentOutOfRangeException]::New(\"Character limit exceeded, value is greater than 10,000 characters.\")\r\n        }\r\n\r\n        # If we're requested to set the field value for a Ninja document we'll specify it here.\r\n        $DocumentationParams = @{}\r\n        if ($DocumentName) { $DocumentationParams[\"DocumentName\"] = $DocumentName }\r\n\r\n        # This is a list of valid fields that can be set. If no type is given, it will be assumed that the input doesn't need to be changed.\r\n        $ValidFields = \"Attachment\", \"Checkbox\", \"Date\", \"Date or Date Time\", \"Decimal\", \"Dropdown\", \"Email\", \"Integer\", \"IP Address\", \"MultiLine\", \"MultiSelect\", \"Phone\", \"Secure\", \"Text\", \"Time\", \"URL\", \"WYSIWYG\"\r\n        if ($Type -and $ValidFields -notcontains $Type) { Write-Warning \"$Type is an invalid type! Please check here for valid types. https:\/\/ninjarmm.zendesk.com\/hc\/en-us\/articles\/16973443979789-Command-Line-Interface-CLI-Supported-Fields-and-Functionality\" }\r\n\r\n        # The field below requires additional information to be set\r\n        $NeedsOptions = \"Dropdown\"\r\n        if ($DocumentName) {\r\n            if ($NeedsOptions -contains $Type) {\r\n                # We'll redirect the error output to the success stream to make it easier to error out if nothing was found or something else went wrong.\r\n                $NinjaPropertyOptions = Ninja-Property-Docs-Options -AttributeName $Name @DocumentationParams 2&gt;&amp;1\r\n            }\r\n        }\r\n        else {\r\n            if ($NeedsOptions -contains $Type) {\r\n                $NinjaPropertyOptions = Ninja-Property-Options -Name $Name 2&gt;&amp;1\r\n            }\r\n        }\r\n\r\n        # If an error is received it will have an exception property, the function will exit with that error information.\r\n        if ($NinjaPropertyOptions.Exception) { throw $NinjaPropertyOptions }\r\n\r\n        # The below types require values not typically given in order to be set. The below code will convert whatever we're given into a format ninjarmm-cli supports.\r\n        switch ($Type) {\r\n            \"Checkbox\" {\r\n                # While it's highly likely we were given a value like \"True\" or a boolean datatype it's better to be safe than sorry.\r\n                $NinjaValue = [System.Convert]::ToBoolean($Value)\r\n            }\r\n            \"Date or Date Time\" {\r\n                # Ninjarmm-cli expects the GUID of the option to be selected. Therefore, the given value will be matched with a GUID.\r\n                $Date = (Get-Date $Value).ToUniversalTime()\r\n                $TimeSpan = New-TimeSpan (Get-Date \"1970-01-01 00:00:00\") $Date\r\n                $NinjaValue = $TimeSpan.TotalSeconds\r\n            }\r\n            \"Dropdown\" {\r\n                # Ninjarmm-cli is expecting the guid of the option we're trying to select. So we'll match up the value we were given with a guid.\r\n                $Options = $NinjaPropertyOptions -replace '=', ',' | ConvertFrom-Csv -Header \"GUID\", \"Name\"\r\n                $Selection = $Options | Where-Object { $_.Name -eq $Value } | Select-Object -ExpandProperty GUID\r\n\r\n                if (-not $Selection) {\r\n                    throw [System.ArgumentOutOfRangeException]::New(\"Value is not present in dropdown\")\r\n                }\r\n\r\n                $NinjaValue = $Selection\r\n            }\r\n            default {\r\n                # All the other types shouldn't require additional work on the input.\r\n                $NinjaValue = $Value\r\n            }\r\n        }\r\n\r\n        # We'll need to set the field differently depending on if its a field in a Ninja Document or not.\r\n        if ($DocumentName) {\r\n            $CustomField = Ninja-Property-Docs-Set -AttributeName $Name -AttributeValue $NinjaValue @DocumentationParams 2&gt;&amp;1\r\n        }\r\n        else {\r\n            $CustomField = Ninja-Property-Set -Name $Name -Value $NinjaValue 2&gt;&amp;1\r\n        }\r\n\r\n        if ($CustomField.Exception) {\r\n            throw $CustomField\r\n        }\r\n    }\r\n    function Get-NinjaProperty {\r\n        [CmdletBinding()]\r\n        Param(\r\n            [Parameter(Mandatory = $True, ValueFromPipeline = $True)]\r\n            [String]$Name,\r\n            [Parameter()]\r\n            [String]$Type,\r\n            [Parameter()]\r\n            [String]$DocumentName\r\n        )\r\n\r\n        # If we're requested to get the field value from a Ninja document we'll specify it here.\r\n        $DocumentationParams = @{}\r\n        if ($DocumentName) { $DocumentationParams[\"DocumentName\"] = $DocumentName }\r\n\r\n        # These two types require more information to parse.\r\n        $NeedsOptions = \"DropDown\", \"MultiSelect\"\r\n\r\n        # Grabbing document values requires a slightly different command.\r\n        if ($DocumentName) {\r\n            # Secure fields are only readable when they're a device custom field\r\n            if ($Type -Like \"Secure\") { throw [System.ArgumentOutOfRangeException]::New(\"$Type is an invalid type! Please check here for valid types. https:\/\/ninjarmm.zendesk.com\/hc\/en-us\/articles\/16973443979789-Command-Line-Interface-CLI-Supported-Fields-and-Functionality\") }\r\n\r\n            # We'll redirect the error output to the success stream to make it easier to error out if nothing was found or something else went wrong.\r\n            Write-Host \"Retrieving value from Ninja Document...\"\r\n            $NinjaPropertyValue = Ninja-Property-Docs-Get -AttributeName $Name @DocumentationParams 2&gt;&amp;1\r\n\r\n            # Certain fields require more information to parse.\r\n            if ($NeedsOptions -contains $Type) {\r\n                $NinjaPropertyOptions = Ninja-Property-Docs-Options -AttributeName $Name @DocumentationParams 2&gt;&amp;1\r\n            }\r\n        }\r\n        else {\r\n            # We'll redirect error output to the success stream to make it easier to error out if nothing was found or something else went wrong.\r\n            $NinjaPropertyValue = Ninja-Property-Get -Name $Name 2&gt;&amp;1\r\n\r\n            # Certain fields require more information to parse.\r\n            if ($NeedsOptions -contains $Type) {\r\n                $NinjaPropertyOptions = Ninja-Property-Options -Name $Name 2&gt;&amp;1\r\n            }\r\n        }\r\n\r\n        # If we received some sort of error it should have an exception property and we'll exit the function with that error information.\r\n        if ($NinjaPropertyValue.Exception) { throw $NinjaPropertyValue }\r\n        if ($NinjaPropertyOptions.Exception) { throw $NinjaPropertyOptions }\r\n\r\n        if (-not $NinjaPropertyValue) {\r\n            throw [System.NullReferenceException]::New(\"The Custom Field '$Name' is empty!\")\r\n        }\r\n\r\n        # This switch will compare the type given with the quoted string. If it matches, it'll parse it further; otherwise, the default option will be selected.\r\n        switch ($Type) {\r\n            \"Attachment\" {\r\n                # Attachments come in a JSON format this will convert it into a PowerShell Object.\r\n                $NinjaPropertyValue | ConvertFrom-Json\r\n            }\r\n            \"Checkbox\" {\r\n                # Checkbox's come in as a string representing an integer. We'll need to cast that string into an integer and then convert it to a more traditional boolean.\r\n                [System.Convert]::ToBoolean([int]$NinjaPropertyValue)\r\n            }\r\n            \"Date or Date Time\" {\r\n                # In Ninja Date and Date\/Time fields are in Unix Epoch time in the UTC timezone the below should convert it into local time as a DateTime object.\r\n                $UnixTimeStamp = $NinjaPropertyValue\r\n                $UTC = (Get-Date \"1970-01-01 00:00:00\").AddSeconds($UnixTimeStamp)\r\n                $TimeZone = [TimeZoneInfo]::Local\r\n                [TimeZoneInfo]::ConvertTimeFromUtc($UTC, $TimeZone)\r\n            }\r\n            \"Decimal\" {\r\n                # In ninja decimals are strings that represent a decimal this will cast it into a double data type.\r\n                [double]$NinjaPropertyValue\r\n            }\r\n            \"Device Dropdown\" {\r\n                # Device Drop-Downs Fields come in a JSON format this will convert it into a PowerShell Object.\r\n                $NinjaPropertyValue | ConvertFrom-Json\r\n            }\r\n            \"Device MultiSelect\" {\r\n                # Device Multi-Select Fields come in a JSON format this will convert it into a PowerShell Object.\r\n                $NinjaPropertyValue | ConvertFrom-Json\r\n            }\r\n            \"Dropdown\" {\r\n                # Drop-Down custom fields come in as a comma-separated list of GUIDs; we'll compare these with all the options and return just the option values selected instead of a GUID.\r\n                $Options = $NinjaPropertyOptions -replace '=', ',' | ConvertFrom-Csv -Header \"GUID\", \"Name\"\r\n                $Options | Where-Object { $_.GUID -eq $NinjaPropertyValue } | Select-Object -ExpandProperty Name\r\n            }\r\n            \"Integer\" {\r\n                # Casts the Ninja provided string into an integer.\r\n                [int]$NinjaPropertyValue\r\n            }\r\n            \"MultiSelect\" {\r\n                # Multi-Select custom fields come in as a comma-separated list of GUIDs we'll compare these with all the options and return just the option values selected instead of a guid.\r\n                $Options = $NinjaPropertyOptions -replace '=', ',' | ConvertFrom-Csv -Header \"GUID\", \"Name\"\r\n                $Selection = ($NinjaPropertyValue -split ',').trim()\r\n\r\n                foreach ($Item in $Selection) {\r\n                    $Options | Where-Object { $_.GUID -eq $Item } | Select-Object -ExpandProperty Name\r\n                }\r\n            }\r\n            \"Organization Dropdown\" {\r\n                # Turns the Ninja provided JSON into a PowerShell Object.\r\n                $NinjaPropertyValue | ConvertFrom-Json\r\n            }\r\n            \"Organization Location Dropdown\" {\r\n                # Turns the Ninja provided JSON into a PowerShell Object.\r\n                $NinjaPropertyValue | ConvertFrom-Json\r\n            }\r\n            \"Organization Location MultiSelect\" {\r\n                # Turns the Ninja provided JSON into a PowerShell Object.\r\n                $NinjaPropertyValue | ConvertFrom-Json\r\n            }\r\n            \"Organization MultiSelect\" {\r\n                # Turns the Ninja provided JSON into a PowerShell Object.\r\n                $NinjaPropertyValue | ConvertFrom-Json\r\n            }\r\n            \"Time\" {\r\n                # Time fields are given as a number of seconds starting from midnight. This will convert it into a DateTime object.\r\n                $Seconds = $NinjaPropertyValue\r\n                $UTC = ([TimeSpan]::FromSeconds($Seconds)).ToString(\"hh\\:mm\\:ss\")\r\n                $TimeZone = [TimeZoneInfo]::Local\r\n                $ConvertedTime = [TimeZoneInfo]::ConvertTimeFromUtc($UTC, $TimeZone)\r\n\r\n                Get-Date $ConvertedTime -DisplayHint Time\r\n            }\r\n            default {\r\n                # If no type was given or not one that matches the above types just output what we retrieved.\r\n                $NinjaPropertyValue\r\n            }\r\n        }\r\n    }\r\n\r\n    $ExitCode = 0\r\n}\r\nprocess {\r\n    if (-not (Test-IsElevated)) {\r\n        Write-Host \"[Error] Access Denied. Please run with Administrator privileges.\"\r\n        exit 1\r\n    }\r\n\r\n    # Check that the NT Version is at least 6.1 for Windows Server 2008 R2\r\n    $WindowsVersion = $(Get-ItemProperty -Path \"HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\" -Name CurrentVersion).CurrentVersion\r\n    if ($WindowsVersion -lt 6.1 -or $(Test-IsWorkstation)) {\r\n        Write-Host \"[Error] This script requires Windows Server 2008 R2 or higher.\"\r\n        exit 1\r\n    }\r\n\r\n    # Get parameters from Script Variables\r\n    if ($env:customFieldName -and $env:customFieldName -notlike \"null\") {\r\n        $CustomFieldName = $env:customFieldName\r\n    }\r\n    if ($env:exchange2010Version -and $env:exchange2010Version -notlike \"null\") {\r\n        $Exchange2010Version = $env:exchange2010Version\r\n    }\r\n    if ($env:exchange2013Version -and $env:exchange2013Version -notlike \"null\") {\r\n        $Exchange2013Version = $env:exchange2013Version\r\n    }\r\n    if ($env:exchange2016Version -and $env:exchange2016Version -notlike \"null\") {\r\n        $Exchange2016Version = $env:exchange2016Version\r\n    }\r\n    if ($env:exchange2019Version -and $env:exchange2019Version -notlike \"null\") {\r\n        $Exchange2019Version = $env:exchange2019Version\r\n    }\r\n    if ($env:checkboxCustomField -and $env:checkboxCustomField -notlike \"null\") {\r\n        $CheckboxCustomField = $env:checkboxCustomField\r\n    }\r\n\r\n    # Required Parameters\r\n    if ($Exchange2010Version -and $Exchange2013Version -and $Exchange2016Version -and $Exchange2019Version) {\r\n        # Check if the versions are valid\r\n        if ([System.Version]::TryParse($Exchange2010Version, [ref]$null) -eq $false) {\r\n            Write-Host \"[Error] Exchange 2010 version is not a valid version: $Exchange2010Version\"\r\n            exit 1\r\n        }\r\n        if ([System.Version]::TryParse($Exchange2013Version, [ref]$null) -eq $false) {\r\n            Write-Host \"[Error] Exchange 2013 version is not a valid version: $Exchange2013Version\"\r\n            exit 1\r\n        }\r\n        if ([System.Version]::TryParse($Exchange2016Version, [ref]$null) -eq $false) {\r\n            Write-Host \"[Error] Exchange 2016 version is not a valid version: $Exchange2016Version\"\r\n            exit 1\r\n        }\r\n        if ([System.Version]::TryParse($Exchange2019Version, [ref]$null) -eq $false) {\r\n            Write-Host \"[Error] Exchange 2019 version is not a valid version: $Exchange2019Version\"\r\n            exit 1\r\n        }\r\n        # Requirements are met\r\n    }\r\n    else {\r\n        Write-Host \"[Error] Exchange 2010, 2013, 2016, and 2019 versions are required to run this script.\"\r\n        exit 1\r\n    }\r\n\r\n    if ($CheckboxCustomField -and $CheckboxCustomField -notlike \"null\") {\r\n        # Check if the text custom field is set to 1 as a check box or true as a string\r\n        try {\r\n            $boolCheck = Get-NinjaProperty -Name $CheckboxCustomField -Type \"Checkbox\"\r\n            $stringCheck = Get-NinjaProperty -Name $CheckboxCustomField\r\n            if (\r\n                $true -eq $boolCheck -or\r\n                $stringCheck -eq \"1\"\r\n            ) {\r\n                Write-Host \"[Info] Skipping Exchange version check.\"\r\n                exit 0\r\n            }\r\n        }\r\n        catch {\r\n            Write-Host \"[Warn] Failed to get the value of the checkbox custom field.\"\r\n            Write-Host \"[Info] Continuing with Exchange version check.\"\r\n        }\r\n    }\r\n\r\n    # Check if Exchange is installed\r\n    if (-not $(Get-Service -Name MSExchangeServiceHost -ErrorAction SilentlyContinue)) {\r\n        Write-Host \"[Error] This script requires Exchange to be installed and running.\"\r\n        exit 1\r\n    }\r\n\r\n    # Find the location of ExSetup.exe\r\n    $ExSetupPath = Get-ChildItem -Path \"C:\\Program Files\\Microsoft\\Exchange Server\\*\" -Recurse -Filter \"ExSetup.exe\" | Select-Object -ExpandProperty FullName\r\n    # Check if this is an Exchange server\r\n    if (-not (Test-Path -Path $ExSetupPath)) {\r\n        Write-Host \"[Error] Exchange Server is not installed.\"\r\n        exit 1\r\n    }\r\n\r\n    # Get the installed Exchange version from ExSetup.exe\r\n    $ExchangeFileVersion = Get-Command $ExSetupPath | ForEach-Object { $_.FileVersionInfo }\r\n    # Determine the edition of Exchange\r\n    $ExchangeYearVersion = switch ($ExchangeFileVersion.FileVersionRaw.Major) {\r\n        14 {\r\n            \"2010\"\r\n        }\r\n        15 {\r\n            switch ($ExchangeFileVersion.FileVersionRaw.Minor) {\r\n                0 { \"2013\" }\r\n                1 { \"2016\" }\r\n                2 { \"2019\" }\r\n                Default { \"Unknown\" }\r\n            }\r\n        }\r\n        Default { \"Unknown\" }\r\n    }\r\n\r\n    # Check if the Exchange version is outdated\r\n    switch ($ExchangeYearVersion) {\r\n        \"2010\" {\r\n            if ($ExchangeFileVersion.FileVersionRaw -lt $Exchange2010Version) {\r\n                Write-Host \"[Warn] Exchange 2010 version is outdated. Found version: $($ExchangeFileVersion.FileVersionRaw)\"\r\n            }\r\n            else {\r\n                Write-Host \"[Info] Exchange 2010 version is up to date. Found version: $($ExchangeFileVersion.FileVersionRaw)\"\r\n            }\r\n        }\r\n        \"2013\" {\r\n            if ($ExchangeFileVersion.FileVersionRaw -lt $Exchange2013Version) {\r\n                Write-Host \"[Warn] Exchange 2013 version is outdated. Found version: $($ExchangeFileVersion.FileVersionRaw)\"\r\n            }\r\n            else {\r\n                Write-Host \"[Info] Exchange 2013 version is up to date. Found version: $($ExchangeFileVersion.FileVersionRaw)\"\r\n            }\r\n        }\r\n        \"2016\" {\r\n            if ($ExchangeFileVersion.FileVersionRaw -lt $Exchange2016Version) {\r\n                Write-Host \"[Warn] Exchange 2016 version is outdated. Found version: $($ExchangeFileVersion.FileVersionRaw)\"\r\n            }\r\n            else {\r\n                Write-Host \"[Info] Exchange 2016 version is up to date. Found version: $($ExchangeFileVersion.FileVersionRaw)\"\r\n            }\r\n        }\r\n        \"2019\" {\r\n            if ($ExchangeFileVersion.FileVersionRaw -lt $Exchange2019Version) {\r\n                Write-Host \"[Warn] Exchange 2019 version is outdated. Found version: $($ExchangeFileVersion.FileVersionRaw)\"\r\n            }\r\n            else {\r\n                Write-Host \"[Info] Exchange 2019 version is up to date. Found version: $($ExchangeFileVersion.FileVersionRaw)\"\r\n            }\r\n        }\r\n        Default {\r\n            Write-Host \"[Error] Unknown Exchange version.\"\r\n            exit 1\r\n        }\r\n    }\r\n\r\n    if ($CustomFieldName -and $CustomFieldName -notlike \"null\") {\r\n        try {\r\n            Write-Host \"[Info] Attempting to set Custom Field '$CustomFieldName'.\"\r\n            Set-NinjaProperty -Name $CustomFieldName -Value $($ExchangeFileVersion.FileVersion | Out-String)\r\n            Write-Host \"[Info] Successfully set Custom Field '$CustomFieldName'!\"\r\n        }\r\n        catch {\r\n            Write-Host \"[Error] Failed to set Custom Field '$CustomFieldName'.\"\r\n            $ExitCode = 1\r\n        }\r\n    }\r\n\r\n    if ($ExitCode -gt 0) {\r\n        exit $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>Gagnez du temps gr\u00e2ce \u00e0 plus de 300 scripts du Dojo NinjaOne.<\/p>\n<p>\u2192 <a class=\"waffle-rich-text-link\" 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>Ce script PowerShell est structur\u00e9 en plusieurs composants cl\u00e9s qui fonctionnent ensemble pour v\u00e9rifier, valider et agir sur les informations relatives \u00e0 la version d&rsquo;Exchange Server. Voici une pr\u00e9sentation \u00e9tape par \u00e9tape\u00a0:<\/p>\n<h3>1. Initialisation et validation<\/h3>\n<p>a. Le script garantit qu&rsquo;il est ex\u00e9cut\u00e9 avec des privil\u00e8ges administratifs.<\/p>\n<p>b. Il v\u00e9rifie la compatibilit\u00e9 du syst\u00e8me en validant la version du syst\u00e8me d&rsquo;exploitation (Windows Server 2008 R2 ou sup\u00e9rieur) et confirme qu&rsquo;Exchange est install\u00e9 en localisant le fichier ExSetup.exe.<\/p>\n<h3>2. Param\u00e8tre Entr\u00e9e<\/h3>\n<p>a. Le script accepte les rep\u00e8res de version pour Exchange 2010, 2013, 2016 et 2019. Par exemple, vous pouvez sp\u00e9cifier -Exchange2019Version \u00ab\u00a015.2.0.0\u00a0\u00bb pour d\u00e9finir la version minimale acceptable pour Exchange 2019.<\/p>\n<p>b. Des param\u00e8tres optionnels comme -CustomFieldName et -CheckboxCustomField permettent aux administrateurs de g\u00e9rer les champs personnalis\u00e9s dans NinjaOne ou d&rsquo;ignorer la v\u00e9rification de la version si une certaine condition est remplie.<\/p>\n<h3>3. R\u00e9cup\u00e9ration des versions<\/h3>\n<p>a. Il r\u00e9cup\u00e8re la version d&rsquo;Exchange install\u00e9e en analysant la version du fichier ExSetup.exe. En se basant sur les num\u00e9ros de version majeure et mineure, il d\u00e9termine l&rsquo;\u00e9dition d&rsquo;Exchange (par exemple, 2010, 2013).<\/p>\n<h3>4. Comparaison des versions<\/h3>\n<p>a. Le script compare la version r\u00e9cup\u00e9r\u00e9e avec les points de r\u00e9f\u00e9rence sp\u00e9cifi\u00e9s. Si la version est obsol\u00e8te, un avertissement s&rsquo;affiche. Les versions actualis\u00e9es sont confirm\u00e9es par un message d&rsquo;information.<\/p>\n<h3>5. Int\u00e9gration de champs personnalis\u00e9s<\/h3>\n<p>a. Si le param\u00e8tre -CustomFieldName est fourni, le script d\u00e9finit les informations relatives \u00e0 la version dans un champ personnalis\u00e9, ce qui permet un suivi facile dans des outils tels que NinjaOne.<\/p>\n<h3>6. Gestion des erreurs et codes de sortie<\/h3>\n<p>a. Le script est con\u00e7u pour g\u00e9rer de mani\u00e8re \u00e9l\u00e9gante les erreurs, telles que les installations Exchange manquantes ou les entr\u00e9es de versions invalides, et se termine avec les codes d&rsquo;\u00e9tat appropri\u00e9s.<\/p>\n<h2>Cas d&rsquo;utilisation potentiels<\/h2>\n<h3>\u00c9tude de cas\u00a0: Gestion des versions d&rsquo;Exchange dans un environnement multi-site<\/h3>\n<p>Imaginez un administrateur informatique qui supervise plusieurs d\u00e9ploiements Exchange dans des bureaux r\u00e9gionaux. L&rsquo;administrateur utilise ce script dans le cadre d&rsquo;une t\u00e2che de maintenance planifi\u00e9e pour v\u00e9rifier les versions d&rsquo;Exchange, valider la conformit\u00e9 avec les politiques de l&rsquo;entreprise et mettre \u00e0 jour les champs personnalis\u00e9s de NinjaOne avec les donn\u00e9es de la derni\u00e8re version. Si une version est obsol\u00e8te, l&rsquo;administrateur est alert\u00e9 pour donner la priorit\u00e9 aux mises \u00e0 jour, ce qui garantit que l&rsquo;environnement reste s\u00e9curis\u00e9 et conforme.<\/p>\n<h2>Comparaisons<\/h2>\n<p>L&rsquo;approche automatis\u00e9e de ce script offre de nets avantages par rapport aux m\u00e9thodes manuelles ou aux outils bas\u00e9s sur l&rsquo;interface graphique\u00a0:<\/p>\n<ul>\n<li><strong>M\u00e9thodes manuelles<\/strong>\u00a0: La v\u00e9rification manuelle des versions d&rsquo;Exchange implique de se connecter \u00e0 chaque serveur et d&rsquo;ex\u00e9cuter des commandes individuelles &#8211; un processus qui prend du temps et qui est source d&rsquo;erreurs.<\/li>\n<li><strong>Outils GUI<\/strong>\u00a0: Si certains outils de gestion fournissent des informations graphiques, ils n&rsquo;ont souvent pas les capacit\u00e9s de personnalisation et d&rsquo;automatisation qu&rsquo;offre ce script, en particulier pour les entreprises MSP qui g\u00e8rent plusieurs environnements.<\/li>\n<\/ul>\n<h2>FAQ<\/h2>\n<p><strong>Q\u00a0: Que se passe-t-il si Exchange n&rsquo;est pas install\u00e9\u00a0?<\/strong><br \/>\nLe script se termine et affiche un message d&rsquo;erreur, ce qui permet de s&rsquo;assurer que les administrateurs sont conscients du probl\u00e8me.<\/p>\n<p><strong>Q\u00a0: Puis-je utiliser ce script pour v\u00e9rifier en bloc les versions d&rsquo;Exchange\u00a0?<\/strong><br \/>\nOui, lorsqu&rsquo;il est int\u00e9gr\u00e9 \u00e0 des outils tels que NinjaOne, vous pouvez automatiser les contr\u00f4les de version sur plusieurs serveurs.<\/p>\n<p><strong>Q\u00a0: Que se passe-t-il si les r\u00e9f\u00e9rences de la version fournie ne sont pas valides\u00a0?<\/strong><br \/>\nLe script valide chaque entr\u00e9e de version et se termine par une erreur si l&rsquo;un des rep\u00e8res n&rsquo;est pas un format de version valide.<\/p>\n<p><strong>Q\u00a0: Comment les champs personnalis\u00e9s fonctionnent-ils dans ce script\u00a0?<\/strong><br \/>\nLes champs personnalis\u00e9s permettent aux administrateurs d&rsquo;enregistrer les informations relatives aux versions dans les syst\u00e8mes de gestion. Le script interagit avec NinjaOne pour d\u00e9finir ces champs de mani\u00e8re dynamique.<\/p>\n<h2>Implications<\/h2>\n<p>En identifiant les versions obsol\u00e8tes d&rsquo;Exchange Server, ce script permet de pr\u00e9venir les failles de s\u00e9curit\u00e9 potentielles et de garantir la conformit\u00e9 avec les configurations prises en charge. L&rsquo;utilisation r\u00e9guli\u00e8re de cette automatisation r\u00e9duit le <a href=\"https:\/\/www.ninjaone.com\/blog\/how-human-error-relates-to-cybersecurity-risks\/\">risque d&rsquo;erreur humaine<\/a>, am\u00e9liore l&rsquo;efficacit\u00e9 et permet une gestion informatique proactive.<\/p>\n<h2>Recommandations pour v\u00e9rifier les versions du serveur Exchange<\/h2>\n<ul>\n<li><strong>Testez le script dans un environnement hors production<\/strong>\u00a0: Testez toujours les scripts dans un environnement d&rsquo;essai pour vous assurer qu&rsquo;ils sont compatibles avec votre configuration.<\/li>\n<li><strong>Programmez des contr\u00f4les r\u00e9guliers<\/strong>\u00a0: Utilisez la planification des t\u00e2ches pour automatiser des v\u00e9rifications r\u00e9guli\u00e8res et maintenir vos environnements Exchange \u00e0 jour.<\/li>\n<li><strong>Exploitez judicieusement les champs personnalis\u00e9s<\/strong>\u00a0: Utilisez le param\u00e8tre -CustomFieldName pour conserver des informations compl\u00e8tes sur votre environnement.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>La gestion des environnements Exchange Server est une responsabilit\u00e9 essentielle pour les professionnels de l&rsquo;informatique. Ce script PowerShell simplifie le processus de v\u00e9rification et de validation des versions d&rsquo;Exchange, ce qui permet aux entreprises de maintenir des syst\u00e8mes s\u00e9curis\u00e9s, conformes et performants. Pour ceux qui utilisent <a href=\"https:\/\/www.ninjaone.com\/fr\/\">NinjaOne<\/a>, les capacit\u00e9s d&rsquo;int\u00e9gration du script am\u00e9liorent l&rsquo;efficacit\u00e9 op\u00e9rationnelle, ce qui en fait un outil inestimable pour la gestion moderne de l&rsquo;informatique.<\/p>\n","protected":false},"author":35,"featured_media":0,"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-390736","script_hub","type-script_hub","status-publish","hentry","script_hub_category-windows","use_cases-configuration-generale"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/script_hub\/390736","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=390736"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/media?parent=390736"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/operating_system?post=390736"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/use_cases?post=390736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}