{"id":353662,"date":"2024-08-27T10:06:47","date_gmt":"2024-08-27T10:06:47","guid":{"rendered":"https:\/\/www.ninjaone.com\/script-hub\/detecter-les-comptes-utilisateurs-inactifs-linux\/"},"modified":"2024-10-13T19:09:10","modified_gmt":"2024-10-13T19:09:10","slug":"detecter-les-comptes-utilisateurs-inactifs-linux","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/fr\/script-hub\/detecter-les-comptes-utilisateurs-inactifs-linux\/","title":{"rendered":"Comment d\u00e9tecter les comptes utilisateurs inactifs Linux : guide complet de script"},"content":{"rendered":"<p>La gestion efficace des comptes utilisateurs est un pilier de la s\u00e9curit\u00e9 informatique. Parmi les diff\u00e9rentes mesures visant \u00e0 maintenir un environnement s\u00e9curis\u00e9, la surveillance des comptes utilisateurs inactifs ou inutilis\u00e9s est essentielle. Les comptes utilisateurs inactifs peuvent constituer des points d&rsquo;entr\u00e9e potentiels pour des personnes malveillantes s&rsquo;ils ne sont pas contr\u00f4l\u00e9s. Pour y rem\u00e9dier, nous allons nous pencher sur un script Bash performant qui alerte les administrateurs lorsque des comptes utilisateurs restent inactifs pendant un nombre de jours d\u00e9termin\u00e9.<\/p>\n<h2>Contexte<\/h2>\n<p>Les comptes d&rsquo;utilisateurs inactifs pr\u00e9sentent des risques importants dans toute infrastructure informatique. Ils peuvent \u00eatre exploit\u00e9s pour obtenir un acc\u00e8s non autoris\u00e9, ce qui peut entra\u00eener des vols de donn\u00e9es. Les <a href=\"https:\/\/www.ninjaone.com\/fr\/quest-ce-quun-msp\" target=\"_blank\" rel=\"noopener\">fournisseurs de services g\u00e9r\u00e9s (MSP)<\/a> et les professionnels de l&rsquo;informatique ont besoin d&rsquo;outils efficaces pour suivre et g\u00e9rer ces comptes. Ce script constitue une excellente solution fournissant des alertes automatis\u00e9es pour les comptes inactifs sur les <a href=\"https:\/\/www.ninjaone.com\/blog\/linux-filesystems\/\" target=\"_blank\" rel=\"noopener\">syst\u00e8mes Linux<\/a>, am\u00e9liorant ainsi la posture de s\u00e9curit\u00e9 globale.<\/p>\n<h2>Le script\u00a0:<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">#!\/usr\/bin\/env bash\r\n#\r\n# Description: Alerts when there is an inactive\/unused account that has not logged in for the specified number of days.\r\n#\r\n# Preset Parameter: --daysInactive \"90\"\r\n#   Alert if account has been inactive for x days.\r\n#\r\n# Preset Parameter: --showDisabled\r\n#   Includes disabled accounts in alert and report.\r\n#\r\n# Preset Parameter: --multilineField \"ReplaceMeWithNameOfYourMultilineField\"\r\n#   Name of an optional multiline custom field to save the results to.\r\n#\r\n# Preset Parameter: --wysiwygField \"ReplaceMeWithNameOfYourWYSIWYGField\"\r\n#   Name of an optional WYSIWYG custom field to save the results to.\r\n#\r\n# Preset Parameter: --help\r\n#   Displays some help text.\r\n#\r\n# Release Notes: Initial Release\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\r\n# These are all our preset parameter defaults. You can set these = to something if you would prefer the script defaults to a certain parameter value.\r\n_arg_daysInactive=\r\n_arg_showDisabled=\"off\"\r\n_arg_multilineField=\r\n_arg_wysiwygField=\r\n\r\n# Help text function for when invalid input is encountered\r\nprint_help() {\r\n  printf '\\n\\n%s\\n\\n' 'Usage: --daysInactive|-d &lt;arg&gt; [--multilineField|-m &lt;arg&gt;] [--wysiwygField|-w &lt;arg&gt;] [--showDisabled] [--help|-h]'\r\n  printf '%s\\n' 'Preset Parameter: --daysInactive \"90\"'\r\n  printf '\\t%s\\n' \"Alert if account has been inactive for x days.\"\r\n  printf '%s\\n' 'Preset Parameter: --showDisabled'\r\n  printf '\\t%s\\n' \"Includes disabled accounts in alert and report.\"\r\n  printf '%s\\n' 'Preset Parameter: --multilineField \"ReplaceMeWithNameOfYourMultilineField\"'\r\n  printf '\\t%s\\n' \"Name of an optional multiline custom field to save the results to.\"\r\n  printf '%s\\n' 'Preset Parameter: --wysiwygField \"ReplaceMeWithNameOfYourWYSIWYGField\"'\r\n  printf '\\t%s\\n' \"Name of an optional WYSIWYG custom field to save the results to.\"\r\n  printf '\\n%s\\n' 'Preset Parameter: --help'\r\n  printf '\\t%s\\n' \"Displays this help menu.\"\r\n}\r\n\r\n# Determines whether or not help text is necessary and routes the output to stderr\r\ndie() {\r\n  local _ret=\"${2:-1}\"\r\n  echo \"$1\" &gt;&amp;2\r\n  test \"${_PRINT_HELP:-no}\" = yes &amp;&amp; print_help &gt;&amp;2\r\n  exit \"${_ret}\"\r\n}\r\n\r\n# Converts a string input into an HTML table format.\r\nconvertToHTMLTable() {\r\n  local _arg_delimiter=\" \"\r\n  local _arg_inputObject\r\n\r\n  # Process command-line arguments for the function.\r\n  while test $# -gt 0; do\r\n    _key=\"$1\"\r\n    case \"$_key\" in\r\n    --delimiter | -d)\r\n      test $# -lt 2 &amp;&amp; echo \"[Error] Missing value for the required argument\" &gt;&amp;2 &amp;&amp; return 1\r\n      _arg_delimiter=$2\r\n      shift\r\n      ;;\r\n    --*)\r\n      echo \"[Error] Got an unexpected argument\" &gt;&amp;2\r\n      return 1\r\n      ;;\r\n    *)\r\n      _arg_inputObject=$1\r\n      ;;\r\n    esac\r\n    shift\r\n  done\r\n\r\n  # Handles missing input by checking stdin or returning an error.\r\n  if [[ -z $_arg_inputObject ]]; then\r\n    if [ -p \/dev\/stdin ]; then\r\n      _arg_inputObject=$(cat)\r\n    else\r\n      echo \"[Error] Missing input object to convert to table\" &gt;&amp;2\r\n      return 1\r\n    fi\r\n  fi\r\n\r\n  local htmlTable=\"&lt;table&gt;\\n\"\r\n  htmlTable+=$(printf '%b' \"$_arg_inputObject\" | head -n1 | awk -F \"$_arg_delimiter\" '{\r\n    printf \"&lt;tr&gt;\"\r\n    for (i=1; i&lt;=NF; i+=1)\r\n      { printf \"&lt;th&gt;\"$i\"&lt;\/th&gt;\" }\r\n    printf \"&lt;\/tr&gt;\"\r\n    }')\r\n  htmlTable+=\"\\n\"\r\n  htmlTable+=$(printf '%b' \"$_arg_inputObject\" | tail -n +2 | awk -F \"$_arg_delimiter\" '{\r\n    printf \"&lt;tr&gt;\"\r\n    for (i=1; i&lt;=NF; i+=1)\r\n      { printf \"&lt;td&gt;\"$i\"&lt;\/td&gt;\" }\r\n    print \"&lt;\/tr&gt;\"\r\n    }')\r\n  htmlTable+=\"\\n&lt;\/table&gt;\"\r\n\r\n  printf '%b' \"$htmlTable\" '\\n'\r\n}\r\n\r\n# Parses command-line arguments and sets script variables accordingly.\r\nparse_commandline() {\r\n  while test $# -gt 0; do\r\n    _key=\"$1\"\r\n    case \"$_key\" in\r\n    --daysInactive | --daysinactive | --days | -d)\r\n      test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n      _arg_daysInactive=$2\r\n      shift\r\n      ;;\r\n    --daysInactive=*)\r\n      _arg_daysInactive=\"${_key##--daysInactive=}\"\r\n      ;;\r\n    --multilineField | --multilinefield | --multiline | -m)\r\n      test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n      _arg_multilineField=$2\r\n      shift\r\n      ;;\r\n    --multilineField=*)\r\n      _arg_multilineField=\"${_key##--multilineField=}\"\r\n      ;;\r\n    --wysiwygField | --wysiwygfield | --wysiwyg | -w)\r\n      test $# -lt 2 &amp;&amp; die \"Missing value for the optional argument '$_key'.\" 1\r\n      _arg_wysiwygField=$2\r\n      shift\r\n      ;;\r\n    --wysiwygField=*)\r\n      _arg_wysiwygField=\"${_key##--wysiwygField=}\"\r\n      ;;\r\n    --showDisabled | --showdisabled)\r\n      _arg_showDisabled=\"on\"\r\n      ;;\r\n    --help | -h)\r\n      _PRINT_HELP=yes die 0\r\n      ;;\r\n    *)\r\n      _PRINT_HELP=yes die \"FATAL ERROR: Got an unexpected argument '$1'\" 1\r\n      ;;\r\n    esac\r\n    shift\r\n  done\r\n}\r\n\r\n# Parses the command-line arguments passed to the script.\r\nparse_commandline \"$@\"\r\n\r\n# If dynamic script variables are used replace the commandline arguments with them.\r\nif [[ -n $daysInactive ]]; then\r\n  _arg_daysInactive=\"$daysInactive\"\r\nfi\r\n\r\nif [[ -n $includeDisabled &amp;&amp; $includeDisabled == \"true\" ]]; then\r\n  _arg_showDisabled=\"on\"\r\nfi\r\n\r\nif [[ -n $multilineCustomFieldName ]]; then\r\n  _arg_multilineField=\"$multilineCustomFieldName\"\r\nfi\r\n\r\nif [[ -n $wysiwygCustomFieldName ]]; then\r\n  _arg_wysiwygField=\"$wysiwygCustomFieldName\"\r\nfi\r\n\r\n# Check if _arg_daysInactive contains any non-digit characters or is less than zero.\r\n# If any of these conditions are true, display the help text and terminate with an error.\r\nif [[ -z $_arg_daysInactive || $_arg_daysInactive =~ [^0-9]+ || $_arg_daysInactive -lt 0 ]]; then\r\n  _PRINT_HELP=yes die \"FATAL ERROR: Days Inactive of '$_arg_daysInactive' is invalid! Days Inactive must be a positive number.\" 1\r\nfi\r\n\r\n# Check if both _arg_multilineField and _arg_wysiwygField are set and not empty.\r\nif [[ -n \"$_arg_multilineField\" &amp;&amp; -n \"$_arg_wysiwygField\" ]]; then\r\n  # Convert both field names to uppercase to check for equality.\r\n  multiline=$(echo \"$_arg_multilineField\" | tr '[:lower:]' '[:upper:]')\r\n  wysiwyg=$(echo \"$_arg_wysiwygField\" | tr '[:lower:]' '[:upper:]')\r\n\r\n  # If the converted names are the same, it means both fields cannot be identical.\r\n  # If they are, terminate the script with an error.\r\n  if [[ \"$multiline\" == \"$wysiwyg\" ]]; then\r\n    _PRINT_HELP=no die 'FATAL ERROR: Multline Field and WYSIWYG Field cannot be the same name. https:\/\/ninjarmm.zendesk.com\/hc\/en-us\/articles\/360060920631-Custom-Fields-Configuration-Device-Role-Fields'\r\n  fi\r\nfi\r\n\r\n# Retrieves the list of user accounts with UniqueIDs greater than 499 (typically these are all not service accounts) from the local user directory.\r\nuserAccounts=$(cut -d \":\" -f1,3 \/etc\/passwd | grep -v \"nobody\" | awk -F ':' '$2 &gt;= 1000 {print $1}')\r\n\r\n# Sets up a header string for the table that will display user account information.\r\nheader=$(printf '%s' \"Username\" ';' \"Password Last Set\" ';' \"Last Logon\" ';' \"Enabled\")\r\n\r\n# Initializes an empty string to store information about relevant user accounts.\r\nrelevantAccounts=\r\n\r\n# Iterates over each user account retrieved earlier.\r\nfor userAccount in $userAccounts; do\r\n  # Extracts the last login information for that user, filtering out unnecessary lines and formatting.\r\n  lastLogin=$(last -RF1 \"$userAccount\" | grep -v \"wtmp\" | grep \"\\S\" | tr -s \" \" | cut -f3-7 -d \" \")\r\n\r\n  # Converts the last login date to seconds since the epoch, for easier date comparison.\r\n  if [[ -n $lastLogin ]]; then\r\n    lastLogin=$(date -d \"$lastLogin\" +\"%s\")\r\n  fi\r\n\r\n  # Calculates the cutoff date in seconds since the epoch for inactivity comparison, based on the days inactive argument.\r\n  if [[ $_arg_daysInactive -gt 0 ]]; then\r\n    cutoffDate=$(date -d \"${_arg_daysInactive} days ago\" +\"%s\")\r\n  fi\r\n\r\n  # Retrieves the timestamp when the password was last set for the user account and converts it to a readable format.\r\n  passwordLastSet=$(passwd -S \"$userAccount\" | cut -f3 -d \" \")\r\n\r\n  # Checks if the user account is part of the group that defines disabled accounts, setting the 'enabled' variable accordingly.\r\n  unlockedaccount=$(passwd -S \"$userAccount\" | cut -f2 -d \" \" | grep -v \"L\")\r\n  nologin=$(grep \"$userAccount\" \/etc\/passwd | cut -d \":\" -f7 | grep \"nologin\")\r\n  if [[ -n $unlockedaccount &amp;&amp; -z $nologin ]]; then\r\n    enabled=\"true\"\r\n  else\r\n    enabled=\"false\"\r\n  fi\r\n\r\n  # Checks if the account is inactive based on the last login date and cutoff date or if the account should be included regardless of its active status.\r\n  if [[ $_arg_daysInactive == \"0\" || -z \"$lastLogin\" || $lastLogin -le $cutoffDate ]]; then\r\n    # Formats the last login date or sets it to \"Never\" if the user has never logged in.\r\n    if [[ -n $lastLogin ]]; then\r\n      lastLogin=$(date -d \"@$lastLogin\")\r\n    else\r\n      lastLogin=\"Never\"\r\n    fi\r\n\r\n    # Skips adding disabled accounts to the output if they should not be shown.\r\n    if [[ $_arg_showDisabled == \"off\" &amp;&amp; $enabled == \"false\" ]]; then\r\n      continue\r\n    fi\r\n\r\n    # Appends the account information to the 'relevantAccounts' string if it meets the criteria.\r\n    relevantAccounts+=$(printf '%s' '\\n' \"$userAccount\" ';' \"$passwordLastSet\" ';' \"$lastLogin\" ';' \"$enabled\")\r\n    foundInactiveAccounts=\"true\"\r\n  fi\r\ndone\r\n\r\n# Checks if there are any inactive accounts found.\r\nif [[ $foundInactiveAccounts == \"true\" ]]; then\r\n  # Formats a nice table for easier viewing\r\n  tableView=\"$header\"\r\n  tableView+=$(printf '%s' '\\n' \"--------\" ';' \"-----------------\" ';' \"----------\" ';' \"-------\")\r\n  tableView+=\"$relevantAccounts\"\r\n  tableView=$(printf '%b' \"$tableView\" | column -s ';' -t)\r\n\r\n  # Output to the activity log\r\n  echo \"\"\r\n  echo 'WARNING: Inactive accounts detected!'\r\n  echo \"\"\r\n  printf '%b' \"$tableView\"\r\n  echo \"\"\r\nelse\r\n  # If no inactive accounts were found, outputs a simple message.\r\n  echo \"No inactive accounts detected.\"\r\nfi\r\n\r\n# Checks if there is a multiline custom field set and if any inactive accounts have been found.\r\nif [[ -n $_arg_multilineField &amp;&amp; $foundInactiveAccounts == \"true\" ]]; then\r\n  echo \"\"\r\n  echo \"Attempting to set Custom Field '$_arg_multilineField'...\"\r\n\r\n  # Formats the relevantAccounts data for the multiline custom field.\r\n  multilineValue=$(printf '%b' \"$relevantAccounts\" | grep \"\\S\" | awk -F \";\" '{ \r\n      print \"Username: \"$1\r\n      print \"Password Last Set: \"$2\r\n      print \"Last Logon: \"$3\r\n      print \"Enabled: \"$4 \r\n      print \"\"\r\n  }')\r\n\r\n  # Tries to set the multiline custom field using ninjarmm-cli and captures the output.\r\n  if ! output=$(printf '%b' \"$multilineValue\" | \/opt\/NinjaRMMAgent\/programdata\/ninjarmm-cli set --stdin \"$_arg_multilineField\" 2&gt;&amp;1); then\r\n    echo \"[Error] $output\" &gt;&amp;2\r\n    EXITCODE=1\r\n  else\r\n    echo \"Successfully set Custom Field '$_arg_multilineField'!\"\r\n  fi\r\nfi\r\n\r\n# Checks if there is a WYSIWYG custom field set and if any inactive accounts have been found.\r\nif [[ -n $_arg_wysiwygField &amp;&amp; $foundInactiveAccounts == \"true\" ]]; then\r\n  echo \"\"\r\n  echo \"Attempting to set Custom Field '$_arg_wysiwygField'...\"\r\n\r\n  # Initializes an HTML formatted string with headers and account details.\r\n  htmlObject=\"$header\"\r\n  htmlObject+=\"$relevantAccounts\"\r\n\r\n  # Converts the text data to an HTML table format.\r\n  htmlObject=$(convertToHTMLTable --delimiter ';' \"$htmlObject\")\r\n\r\n  # Tries to set the WYSIWYG custom field using ninjarmm-cli and captures the output.\r\n  if ! output=$(echo \"$htmlObject\" | \/opt\/NinjaRMMAgent\/programdata\/ninjarmm-cli set --stdin \"$_arg_wysiwygField\" 2&gt;&amp;1); then\r\n    echo \"[Error] $output\" &gt;&amp;2\r\n    EXITCODE=1\r\n  else\r\n    echo \"Successfully set Custom Field '$_arg_wysiwygField'!\"\r\n  fi\r\nfi\r\n\r\n# Checks if an error code is set and exits the script with that code.\r\nif [[ -n $EXITCODE ]]; then\r\n  exit \"$EXITCODE\"\r\nfi<\/pre>\n<p>&nbsp;<\/p>\n\n<div class=\"blog-cta-new blog-cta-style-1\"><div class=\"cta-left\"><h2><\/h2><p><\/p><\/div><div class=\"cta-right\"><a class=\"button\" href=\"\"><\/a><\/div><\/div>\n<h2>Description d\u00e9taill\u00e9e<\/h2>\n<p>Voyons comment ce script fonctionne pour maintenir l&rsquo;hygi\u00e8ne des comptes d&rsquo;utilisateurs sur vos syst\u00e8mes Linux.<\/p>\n<h3>Param\u00e8tres pr\u00e9d\u00e9finis<\/h3>\n<p>Le script commence par d\u00e9finir des param\u00e8tres pr\u00e9d\u00e9finis :<\/p>\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\">&#8211;daysInactive : Nombre de jours pendant lesquels un compte doit \u00eatre inactif pour d\u00e9clencher une alerte.<\/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\">&#8211;showDisabled : Indique s&rsquo;il faut inclure les comptes d\u00e9sactiv\u00e9s dans le rapport.<\/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\">&#8211;multilineField : Le nom d&rsquo;un champ personnalis\u00e9 multiligne pour enregistrer les r\u00e9sultats.<\/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\">&#8211;wysiwygField : Le nom d&rsquo;un champ personnalis\u00e9 WYSIWYG pour enregistrer les r\u00e9sultats.<\/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\">&#8211;help : Affiche le texte d&rsquo;aide.<\/li>\n<\/ul>\n<h3>Analyse des arguments de la ligne de commande<\/h3>\n<p>Le script utilise une fonction pour analyser les arguments de la ligne de commande et d\u00e9finir les variables du script en cons\u00e9quence. Si des arguments incorrects sont fournis, le script affiche un message d&rsquo;aide et se termine.<\/p>\n<h3>D\u00e9tection des comptes inactifs<\/h3>\n<p>La fonctionnalit\u00e9 principale consiste \u00e0 d\u00e9tecter les comptes d&rsquo;utilisateurs inactifs. Il r\u00e9cup\u00e8re une liste de comptes d&rsquo;utilisateurs dont l&rsquo;identifiant unique (UniqueID) est sup\u00e9rieur \u00e0 499 (g\u00e9n\u00e9ralement des comptes de non-service) dans le r\u00e9pertoire local des utilisateurs. Il v\u00e9rifie ensuite la date de derni\u00e8re connexion de chaque compte et la compare \u00e0 la date du jour moins le param\u00e8tre &#8211;daysInactive. Les comptes r\u00e9pondant aux crit\u00e8res d&rsquo;inactivit\u00e9 sont signal\u00e9s.<\/p>\n<h3>G\u00e9n\u00e9ration de rapports<\/h3>\n<p>Si des comptes inactifs sont d\u00e9tect\u00e9s, le script g\u00e9n\u00e8re un tableau qui les affiche :<\/p>\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\">Nom d&rsquo;utilisateur<\/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=\"7\" data-aria-level=\"1\">Dernier mot de passe d\u00e9fini<\/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\">Derni\u00e8re connexion<\/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\">\u00c9tat activ\u00e9<\/li>\n<\/ul>\n<h3>Int\u00e9gration de champs personnalis\u00e9s<\/h3>\n<p>Le script peut enregistrer les r\u00e9sultats dans les champs personnalis\u00e9s sp\u00e9cifi\u00e9s. Il formate les donn\u00e9es en texte brut ou en HTML, selon qu&rsquo;elles sont enregistr\u00e9es dans un champ multiligne ou WYSIWYG.<\/p>\n<h2>Cas d&rsquo;utilisation potentiels<\/h2>\n<p>Prenons l&rsquo;exemple d&rsquo;un administrateur informatique qui g\u00e8re les serveurs Linux d&rsquo;une entreprise. Des audits r\u00e9guliers des comptes d&rsquo;utilisateurs font partie du protocole de s\u00e9curit\u00e9. L&rsquo;administrateur planifie l&rsquo;ex\u00e9cution hebdomadaire de ce script. Une semaine, le script d\u00e9tecte plusieurs comptes inactifs qui ne se sont pas connect\u00e9s depuis plus de 90 jours. Apr\u00e8s avoir examin\u00e9 le rapport, l&rsquo;administrateur d\u00e9cide de d\u00e9sactiver ces comptes jusqu&rsquo;\u00e0 ce qu&rsquo;une nouvelle v\u00e9rification soit effectu\u00e9e, ce qui permet d&rsquo;att\u00e9nuer les risques potentiels pour la s\u00e9curit\u00e9.<\/p>\n<h2>Comparaisons<\/h2>\n<p>D&rsquo;autres m\u00e9thodes permettant d&rsquo;obtenir des r\u00e9sultats similaires peuvent inclure l&rsquo;audit manuel ou l&rsquo;utilisation d&rsquo;outils de gestion des utilisateurs plus complexes. L&rsquo;audit manuel prend du temps et est sujet \u00e0 des erreurs humaines. Les outils avanc\u00e9s peuvent \u00eatre co\u00fbteux et n\u00e9cessiter une installation et une configuration approfondies. Ce texte offre une solution simple et rentable, ce qui en fait une excellente solution interm\u00e9diaire.<\/p>\n<h2>FAQ<\/h2>\n<ol>\n<li><strong> Que se passe-t-il si je veux v\u00e9rifier l&rsquo;inactivit\u00e9 pendant un nombre de jours diff\u00e9rent ?<\/strong> Ajustez le param\u00e8tre &#8211;daysInactive en cons\u00e9quence. Par exemple, utilisez &#8211;daysInactive 60 pour v\u00e9rifier 60 jours d&rsquo;inactivit\u00e9.<\/li>\n<li><strong> Puis-je exclure les comptes d\u00e9sactiv\u00e9s du rapport ?<\/strong> Oui, le script comprend le param\u00e8tre &#8211;showDisabled qui permet d&rsquo;inclure les comptes d\u00e9sactiv\u00e9s.<\/li>\n<li><strong> Comment enregistrer les r\u00e9sultats dans un champ personnalis\u00e9 ?<\/strong> Sp\u00e9cifiez les noms des champs personnalis\u00e9s \u00e0 l&rsquo;aide des param\u00e8tres &#8211;multilineField ou &#8211;wysiwygField.<\/li>\n<li><strong> Que se passe-t-il si je fournis des param\u00e8tres incorrects ?<\/strong> Le script affichera un message d&rsquo;aide et se terminera, assurant ainsi que vous fournissez les donn\u00e9es correctes.<\/li>\n<\/ol>\n<h2>Implications<\/h2>\n<p>Le contr\u00f4le r\u00e9gulier des comptes inactifs a de profondes r\u00e9percussions sur la s\u00e9curit\u00e9 informatique. Il permet d&#8217;emp\u00eacher les acc\u00e8s non autoris\u00e9s, de r\u00e9duire la surface d&rsquo;attaque et de garantir la conformit\u00e9 avec les politiques de s\u00e9curit\u00e9. En utilisant ce script, les administrateurs peuvent automatiser un aspect crucial de la gestion des comptes d&rsquo;utilisateurs, am\u00e9liorant ainsi la s\u00e9curit\u00e9 et l&rsquo;efficacit\u00e9 globales.<\/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=\"10\" data-aria-level=\"1\">Planifiez l&rsquo;ex\u00e9cution du script \u00e0 intervalles r\u00e9guliers, par exemple une fois par semaine ou par mois.<\/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=\"11\" data-aria-level=\"1\">Examinez rapidement le rapport sur les comptes inactifs et prennez les mesures qui s&rsquo;imposent.<\/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=\"12\" data-aria-level=\"1\">Utilisez la fonction de champs personnalis\u00e9s pour int\u00e9grer les r\u00e9sultats \u00e0 vos outils de gestion informatique existants.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>La gestion <a href=\"https:\/\/www.ninjaone.com\/fr\/efficacite\" target=\"_blank\" rel=\"noopener\">efficace<\/a> des comptes d&rsquo;utilisateurs inactifs est essentielle au maintien de la s\u00e9curit\u00e9 informatique. Ce script fournit une solution pratique et automatis\u00e9e, permettant aux administrateurs de garder une longueur d&rsquo;avance sur les menaces de s\u00e9curit\u00e9 potentielles. En int\u00e9grant cet outil dans vos protocoles de s\u00e9curit\u00e9, vous pouvez garantir un environnement informatique plus s\u00fbr et plus conforme.<\/p>\n<p><a href=\"https:\/\/www.ninjaone.com\/fr\/\" target=\"_blank\" rel=\"noopener\">NinjaOne<\/a> propose des solutions compl\u00e8tes de gestion informatique qui s&rsquo;int\u00e8grent de mani\u00e8re optimale \u00e0 des scripts de ce type, offrant une fonctionnalit\u00e9 am\u00e9lior\u00e9e et une gestion centralis\u00e9e de votre infrastructure informatique. Adoptez l&rsquo;automatisation et des pratiques de s\u00e9curit\u00e9 de pointe avec NinjaOne pour prot\u00e9ger efficacement votre entreprise.<\/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":[4211],"use_cases":[4289],"class_list":["post-353662","script_hub","type-script_hub","status-publish","hentry","script_hub_category-linux","use_cases-gestion-des-utilisateurs-et-des-acces"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/script_hub\/353662","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=353662"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/media?parent=353662"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/operating_system?post=353662"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/fr\/wp-json\/wp\/v2\/use_cases?post=353662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}