{"id":534746,"date":"2025-09-30T18:11:04","date_gmt":"2025-09-30T18:11:04","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=534746"},"modified":"2025-09-30T18:11:04","modified_gmt":"2025-09-30T18:11:04","slug":"forcer-une-synchronisation-temporelle-avec-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/fr\/script-hub\/forcer-une-synchronisation-temporelle-avec-powershell\/","title":{"rendered":"Comment forcer une synchronisation temporelle avec PowerShell"},"content":{"rendered":"<p>Un chronom\u00e9trage pr\u00e9cis est essentiel dans les environnements informatiques des entreprises. Qu&rsquo;il s&rsquo;agisse d&rsquo;audit de s\u00e9curit\u00e9, de corr\u00e9lation de journaux, d&rsquo;authentification Kerberos ou de planification de t\u00e2ches d&rsquo;automatisation, une horloge syst\u00e8me correctement synchronis\u00e9e peut faire la diff\u00e9rence entre un fonctionnement sans heurts et une perturbation g\u00e9n\u00e9ralis\u00e9e. Malheureusement, la d\u00e9rive temporelle est fr\u00e9quente sur les syst\u00e8mes Windows, en particulier ceux qui sont d\u00e9connect\u00e9s d&rsquo;Active Directory ou dont les services de gestion du temps sont mal configur\u00e9s. Cet article explique comment les professionnels de l&rsquo;informatique <strong>forcent une synchronisation temporelle avec PowerShell<\/strong> sur Windows, afin de garantir la pr\u00e9cision et la fiabilit\u00e9 des op\u00e9rations.<\/p>\n<h2>Contexte<\/h2>\n<p>Les appareils Windows s&rsquo;appuient sur le service Windows Time (W32Time) pour se synchroniser avec une source de temps fiable, g\u00e9n\u00e9ralement \u00e0 l&rsquo;aide du protocole NTP (Network Time Protocol). Cependant, W32Time peut parfois ne pas d\u00e9marrer, d\u00e9river de mani\u00e8re significative ou pointer vers des serveurs de temps non valides. Pour les <a href=\"https:\/\/www.ninjaone.com\/fr\/quest-ce-quun-msp\/\">fournisseurs de services g\u00e9r\u00e9s (MSP)<\/a> et les administrateurs informatiques qui g\u00e8rent divers parcs de terminaux, en particulier dans les environnements de travail distribu\u00e9s ou hybrides, il est essentiel de pouvoir inspecter et r\u00e9soudre les probl\u00e8mes de synchronisation de mani\u00e8re programmatique.<\/p>\n<p>Le script <a href=\"https:\/\/www.ninjaone.com\/it-hub\/endpoint-management\/what-is-powershell\/\">PowerShell<\/a> fourni r\u00e9pond pr\u00e9cis\u00e9ment \u00e0 ce besoin. Il inspecte la configuration actuelle de la synchronisation du temps, v\u00e9rifie le service Windows Time, l&rsquo;active et le d\u00e9marre \u00e9ventuellement, puis tente une synchronisation manuelle du temps. En cours de route, il fournit un aper\u00e7u d\u00e9taill\u00e9 du fuseau horaire du syst\u00e8me et de l&rsquo;\u00e9tat de la synchronisation, aidant ainsi les professionnels de l&rsquo;informatique \u00e0 prendre des d\u00e9cisions \u00e9clair\u00e9es ou \u00e0 r\u00e9soudre des probl\u00e8mes de temps plus profonds.<\/p>\n<h2>Le script\u00a0:<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">#Requires -Version 5.1\r\n\r\n&lt;#\r\n.SYNOPSIS\r\n    Force a time synchronization with the current time settings and display the current time zone and time sync settings.\r\n.DESCRIPTION\r\n    Force a time synchronization with the current time settings and display the current time zone and time sync settings.\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\r\n.PARAMETER -EnableAndStartWindowsTimeService\r\n    Enable and start the Windows Time service if it is disabled or not running. This will set the Start Type to 'Automatic.' This service is required to force a time sync.\r\n\r\n.EXAMPLE\r\n    ### Current time zone settings: ###\r\n\r\n    Id                         : Pacific Standard Time\r\n    DisplayName                : (UTC-08:00) Pacific Time (US &amp; Canada)\r\n    StandardName               : Pacific Standard Time\r\n    DaylightName               : Pacific Daylight Time\r\n    BaseUtcOffset              : -08:00:00\r\n    SupportsDaylightSavingTime : True\r\n\r\n    ### Current time sync settings: ###\r\n\r\n    Sync Type                      : NTP only\r\n    NTP Servers                    : time.windows.com\r\n    Last Sync Time                 : 5\/12\/2025 1:05:48 PM\r\n    Last Sync Source               : time.windows.com\r\n    Sync Interval (NTP)            : 10 minutes\r\n    Sync Interval Minimum (Domain) : 1 minutes\r\n    Sync Interval Maximum (Domain) : 546 minutes\r\n\r\n    [Info] Attempting to force a sync with current time settings...\r\n    Sending resync command to local computer\r\n    The command completed successfully.\r\n\r\n    ### Current time: ###\r\n\r\n    Monday, May 12, 2025 1:05:55 PM\r\n\r\n.NOTES\r\n    Minimum OS Architecture Supported: Windows 10, Windows Server 2016\r\n    Release Notes: Initial Release\r\n#&gt;\r\n\r\n[CmdletBinding()]\r\nparam (\r\n    [Parameter()]\r\n    [switch]$EnableAndStartWindowsTimeService = [System.Convert]::ToBoolean($env:EnableAndStartWindowsTimeService)\r\n)\r\n\r\nbegin {\r\n    function Test-IsElevated {\r\n        [CmdletBinding()]\r\n        param ()\r\n        \r\n        # Get the current Windows identity of the user running the script\r\n        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()\r\n        \r\n        # Create a WindowsPrincipal object based on the current identity\r\n        $p = New-Object System.Security.Principal.WindowsPrincipal($id)\r\n        \r\n        # Check if the current user is in the Administrator role\r\n        # The function returns $True if the user has administrative privileges, $False otherwise\r\n        # 544 is the value for the Built In Administrators role\r\n        # Reference: https:\/\/learn.microsoft.com\/en-us\/dotnet\/api\/system.security.principal.windowsbuiltinrole\r\n        $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]'544')\r\n    }\r\n    function Get-TimeSettings {\r\n        # Get the time sync status\r\n        try {\r\n            $StatusOutputFilename = \"$env:temp\\w32tm_status_output_$(Get-Random).txt\"\r\n            Start-Process -FilePath \"$env:WinDir\\system32\\w32tm.exe\" -ArgumentList \"\/query \/status\" -RedirectStandardOutput $StatusOutputFilename -NoNewWindow -Wait\r\n        }\r\n        catch {\r\n            throw (New-Object System.Exception(\"Unable to retrieve time sync status.\"))\r\n        }\r\n        \r\n        # Get the time sync configuration\r\n        try {\r\n            $ConfigOutputFilename = \"$env:temp\\w32tm_config_output_$(Get-Random).txt\"\r\n            Start-Process -FilePath \"$env:WinDir\\system32\\w32tm.exe\" -ArgumentList \"\/query \/configuration\" -RedirectStandardOutput $ConfigOutputFilename -NoNewWindow -Wait\r\n        }\r\n        catch {\r\n            throw (New-Object System.Exception(\"Unable to retrieve time sync configuration.\"))\r\n        }\r\n        \r\n        # Attempt to read the status output file\r\n        try {\r\n            $status = Get-Content $StatusOutputFilename -Encoding Oem\r\n        }\r\n        catch {\r\n            throw (New-Object System.Exception(\"Unable to read time sync status.\"))\r\n        }\r\n\r\n        # Attempt to read the config output file\r\n        try {\r\n            $config = Get-Content $ConfigOutputFilename -Encoding Oem\r\n        }\r\n        catch {\r\n            throw (New-Object System.Exception(\"Unable to read time sync configuration.\"))\r\n        }\r\n\r\n        $lastSyncTime = ($status[-4] -replace \"^\\w+:\\s\" -replace \"^.+: \" | Out-String).Trim()\r\n        $lastSyncSource = ($status[-3] -replace \"^\\w+:\\s\" -replace \"^.+: \" -replace \",0x\\w\" | Out-String).Trim()\r\n        $syncType = (($config | Select-String -Pattern \"^Type: \") -replace \"Type: \" -replace \"\\(.+$\" | Out-String).Trim()\r\n\r\n        $regPath = \"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\W32Time\\Parameters\"\r\n        $NtpServers = (Get-ItemProperty -Path $regPath -Name \"NtpServer\" -ErrorAction SilentlyContinue).NtpServer.Trim() -replace \",0x\\w\" -replace \"\\s\",\", \"\r\n\r\n        $syncType = switch ($syncType) {\r\n            \"NTP\" { \"NTP only\" }\r\n            \"NT5DS\" { \"Domain only\" }\r\n            \"AllSync\" { \"Domain with NTP as fallback\" }\r\n            default { \"Unknown\" }\r\n        }\r\n\r\n        # Get the SpecialPollInterval from the config\r\n        $SpecialPollInterval = ($config | Select-String -Pattern \"^SpecialPollInterval: \") -replace \"SpecialPollInterval: \" -replace \"\\(.+$\"\r\n        # Convert the SpecialPollInterval to minutes\r\n        $SpecialPollIntervalInMinutes = [int]$SpecialPollInterval \/ 60\r\n\r\n        $object = [PSCustomObject]@{\r\n            \"Sync Type\"         = $syncType\r\n            \"NTP Servers\"       = $NtpServers\r\n            \"Last Sync Time\"    = $lastSyncTime\r\n            \"Last Sync Source\"  = $lastSyncSource\r\n            \"Sync Interval (NTP)\" = \"$SpecialPollIntervalInMinutes minutes\"\r\n        }\r\n\r\n        # Get the Min and Max poll intervals used for domain time sync\r\n        $regPath = \"HKLM:\\SYSTEM\\CurrentControlSet\\Services\\W32Time\\Config\"\r\n        $MinPollInterval = (Get-ItemProperty -Path $regPath -Name \"MinPollInterval\" -ErrorAction SilentlyContinue).MinPollInterval\r\n        $MaxPollInterval = (Get-ItemProperty -Path $regPath -Name \"MaxPollInterval\" -ErrorAction SilentlyContinue).MaxPollInterval\r\n\r\n        if ($MinPollInterval -and $MaxPollInterval) {\r\n            # These values are actually powers of 2, the resulting value is the amount of seconds\r\n            $MinPollInterval = [math]::Pow(2, $MinPollInterval)\r\n            $MaxPollInterval = [math]::Pow(2, $MaxPollInterval)\r\n\r\n            # Convert those seconds to minutes\r\n            $MinPollInterval = [math]::Round($MinPollInterval \/ 60)\r\n            $MaxPollInterval = [math]::Round($MaxPollInterval \/ 60)\r\n\r\n            # Add the intervals to the object\r\n            $object | Add-Member -MemberType NoteProperty -Name \"Sync Interval Minimum (Domain)\" -Value \"$MinPollInterval minutes\"\r\n            $object | Add-Member -MemberType NoteProperty -Name \"Sync Interval Maximum (Domain)\" -Value \"$MaxPollInterval minutes\"\r\n        }\r\n        else {\r\n            Write-Host -Object \"[Warning] Unable to retrieve the minimum and maximum poll intervals from the registry.\"\r\n            $object | Add-Member -MemberType NoteProperty -Name \"Sync Interval Minimum (Domain)\" -Value \"Unavailable\"\r\n            $object | Add-Member -MemberType NoteProperty -Name \"Sync Interval Maximum (Domain)\" -Value \"Unavailable\"\r\n        }\r\n\r\n        # Attempt to remove the status output file\r\n        try {\r\n            Remove-Item $StatusOutputFilename -ErrorAction Stop\r\n        }\r\n        catch {\r\n            Write-Host -Object \"[Warning] Unable to delete the temporary file '$StatusOutputFilename'.\"\r\n        }\r\n\r\n        # Attempt to remove the config output file\r\n        try {\r\n            Remove-Item $ConfigOutputFilename -ErrorAction Stop\r\n        }\r\n        catch {\r\n            Write-Host -Object \"[Warning] Unable to delete the temporary file '$ConfigOutputFilename'.\"\r\n        }\r\n\r\n        return $object\r\n    }\r\n}\r\nprocess {\r\n    # Attempt to determine if the current session is running with Administrator privileges.\r\n    try {\r\n        $IsElevated = Test-IsElevated -ErrorAction Stop\r\n    }\r\n    catch {\r\n        Write-Host -Object \"[Error] $($_.Exception.Message)\"\r\n        Write-Host -Object \"[Error] Unable to determine if the account '$env:Username' is running with Administrator privileges.\"\r\n        exit 1\r\n    }\r\n    \r\n    if (!$IsElevated) {\r\n        Write-Host -Object \"[Error] Access Denied: Please run with Administrator privileges.\"\r\n        exit 1\r\n    }\r\n\r\n    $ExitCode = 0\r\n\r\n    # Get status of Windows Time Service\r\n    # This service is required for time sync\r\n    try {\r\n        $WindowsTimeService = Get-Service -Name \"w32time\" -ErrorAction Stop\r\n    }\r\n    catch {\r\n        Write-Host -Object \"[Error] Unable to retrieve Windows Time service status.\"\r\n        Write-Host -Object \"[Error] $($_.Exception.Message)\"\r\n        exit 1\r\n    }\r\n\r\n    # Enable the Windows Time service if requested\r\n    if ($EnableAndStartWindowsTimeService) {\r\n        Write-Host -Object \"`n[Info] Setting Windows Time service to start up automatically...\"\r\n\r\n        # Set the start type to automatic if it is not already\r\n        if ($WindowsTimeService.StartType -ne \"Automatic\") {\r\n            try {\r\n                Set-Service -Name \"w32time\" -StartupType Automatic -ErrorAction Stop\r\n                Write-Host -Object \"[Info] Windows Time service enabled successfully.\"\r\n            }\r\n            catch {\r\n                Write-Host -Object \"[Error] Unable to enable Windows Time service.\"\r\n                Write-Host -Object \"[Error] $($_.Exception.Message)\"\r\n                # Set flag to true so that we can skip forcing the sync\r\n                $serviceError = $true\r\n                $ExitCode = 1\r\n            }\r\n        }\r\n        else {\r\n            Write-Host \"[Info] Windows Time service is already set to start automatically.\"\r\n        }\r\n\r\n        # Start the Windows Time service if it is not already running\r\n        Write-Host -Object \"`n[Info] Starting Windows Time service...\"\r\n        if ($WindowsTimeService.Status -ne \"Running\") {\r\n            try {\r\n                Start-Service -Name \"w32time\" -WarningAction SilentlyContinue -ErrorAction Stop\r\n                Write-Host -Object \"[Info] Windows Time service started successfully.\"\r\n            }\r\n            catch {\r\n                Write-Host -Object \"[Error] Unable to enable Windows Time service.\"\r\n                Write-Host -Object \"[Error] $($_.Exception.Message)\"\r\n                # Set flag to true so that we can skip forcing the sync\r\n                $serviceError = $true\r\n                $ExitCode = 1\r\n            }\r\n        }\r\n        else {\r\n            Write-Host \"[Info] Windows Time service is already running.\"\r\n        }\r\n    }\r\n    # Otherwise check if the service is running and set to start automatically, error if not\r\n    else {\r\n        if ($WindowsTimeService.StartType -ne \"Automatic\") {\r\n            Write-Host \"`n[Error] Windows Time service is not set to start automatically. Please use the 'Enable and Start Windows Time Service' option to enable it.\"\r\n            # Set flag to true so that we can skip forcing the sync\r\n            $serviceError = $true\r\n            $ExitCode = 1\r\n        }\r\n        elseif ($WindowsTimeService.Status -ne \"Running\") {\r\n            Write-Host \"`n[Error] Windows Time service is not running. Please use the 'Enable and Start Windows Time Service' option to start it.\"\r\n            # Set flag to true so that we can skip forcing the sync\r\n            $serviceError = $true\r\n            $ExitCode = 1\r\n        }\r\n    }\r\n\r\n    # Show current time zone settings\r\n    try {\r\n        Write-Host -Object \"`n### Current time zone settings: ###`n\"\r\n        (Get-TimeZone -ErrorAction Stop | Out-String).Trim()\r\n    }\r\n    catch {\r\n        Write-Host -Object \"[Error] Unable to retrieve current time zone settings.\"\r\n        Write-Host -Object \"[Error] $($_.Exception.Message)\"\r\n        $ExitCode = 1\r\n    }\r\n    \r\n    # Show current time sync settings if the Windows Time service is running\r\n    if (-not $serviceError) {\r\n        try {\r\n            Write-Host -Object \"`n### Current time sync settings: ###`n\"\r\n            $timeSettings = Get-TimeSettings -ErrorAction Stop\r\n            ($timeSettings | Format-List | Out-String).Trim()\r\n            if ($timeSettings.\"Sync Type\" -eq \"Unknown\") {\r\n                Write-Host -Object \"`n[Error] Unable to determine the sync type. The time sync settings may not be configured correctly.\"\r\n                $skipSync = $true\r\n                $ExitCode = 1\r\n            }\r\n        }\r\n        catch {\r\n            Write-Host -Object \"[Error] Unable to retrieve current time sync settings.\"\r\n            $skipSync = $true\r\n            Write-Host -Object \"[Error] $($_.Exception.Message)\"\r\n            $ExitCode = 1\r\n        }\r\n    }\r\n    else {\r\n        Write-Host -Object \"`n[Error] Unable to retrieve current time sync settings because the Windows Time service is not running.\"\r\n    }\r\n\r\n    # Force a sync if Windows Time service is running\r\n    if ($serviceError) {\r\n        Write-Host \"`n[Error] Unable to force a time sync because the Windows Time service is not running.\"\r\n        $ExitCode = 1\r\n    }\r\n    elseif ($skipSync) {\r\n        Write-Host \"`n[Error] Unable to force a time sync because the sync type is unknown. Please correct the time sync settings using the 'Time Sync - Configure Settings' script in the Template Library.\"\r\n    }\r\n    else {\r\n        try {\r\n            Write-Host \"`n[Info] Attempting to force a sync with current time settings...\"\r\n\r\n            # Create a temporary file to store the output\r\n            $ResyncOutputFile = \"$env:temp\\w32tm_resync_output_$(Get-Random).txt\"\r\n            \r\n            # Start the process to force a time sync \r\n            Start-Process -FilePath \"$env:Windir\\System32\\w32tm.exe\" -ArgumentList \"\/resync\" -NoNewWindow -Wait -RedirectStandardOutput $ResyncOutputFile -ErrorAction Stop\r\n        }\r\n        catch {\r\n            Write-Host -Object \"[Error] Unable to initiate time sync.\"\r\n            Write-Host -Object \"[Error] $($_.Exception.Message)\"\r\n            $ExitCode = 1\r\n        }\r\n\r\n        # Make sure the output file exists\r\n        if (Test-Path -Path $ResyncOutputFile) {\r\n            # Read the output of the time sync\r\n            try {\r\n                Get-Content $ResyncOutputFile -Encoding Oem -ErrorAction Stop | Out-Host\r\n            }\r\n            catch {\r\n                Write-Host -Object \"[Error] Unable to read the output of the time sync.\"\r\n                Write-Host -Object \"[Error] $($_.Exception.Message)\"\r\n                $ExitCode = 1\r\n            }\r\n\r\n            # Clean up the output file\r\n            try {\r\n                Remove-Item -Path $ResyncOutputFile -Force -ErrorAction Stop\r\n            }\r\n            catch {\r\n                Write-Host -Object \"[Error] Unable to delete the output file.\"\r\n                Write-Host -Object \"[Error] $($_.Exception.Message)\"\r\n                $ExitCode = 1\r\n            }\r\n        }\r\n        else {\r\n            Write-Host -Object \"[Error] Unable to find the output file.\"\r\n            $ExitCode = 1\r\n        }\r\n    }\r\n    \r\n    # Show current time\r\n    try {\r\n        Write-Host -Object \"`n### Current time: ###\"\r\n        Get-Date -DisplayHint DateTime -ErrorAction Stop | Out-Host\r\n    }\r\n    catch {\r\n        Write-Host -Object \"[Error] Unable to retrieve current time.\"\r\n        Write-Host -Object \"[Error] $($_.Exception.Message)\"\r\n        $ExitCode = 1\r\n    }\r\n\r\n    exit $ExitCode\r\n}\r\nend {\r\n    \r\n    \r\n    \r\n}<\/pre>\n<p>&nbsp;<\/p>\n\n<h2>Description d\u00e9taill\u00e9e<\/h2>\n<p>Le script est modulaire et complet, ce qui le rend bien adapt\u00e9 \u00e0 l&rsquo;ex\u00e9cution autonome et \u00e0 l&rsquo;int\u00e9gration dans des outils tels que\u00a0<strong>NinjaOne<\/strong>. Voici une description \u00e9tape par \u00e9tape\u00a0:<\/p>\n<h3>1. Contr\u00f4le des autorisations<\/h3>\n<p>Il commence par v\u00e9rifier si le script est ex\u00e9cut\u00e9 avec des privil\u00e8ges administratifs, car les actions de synchronisation temporelle n\u00e9cessitent une \u00e9l\u00e9vation.<\/p>\n<h3>2. Validation du service Windows Time<\/h3>\n<p>Il interroge le service w32time :<\/p>\n<ul>\n<li>Si l&rsquo;option -EnableAndStartWindowsTimeService est pass\u00e9e (ou d\u00e9finie par une variable d&rsquo;environnement), le service d\u00e9marre automatiquement et s&rsquo;assure qu&rsquo;il est en cours d&rsquo;ex\u00e9cution.<\/li>\n<li>Dans le cas contraire, il v\u00e9rifie que le service est actif et avertit l&rsquo;utilisateur s&rsquo;il ne l&rsquo;est pas.<\/li>\n<\/ul>\n<h3>3. Affichage du fuseau horaire et des param\u00e8tres de synchronisation<\/h3>\n<p>Le texte alors :<\/p>\n<ul>\n<li>Affiche le\u00a0<strong>fuseau horaire<\/strong>\u00a0actuel en utilisant Get-TimeZone.<\/li>\n<li>Utilise les commandes w32tm.exe pour recueillir l&rsquo;\u00e9tat et la configuration de la synchronisation.<\/li>\n<li>Parses :\n<ul>\n<li>Serveurs NTP utilis\u00e9s<\/li>\n<li>Derni\u00e8re heure de synchronisation et source<\/li>\n<li>Intervalles de synchronisation (NTP et sp\u00e9cifiques au domaine)<\/li>\n<li>Type de synchronisation : NTP, bas\u00e9 sur un domaine (NT5DS), ou fallback (AllSync)<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>4. Forcer la synchronisation de l&rsquo;heure<\/h3>\n<p>Si la validation r\u00e9ussit, il appelle w32tm \/resync et capture la sortie, indiquant le succ\u00e8s ou d\u00e9taillant les erreurs.<\/p>\n<h3>5. Courant de sortie Temps<\/h3>\n<p>Il se termine par l&rsquo;affichage de l&rsquo;heure actualis\u00e9e du syst\u00e8me.<\/p>\n<h2>Cas d&rsquo;utilisation potentiels<\/h2>\n<h3>\u00c9tude de cas\u00a0: D\u00e9rive des terminaux de vente distant<\/h3>\n<p>Un fournisseur de services g\u00e9r\u00e9s (MSP) prend en charge 300 syst\u00e8mes de point de vente (POS) au d\u00e9tail, dont beaucoup ne sont pas reli\u00e9s \u00e0 un domaine et d\u00e9pendent de serveurs NTP publics. Au fil du temps, plusieurs terminaux sont d\u00e9synchronis\u00e9s de plusieurs minutes, ce qui entra\u00eene des d\u00e9calages entre l&rsquo;horodatage des transactions et le syst\u00e8me central de facturation.<\/p>\n<p>En utilisant ce script via le\u00a0<strong>module de script de NinjaOne<\/strong>, l&rsquo;\u00e9quipe informatique l&rsquo;envoie \u00e0 tous les syst\u00e8mes concern\u00e9s. Le script\u00a0:<\/p>\n<ul>\n<li>Valide et d\u00e9marre le service Windows Time,<\/li>\n<li>Confirme la configuration du serveur NTP,<\/li>\n<li>Resynchronise l&rsquo;horloge, et<\/li>\n<li>Enregistre les param\u00e8tres de synchronisation actuels \u00e0 des fins d&rsquo;audit.<\/li>\n<\/ul>\n<p>Cette solution proactive permet d&rsquo;\u00e9viter les retards ayant un impact sur les recettes et les erreurs de r\u00e9conciliation lors du traitement de fin de journ\u00e9e.<\/p>\n<h2>Comparaisons<\/h2>\n<table>\n<tbody>\n<tr>\n<td style=\"text-align: center;\"><strong>M\u00e9thode<\/strong><\/td>\n<td style=\"text-align: center;\"><strong>Avantages<\/strong><\/td>\n<td style=\"text-align: center;\"><strong>Inconv\u00e9nients<\/strong><\/td>\n<\/tr>\n<tr>\n<td><strong>Commandes du manuel w32tm<\/strong><\/td>\n<td>Des r\u00e9pliques rapides<\/td>\n<td>Pas de validation, de traitement des erreurs ou de contr\u00f4le des services<\/td>\n<\/tr>\n<tr>\n<td><strong>Politique de groupe \/ Contr\u00f4le de domaine<\/strong><\/td>\n<td>Automatique pour les appareils reli\u00e9s \u00e0 AD<\/td>\n<td>Inefficace pour les groupes de travail ou les syst\u00e8mes distants<\/td>\n<\/tr>\n<tr>\n<td><strong>Ce script PowerShell<\/strong><\/td>\n<td>Visibilit\u00e9 totale, automatisation possible, prise en charge des appareils AD et non AD<\/td>\n<td>Acc\u00e8s administrateur et PowerShell 5.1+ requis<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Ce script comble le foss\u00e9 entre le d\u00e9pannage manuel et l&rsquo;automatisation bas\u00e9e sur le domaine, en particulier pour les environnements hybrides et MSP.<\/p>\n<h2>FAQ<\/h2>\n<h3>Question 1\u00a0: Ce script peut-il fonctionner sur des syst\u00e8mes qui ne sont pas des domaines ?<\/h3>\n<p>Oui. Il d\u00e9tecte le type de synchronisation et prend en charge les configurations NTP uniquement.<\/p>\n<h3>Question 2\u00a0: Que se passe-t-il si la synchronisation \u00e9choue ?<\/h3>\n<p>Le script fournit des erreurs sp\u00e9cifiques, telles qu&rsquo;un service qui ne fonctionne pas, une mauvaise configuration ou un type de synchronisation inconnu, ce qui permet d&rsquo;orienter les mesures correctives.<\/p>\n<h3>Question 3\u00a0: Le script peut-il \u00eatre ex\u00e9cut\u00e9 plusieurs fois en toute s\u00e9curit\u00e9 ?<\/h3>\n<p>Absolument. Il v\u00e9rifie l&rsquo;\u00e9tat des services et \u00e9vite les changements redondants.<\/p>\n<h3>Question 4\u00a0: Puis-je programmer ce script\u00a0?<\/h3>\n<p>Oui. Il peut \u00eatre programm\u00e9 via le planificateur de t\u00e2ches, des outils RMM tels que NinjaOne, ou int\u00e9gr\u00e9 dans des flux de travail de rem\u00e9diation plus larges.<\/p>\n<h2>Implications<\/h2>\n<p>Un service de gestion du temps mal configur\u00e9 n&rsquo;est pas seulement un d\u00e9sagr\u00e9ment, il peut entra\u00eener de graves d\u00e9faillances informatiques. Les services d&rsquo;authentification (Kerberos), les journaux d&rsquo;\u00e9v\u00e9nements, la surveillance du syst\u00e8me et m\u00eame la validation des certificats SSL\/TLS d\u00e9pendent de l&rsquo;exactitude des horloges du syst\u00e8me. En utilisant ce script pour inspecter et appliquer la synchronisation, les \u00e9quipes informatiques r\u00e9duisent les risques :<\/p>\n<ul>\n<li>Risques pour la s\u00e9curit\u00e9 dus \u00e0 des d\u00e9faillances d&rsquo;audit,<\/li>\n<li>Les erreurs d&rsquo;application dues \u00e0 la logique temporelle, et<\/li>\n<li>Lacunes en mati\u00e8re de conformit\u00e9 dans des environnements o\u00f9 le temps est compt\u00e9.<\/li>\n<\/ul>\n<h2>Recommandations<\/h2>\n<ul>\n<li><strong>Ex\u00e9cutez toujours le programme avec les privil\u00e8ges d&rsquo;administrateur.<\/strong><\/li>\n<li><strong>Utilisez le drapeau\u00a0<\/strong><strong>-EnableAndStartWindowsTimeService<\/strong><strong>\u00a0dans<\/strong>\u00a0les scripts non surveill\u00e9s ou les outils RMM.<\/li>\n<li><strong>Surveillez les param\u00e8tres de synchronisation<\/strong>\u00a0de mani\u00e8re proactive sur les terminaux distants et non-domaines.<\/li>\n<li>La <strong>sortie du journal<\/strong>\u00a0de ce script est enregistr\u00e9e dans des plates-formes de journalisation centralis\u00e9es \u00e0 des fins d&rsquo;audit.<\/li>\n<\/ul>\n<p>Pour une automatisation plus large, envisagez de l&rsquo;int\u00e9grer \u00e0 une logique de journalisation\/rapport et de la d\u00e9ployer par le biais de votre RMM de pr\u00e9dilection.<\/p>\n<h2>Conclusion<\/h2>\n<p>La synchronisation des horloges des syst\u00e8mes est fondamentale pour la stabilit\u00e9 et la s\u00e9curit\u00e9 informatiques. Ce script PowerShell offre un moyen clair, fiable et facile \u00e0 automatiser d&rsquo;appliquer la synchronisation de l&rsquo;heure dans les environnements, qu&rsquo;ils soient reli\u00e9s \u00e0 un domaine ou autonomes.<\/p>\n<p>Avec\u00a0<a href=\"https:\/\/www.ninjaone.com\/fr\/\"><strong>NinjaOne<\/strong><\/a> les professionnels de l&rsquo;informatique peuvent aller plus loin. En d\u00e9ployant des scripts de ce type via le moteur <a href=\"https:\/\/www.ninjaone.com\/fr\/blog\/tout-ce-que-vous-devez-savoir-sur-lautomatisation\/\">d&rsquo;automatisation<\/a> de NinjaOne, en surveillant les rapports de r\u00e9ussite\/d&rsquo;\u00e9chec et en rem\u00e9diant aux d\u00e9rives \u00e0 l&rsquo;\u00e9chelle, les MSP peuvent assurer la conformit\u00e9 de la synchronisation des temps sans avoir \u00e0 lever le petit doigt. Combin\u00e9e \u00e0 des champs personnalis\u00e9s et \u00e0 des alertes, la gestion du temps devient un atout \u00e0 ne pas n\u00e9gliger.<\/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-534746","script_hub","type-script_hub","status-publish","hentry","script_hub_category-windows"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/script_hub\/534746","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=534746"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/media?parent=534746"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/operating_system?post=534746"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/use_cases?post=534746"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}