{"id":353659,"date":"2024-08-27T10:00:12","date_gmt":"2024-08-27T10:00:12","guid":{"rendered":"https:\/\/www.ninjaone.com\/script-hub\/verification-du-hachage-des-fichiers-powershell\/"},"modified":"2024-10-13T19:08:45","modified_gmt":"2024-10-13T19:08:45","slug":"verification-du-hachage-des-fichiers-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/fr\/script-hub\/verification-du-hachage-des-fichiers-powershell\/","title":{"rendered":"Comment utiliser PowerShell pour la v\u00e9rification du hachage des fichiers pour la s\u00e9curit\u00e9 informatique ?"},"content":{"rendered":"<p>Dans le monde informatique actuel, il est primordial de garantir l&rsquo;int\u00e9grit\u00e9 et la s\u00e9curit\u00e9 des donn\u00e9es. Une m\u00e9thode efficace pour v\u00e9rifier l&rsquo;int\u00e9grit\u00e9 des fichiers consiste \u00e0 utiliser des valeurs de hachage. Une valeur de hachage agit comme une empreinte digitale num\u00e9rique des fichiers, permettant aux professionnels de l&rsquo;informatique de v\u00e9rifier si les fichiers ont \u00e9t\u00e9 alt\u00e9r\u00e9s ou corrompus. Cet article se penche sur un script PowerShell con\u00e7u pour rechercher des fichiers avec des valeurs de hachage sp\u00e9cifiques, ce qui en fait un outil pr\u00e9cieux pour les professionnels de l&rsquo;informatique et les <a href=\"https:\/\/www.ninjaone.com\/fr\/quest-ce-quun-msp\" target=\"_blank\" rel=\"noopener\">fournisseurs de services g\u00e9r\u00e9s (MSP)<\/a>.<\/p>\n<h2>Contexte<\/h2>\n<p>Le script PowerShell fourni est con\u00e7u pour alerter les utilisateurs si un fichier avec un hachage et une extension sp\u00e9cifi\u00e9s est trouv\u00e9 dans un r\u00e9pertoire donn\u00e9 et ses sous-r\u00e9pertoires. Le hachage des fichiers est une pratique courante en informatique pour v\u00e9rifier l&rsquo;int\u00e9grit\u00e9 des fichiers et d\u00e9tecter les modifications non autoris\u00e9es. Ce script simplifie et automatise le processus, ce qui permet aux professionnels de l&rsquo;informatique de garantir plus facilement la s\u00e9curit\u00e9 et l&rsquo;int\u00e9grit\u00e9 de leurs syst\u00e8mes.<\/p>\n<h2>Le script<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">#Requires -Version 5.1\r\n\r\n&lt;#\r\n.SYNOPSIS\r\n    Alerts if a file with the extension and specified hash is found in the given search directory or subdirectories. Warning: Hashing large files may impact performance.\r\n.DESCRIPTION\r\n    Alerts if a file with the extension and specified hash is found in the given search directory or subdirectories. Warning: Hashing large files may impact performance.\r\n.EXAMPLE\r\n    -Hash \"F55A61A82F4F5943F86565E1FA2CCB4F\" -SearchPath \"C:\" -FileType \".ico\" -CustomField \"multiline\"\r\n    WARNING: Backslash missing from the search path. Changing it to C:\\.\r\n    WARNING: File with MD5 hash of F55A61A82F4F5943F86565E1FA2CCB4F found!\r\n\r\n    File Name         Path                                                                                    \r\n    ---------         ----                                                                                    \r\n    zoo_ecosystem.ico C:\\Users\\Administrator\\Desktop\\Find-FileHash\\Test Folder 1\\zoo_ecosystem.ico            \r\n    zoo_ecosystem.ico C:\\Users\\Administrator\\Desktop\\Find-FileHash\\TestFolder1\\Test Folder 1\\zoo_ecosystem.ico\r\n    zoo_ecosystem.ico C:\\Users\\Administrator\\Desktop\\Find-FileHash\\TestFolder2\\Test Folder 1\\zoo_ecosystem.ico\r\n\r\n    Attempting to set Custom Field 'multiline'.\r\n    Successfully set Custom Field 'multiline'!\r\n\r\nPARAMETER: -Hash \"REPLACEMEWITHAVALIDHASH\"\r\n    Files with this hash should cause the alert to trigger.\r\n\r\nPARAMETER: -Algorithm \"MD5\"\r\n    Hashing algorithm used for the above hash.\r\n\r\nPARAMETER: -SearchPath \"C:\\ReplaceMeWithAValidSearchPath\"\r\n   Specifies one or more starting directories for the search, separated by commas. The search will recursively include all subdirectories from these starting points.\r\n\r\nPARAMETER: -Timeout \"15\"\r\n    Once this timeout is reached, the script will stop searching for files that match your given hash.\r\n\r\nPARAMETER: -FileType \".exe\"\r\n    Specifies the file extension to filter the search. Only files with this extension will be analyzed for a hash match. Example: '.exe'\r\n\r\nPARAMETER: -CustomField \"NameOfMultiLineCustomField\"\r\n    Specifies the name of an optional multiline custom field where results can be sent. \r\n\r\n.NOTES\r\n    Minimum OS Architecture Supported: Windows 10, Windows Server 2016\r\n    Release 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\r\n[CmdletBinding()]\r\nparam (\r\n    [Parameter()]\r\n    [String]$Hash,\r\n    [Parameter()]\r\n    [String]$SearchPath = \"C:\\Windows\",\r\n    [Parameter()]\r\n    [String]$FileType,\r\n    [Parameter()]\r\n    [Int]$Timeout = 15,\r\n    [Parameter()]\r\n    [String]$Algorithm = \"MD5\",\r\n    [Parameter()]\r\n    [String]$CustomField\r\n)\r\n\r\nbegin {\r\n    # Set parameters using dynamic script variables.\r\n    if ($env:hash -and $env:hash -notlike \"null\") { $Hash = $env:hash }\r\n    if ($env:hashType -and $env:hashType -notlike \"null\") { $Algorithm = $env:hashType }\r\n    if ($env:searchPath -and $env:searchPath -notlike \"null\") { $SearchPath = $env:searchPath }\r\n    if ($env:timeoutInMinutes -and $env:timeoutInMinutes -notlike \"null\") { $Timeout = $env:timeoutInMinutes }\r\n    if ($env:fileExtensionToSearchFor -and $env:fileExtensionToSearchFor -notlike \"null\") { $FileType = $env:fileExtensionToSearchFor }\r\n    if ($env:customFieldName -and $env:customFieldName -notlike \"null\") { $CustomField = $env:customFieldName }\r\n\r\n    # If given a comma-separated list, split the paths.\r\n    $PathsToSearch = New-Object System.Collections.Generic.List[String]\r\n    if ($SearchPath -match \",\") {\r\n        $SearchPath -split \",\" | ForEach-Object { $PathsToSearch.Add($_.Trim()) }\r\n    }\r\n    else {\r\n        $PathsToSearch.Add($SearchPath)\r\n    }\r\n\r\n    $ReplacementPaths = New-Object System.Collections.Generic.List[Object]\r\n    $PathsToRemove = New-Object System.Collections.Generic.List[String]\r\n\r\n    # If given a drive without the backslash add it in.\r\n    $PathsToSearch | ForEach-Object {\r\n        if ($_ -notmatch '^[A-Z]:\\\\$' -and $_ -match '^[A-Z]:$') {\r\n            $NewPath = \"$_\\\"\r\n            $ReplacementPaths.Add(\r\n                [PSCustomObject]@{\r\n                    Index   = $PathsToSearch.IndexOf(\"$_\")\r\n                    NewPath = $NewPath\r\n                }\r\n            )\r\n                \r\n            Write-Warning \"Backslash missing from the search path. Changing it to $NewPath.\"\r\n        }\r\n    }\r\n\r\n    # Apply replacements\r\n    $ReplacementPaths | ForEach-Object {\r\n        $PathsToSearch[$_.index] = $_.NewPath \r\n    }\r\n\r\n    # Check if the search path is valid.\r\n    $PathsToSearch | ForEach-Object {\r\n        if (-not (Test-Path $_)) {\r\n            Write-Host -Object \"[Error] $_ does not exist!\"\r\n            $PathsToRemove.Add($_)\r\n            $ExitCode = 1\r\n        }\r\n    }\r\n\r\n    $PathsToRemove | ForEach-Object {\r\n        $PathsToSearch.Remove($_) | Out-Null\r\n    }\r\n\r\n\r\n    # Error out if no valid paths to search.\r\n    if ($PathsToSearch.Count -eq 0) {\r\n        Write-Host \"[Error] No valid paths to search!\"\r\n        exit 1\r\n    }\r\n\r\n    # A file extension is required.\r\n    if (-not $FileType) {\r\n        Write-Host -Object \"[Error] File Type is required!\"\r\n        exit 1\r\n    }\r\n\r\n    # If we were given the extension without the . we'll add it back in\r\n    if ($FileType -notmatch '^\\.') {\r\n        $FileType = \".$FileType\"\r\n        Write-Warning -Message \"Extension missing changing filetype to $FileType.\"\r\n    }\r\n\r\n    # The timeout has to be between 1 and 120\r\n    if ($Timeout -lt 1 -or $Timeout -gt 120) {\r\n        Write-Host \"[Error] Invalid timeout given of $Timeout minutes. Please enter a value between 1 and 120.\"\r\n        exit 1\r\n    }\r\n\r\n    # PowerShell 5.1 supports more algorithms than this, however PowerShell 7 does not.\r\n    $ValidAlgorithms = \"SHA1\", \"SHA256\", \"SHA384\", \"SHA512\", \"MD5\"\r\n    if ($ValidAlgorithms -notcontains $Algorithm) {\r\n        Write-Host \"[Error] Invalid Algorithm selected. Only SHA1, SHA256, SHA384, SHA512 and MD5 are supported.\"\r\n        exit 1\r\n    }\r\n\r\n    # Helper function to make it easier to set custom fields.\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 type's 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  Date-Time to be in Unix Epoch time so we'll convert it here.\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\r\n    # Test for local administrator rights\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    $ExitCode = 0\r\n}\r\nprocess {\r\n    if (-not (Test-IsElevated)) {\r\n        Write-Host -Object \"[Error] Access Denied. Please run with Administrator privileges.\"\r\n        exit 1\r\n    }\r\n\r\n    # If we're given a file instead of a folder, we'll check if it matches anyways.\r\n    $PathsToSearch | ForEach-Object {\r\n        if (-not (Get-Item $_).PSIsContainer) {\r\n            Write-Warning \"The search path you gave is actually a file not a folder. Checking the hash of the file...\"\r\n        }\r\n    }\r\n    \r\n    $HashJobs = New-Object System.Collections.Generic.List[object]\r\n    $MatchingFiles = New-Object System.Collections.Generic.List[object]\r\n    $CustomFieldValue = New-Object System.Collections.Generic.List[string]\r\n\r\n    # We'll use a PowerShell job so that we can timeout appropriately.\r\n    $PathsToSearch | ForEach-Object {\r\n        $HashJobs.Add(\r\n            (\r\n                Start-Job -ScriptBlock {\r\n                    param($SearchPath, $FileType, $Algorithm, $Hash)\r\n                    $Files = Get-ChildItem -Path $SearchPath -Filter \"*$FileType\" -File -Recurse\r\n                    $Files | ForEach-Object {\r\n                        $CurrentHash = Get-FileHash -Path $_.FullName -Algorithm $Algorithm\r\n                        if ($CurrentHash.Hash -match $Hash) { $_.FullName }\r\n                    }\r\n                } -ArgumentList $_, $FileType, $Algorithm, $Hash\r\n            )\r\n        )\r\n    }\r\n\r\n    $TimeoutInSeconds = $Timeout * 60\r\n    $StartTime = Get-Date\r\n\r\n    # Wait for all jobs to complete or timeout\r\n    foreach ($HashJob in $HashJobs) {\r\n        # Calculate the remaining time\r\n        $TimeElapsed = (Get-Date) - $StartTime\r\n        $RemainingTime = $TimeoutInSeconds - $TimeElapsed.TotalSeconds\r\n    \r\n        # If there is no remaining time, break the loop\r\n        if ($RemainingTime -le 0) {\r\n            break\r\n        }\r\n    \r\n        # Wait for the current job with the remaining time as the timeout\r\n        $HashJob | Wait-Job -Timeout $RemainingTime | Out-Null\r\n    }\r\n\r\n    # If we failed to complete the job, we'll output a warning.\r\n    $IncompleteJobs = $HashJobs | Get-Job | Where-Object { $_.State -eq \"Running\" }\r\n    if ($IncompleteJobs) {\r\n        Write-Host \"[Error] The timeout period of $Timeout minutes has been reached, but some files still require a hash check!\"\r\n        $CustomFieldValue.Add(\"[Error] The timeout period of $Timeout minutes has been reached, but some files still require a hash check!\")\r\n        $ExitCode = 1\r\n    }\r\n\r\n    # Receive the data from the job.\r\n    $HashJobs | Receive-Job -ErrorAction SilentlyContinue -ErrorVariable JobErrors | ForEach-Object {\r\n        $MatchingFiles.Add(\r\n            [PSCustomObject]@{\r\n                \"File Name\" = $(Split-Path $_ -Leaf)\r\n                Path        = $_\r\n            }\r\n        )\r\n    }\r\n\r\n    # If we have any matching files, we'll output them here.\r\n    if ($MatchingFiles) {\r\n        Write-Warning -Message \"File with $Algorithm hash of $Hash found!\"\r\n        $MatchingFiles | Format-Table -AutoSize | Out-String | Write-Host\r\n        $MatchingFiles | Select-Object -ExpandProperty Path | ForEach-Object { $CustomFieldValue.Add($_) }\r\n    }\r\n    else {\r\n        Write-Host -Object \"No files found with $Hash.\"\r\n    }\r\n\r\n    # If we received any failures or errors, we'll output that here.\r\n    $FailedJobs = $HashJobs | Get-Job | Where-Object { $_.State -ne \"Completed\" -and $_.State -ne \"Running\" }\r\n    if ($FailedJobs -or $JobErrors) {\r\n        Write-Host \"\"\r\n        Write-Host \"[Error] Failed to get the hash of certain files due to an error.\"\r\n        $CustomFieldValue.Add(\" \")\r\n        $CustomFieldValue.Add(\"[Error] Failed to get the hash of certain files due to an error.\")\r\n        if ($JobErrors) {\r\n            Write-Host \"\"\r\n            $JobErrors | ForEach-Object { Write-Host \"[Error] $($_.Exception.Message)\" }\r\n            $CustomFieldValue.Add(\" \")\r\n            $JobErrors | ForEach-Object { $CustomFieldValue.Add(\"[Error] $($_.Exception.Message)\") }\r\n        }\r\n        $ExitCode = 1\r\n    }\r\n\r\n    $HashJobs | Remove-Job -Force\r\n\r\n    # If we're given a custom field, we'll attempt to save the results to it.\r\n    if ($CustomField) {\r\n        try {\r\n            Write-Host \"Attempting to set Custom Field '$CustomField'.\"\r\n            Set-NinjaProperty -Name $CustomField -Value ($CustomFieldValue | Out-String)\r\n            Write-Host \"Successfully set Custom Field '$CustomField'!\"\r\n        }\r\n        catch {\r\n            if (-not $_.Exception.Message) {\r\n                Write-Host \"[Error] $($_.Message)\"\r\n            }\r\n            else {\r\n                Write-Host \"[Error] $($_.Exception.Message)\"\r\n            }\r\n            $ExitCode = 1\r\n        }\r\n        \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<div class=\"in-context-cta\"><\/div>\n<h2>Description d\u00e9taill\u00e9e<\/h2>\n<p>Le script commence par des informations sur les m\u00e9tadonn\u00e9es, notamment un synopsis, une description et un exemple d&rsquo;utilisation. Il d\u00e9finit les param\u00e8tres que l&rsquo;utilisateur peut sp\u00e9cifier, tels que la valeur de hachage, le chemin de recherche, le type de fichier, l&rsquo;algorithme de hachage, le d\u00e9lai d&rsquo;attente et un champ personnalis\u00e9 facultatif pour les r\u00e9sultats de sortie.<\/p>\n<h3>Configuration des param\u00e8tres<\/h3>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&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>Hash<\/strong>: La valeur de hachage sp\u00e9cifique \u00e0 rechercher.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&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>SearchPath<\/strong>: Le r\u00e9pertoire de d\u00e9part de la recherche, par d\u00e9faut C:NWindows.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&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>FileType<\/strong>: L&rsquo;extension de fichier \u00e0 filtrer.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&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>Timeout<\/strong>: Dur\u00e9e maximale de la recherche, fix\u00e9e par d\u00e9faut \u00e0 15 minutes.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&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>Algorithm<\/strong>: L&rsquo;algorithme de hachage, par d\u00e9faut MD5.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&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>CustomField<\/strong>: Un champ facultatif pour stocker les r\u00e9sultats.<\/li>\n<\/ul>\n<p>Le script ajuste dynamiquement ces param\u00e8tres en fonction des variables environnementales, si elles sont d\u00e9finies.<\/p>\n<h3>Validation du chemin d&rsquo;acc\u00e8s et du type de fichier<\/h3>\n<p>Le script valide les chemins de recherche, en s&rsquo;assurant qu&rsquo;ils existent et qu&rsquo;ils sont correctement format\u00e9s. Il ajoute une barre oblique inverse aux lettres de lecteur si elles sont manquantes et v\u00e9rifie si le chemin d&rsquo;acc\u00e8s fourni est un fichier au lieu d&rsquo;un dossier, en \u00e9mettant des avertissements et en proc\u00e9dant \u00e0 des ajustements en cons\u00e9quence.<\/p>\n<h3>Gestion des t\u00e2ches pour le calcul du hachage<\/h3>\n<p>Pour g\u00e9rer les calculs de hachage potentiellement longs, le script utilise des t\u00e2ches PowerShell. Il lance une t\u00e2che pour chaque chemin de recherche, en recherchant de mani\u00e8re r\u00e9cursive les fichiers portant l&rsquo;extension sp\u00e9cifi\u00e9e et en calculant leur valeur de hachage. Les r\u00e9sultats sont collect\u00e9s et compar\u00e9s \u00e0 la valeur de hachage fournie.<\/p>\n<h3>D\u00e9lai d&rsquo;attente et gestion des erreurs<\/h3>\n<p>Le script comprend un m\u00e9canisme de temporisation qui permet d&rsquo;arr\u00eater la recherche au bout d&rsquo;une p\u00e9riode donn\u00e9e, l&#8217;emp\u00eachant ainsi de fonctionner ind\u00e9finiment. Il collecte toutes les erreurs rencontr\u00e9es pendant l&rsquo;ex\u00e9cution du travail et fournit des messages d&rsquo;erreur d\u00e9taill\u00e9s \u00e0 l&rsquo;utilisateur.<\/p>\n<h3>Int\u00e9gration de champs personnalis\u00e9s<\/h3>\n<p>Si un champ personnalis\u00e9 est sp\u00e9cifi\u00e9, le script tente d&rsquo;y enregistrer les r\u00e9sultats \u00e0 l&rsquo;aide de la fonction Set-NinjaProperty, qui g\u00e8re diff\u00e9rents types de champs personnalis\u00e9s et veille \u00e0 ce que les donn\u00e9es soient correctement format\u00e9es et respectent les limites de caract\u00e8res.<\/p>\n<h3>R\u00e9sultat final<\/h3>\n<p>Le script affiche les fichiers correspondants, les \u00e9ventuelles erreurs rencontr\u00e9es et tente de d\u00e9finir le champ personnalis\u00e9 en fonction des r\u00e9sultats. Il se termine par un code d&rsquo;\u00e9tat appropri\u00e9 en fonction de la r\u00e9ussite ou de l&rsquo;\u00e9chec des op\u00e9rations.<\/p>\n<h2>Cas d&rsquo;utilisation potentiels<\/h2>\n<p>Imaginez un professionnel de l&rsquo;informatique charg\u00e9 de maintenir l&rsquo;int\u00e9grit\u00e9 des fichiers de distribution de logiciels sur un r\u00e9seau. Ce script lui permet d&rsquo;analyser r\u00e9guli\u00e8rement les r\u00e9pertoires dans lesquels sont stock\u00e9s les logiciels, afin de s&rsquo;assurer qu&rsquo;aucune modification non autoris\u00e9e n&rsquo;y a \u00e9t\u00e9 apport\u00e9e. Par exemple, si le hachage d&rsquo;un fichier .exe critique change, cela peut indiquer une alt\u00e9ration ou une corruption, ce qui n\u00e9cessite une investigation imm\u00e9diate.<\/p>\n<h2>Comparaisons<\/h2>\n<p>Les m\u00e9thodes traditionnelles pour v\u00e9rifier l&rsquo;int\u00e9grit\u00e9 des fichiers impliquent souvent des contr\u00f4les manuels de hachage \u00e0 l&rsquo;aide d&rsquo;outils tels que certutil sur Windows. Ce script automatise et optimise le processus, offrant ainsi une solution plus efficace et plus compl\u00e8te. Il s&rsquo;int\u00e8gre \u00e9galement en toute simplicit\u00e9 \u00e0 d&rsquo;autres scripts et outils utilis\u00e9s par les professionnels de l&rsquo;informatique, ce qui renforce son utilit\u00e9 dans divers sc\u00e9narios.<\/p>\n<h2>FAQ<\/h2>\n<p><strong>Comment puis-je sp\u00e9cifier plusieurs r\u00e9pertoires pour la recherche ?<\/strong><br \/>\nUtilisez une liste s\u00e9par\u00e9e par des virgules dans le param\u00e8tre -SearchPath.<\/p>\n<p><strong>Quels sont les algorithmes de hachage pris en charge ?<\/strong><br \/>\nLe script prend en charge MD5, SHA1, SHA256, SHA384 et SHA512.<\/p>\n<p><strong>Puis-je augmenter le d\u00e9lai d&rsquo;attente au-del\u00e0 de 120 minutes ?<\/strong><br \/>\nNon, le d\u00e9lai maximum autoris\u00e9 est de 120 minutes pour des raisons de performance et de praticit\u00e9.<\/p>\n<h2>Implications<\/h2>\n<p>L&rsquo;utilisation de ce script aide les professionnels de l&rsquo;informatique \u00e0 garantir l&rsquo;int\u00e9grit\u00e9 des fichiers cruciaux, r\u00e9duisant ainsi le risque de failles de s\u00e9curit\u00e9 caus\u00e9es par des fichiers alt\u00e9r\u00e9s ou corrompus. En automatisant le processus de v\u00e9rification du hachage, il permet de gagner du temps et fournit une m\u00e9thode fiable pour maintenir l&rsquo;int\u00e9grit\u00e9 des donn\u00e9es sur de grands r\u00e9seaux.<\/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;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\">Mettez \u00e0 jour et entretenez r\u00e9guli\u00e8rement le script pour l&rsquo;adapter aux nouveaux algorithmes de hachage et aux nouveaux types de fichiers.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&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\">Planifiez l&rsquo;ex\u00e9cution du script \u00e0 intervalles r\u00e9guliers afin de contr\u00f4ler en permanence l&rsquo;int\u00e9grit\u00e9 des fichiers.<\/li>\n<\/ul>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&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=\"9\" data-aria-level=\"1\">Utilisez la fonction de champ personnalis\u00e9 pour enregistrer les r\u00e9sultats dans un endroit central afin d&rsquo;en faciliter l&rsquo;acc\u00e8s et la r\u00e9vision.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>L&rsquo;int\u00e9gration de scripts PowerShell comme celui-ci dans votre bo\u00eete \u00e0 outils informatique am\u00e9liore votre capacit\u00e9 \u00e0 <a href=\"https:\/\/www.ninjaone.com\/fr\/blog\/decouvrez-si-la-securite-de-vos-equipes-mobiles-est-insuffisante-et-remediez-y\/\" target=\"_blank\" rel=\"noopener\">maintenir l&rsquo;int\u00e9grit\u00e9 et la s\u00e9curit\u00e9 des donn\u00e9es<\/a>. Des outils tels que <a href=\"https:\/\/www.ninjaone.com\/fr\/\" target=\"_blank\" rel=\"noopener\">NinjaOne<\/a> peuvent am\u00e9liorer davantage ces processus, en offrant des fonctionnalit\u00e9s avanc\u00e9es et des int\u00e9grations qui rendent la gestion des syst\u00e8mes informatiques plus efficace. En tirant parti de ces technologies, les professionnels de l&rsquo;informatique peuvent mieux prot\u00e9ger leurs environnements et garantir la fiabilit\u00e9 de leurs donn\u00e9es.<\/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":"","_lmt_disable":""},"operating_system":[4212],"use_cases":[4281,4284],"class_list":["post-353659","script_hub","type-script_hub","status-publish","hentry","script_hub_category-windows","use_cases-configuration-generale","use_cases-maintenance-fr"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/script_hub\/353659","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=353659"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/media?parent=353659"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/operating_system?post=353659"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/use_cases?post=353659"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}