{"id":208106,"date":"2023-09-20T11:56:20","date_gmt":"2023-09-20T11:56:20","guid":{"rendered":"https:\/\/www.ninjaone.com\/script-hub\/account-locali-inutilizzati-su-windows-powershell\/"},"modified":"2024-03-04T18:12:13","modified_gmt":"2024-03-04T18:12:13","slug":"account-locali-inutilizzati-su-windows-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/it\/script-hub\/account-locali-inutilizzati-su-windows-powershell\/","title":{"rendered":"Identificare e gestire gli account locali inutilizzati sui sistemi Windows"},"content":{"rendered":"<p><span data-contrast=\"none\">Se sei un professionista IT o un Managed Service Provider (MSP), il concetto di account locali inutilizzati ti dovrebbe suonare familiare. In poche parole, gli account locali inutilizzati sono account che non sono stati utilizzati per un certo periodo di tempo, spesso definito dai criteri dell&#8217;organizzazione. Questi account locali inutilizzati, apparentemente innocui, possono in realt\u00e0 rappresentare un rischio significativo per la sicurezza, in quanto potenzialmente possono fungere da backdoor per gli aggressori che vogliono ottenere un accesso non autorizzato al sistema. Oggi vedremo uno <strong>script PowerShell progettato per identificare e gestire queste potenziali falle di sicurezza<\/strong>.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;201341983&quot;:0,&quot;335559738&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h2 aria-level=\"2\"><span data-contrast=\"none\">Lo script per gestire gli account locali inutilizzati: Un\u2019analisi dettagliata<\/span><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h2>\n<p><span data-contrast=\"none\">Lo script <\/span><b><span data-contrast=\"none\">Test-UnusedLocalAccounts.ps1<\/span><\/b><span data-contrast=\"none\"> funziona con PowerShell 5.1 e offre un approccio semplificato alla gestione degli account locali inutilizzati. Come prima operazione, verifica se l&#8217;opzione <\/span><b><span data-contrast=\"none\">Get-LocalUser<\/span><\/b><span data-contrast=\"none\"> \u00e8 disponibile sul sistema. Si tratta di un aspetto cruciale, perch\u00e9 l&#8217;intera funzionalit\u00e0 si basa su questo comando. Una volta ottenuta una conferma, lo script scorre tutti gli account locali per individuare quelli che non hanno registrato alcuna attivit\u00e0 per un determinato numero di giorni (30 giorni per impostazione predefinita). La ciliegina sulla torta? Lo script fornisce un elenco ordinato di questi account locali inutilizzati direttamente nella console.<\/span><\/p>\n<p><span class=\"TextRun SCXW80442323 BCX0\" lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW80442323 BCX0\" data-ccp-parastyle=\"heading 2\">Lo script: Script di condizione per gli account locali inutilizzati in Windows<\/span><\/span><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">#Requires -Version 5.1\r\n\r\n&lt;#\r\n.SYNOPSIS\r\n    Condition script for unused local account on windows\r\n.DESCRIPTION\r\n    Condition script for unused local account on windows\r\n.EXAMPLE\r\n     -Days 30\r\n    Checks for accounts that have not logged in for more than 30 days\r\n.EXAMPLE\r\n    PS C:&gt; Test-UnusedLocalAccounts.ps1 -Days 30\r\n    Checks for accounts that have not logged in for more than 30 days\r\n.OUTPUTS\r\n    None\r\n.NOTES\r\n    Minimum supported OS: Windows 10, Server 2016\r\n    Release Notes:\r\n    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    [int]\r\n    $Days = 30\r\n)\r\n\r\nbegin {\r\n    function Test-StringEmpty {\r\n        param([string]$Text)\r\n        # Returns true if string is empty, null, or whitespace\r\n        process { [string]::IsNullOrEmpty($Text) -or [string]::IsNullOrWhiteSpace($Text) }\r\n    }\r\n    if (-not $(Test-StringEmpty -Text $env:Days)) {\r\n        $Days = $env:Days\r\n    }\r\n}\r\nprocess {\r\n    # Check if Get-LocalUser is available on this system\r\n    if (-not $(Get-Command -Name \"Get-LocalUser\" -ErrorAction SilentlyContinue)) {\r\n        Write-Error \"The command Get-LocalUser is not available on this system.\"\r\n        exit 2\r\n    }\r\n\r\n    $UnusedAccounts = Get-LocalUser |\r\n        Where-Object {\r\n            ($(Test-StringEmpty -Text $_.LastLogon) -or $_.LastLogon -le (Get-Date).AddDays(-$Days)) -and\r\n            $_.Enabled\r\n        } |\r\n        Select-Object Name, LastLogon |\r\n        ForEach-Object {\r\n            [PSCustomObject]@{\r\n                Name      = $_.Name\r\n                LastLogon = $_.LastLogon\r\n            }\r\n        }\r\n    if ($UnusedAccounts) {\r\n        Write-Host \"Accounts that have not logged in for the past $Days days:\"\r\n        $UnusedAccounts | ForEach-Object {\r\n            Write-Host \"$($_.Name): $($_.LastLogon)\"\r\n        }\r\n        exit 1\r\n    }\r\n    exit 0\r\n}\r\nend {\r\n    $ScriptVariables = @(\r\n        [PSCustomObject]@{\r\n            name           = \"Days\"\r\n            calculatedName = \"days\"\r\n            required       = $false\r\n            defaultValue   = [PSCustomObject]@{\r\n                type  = \"TEXT\"\r\n                value = \"30\"\r\n            }\r\n            valueType      = \"TEXT\"\r\n            valueList      = $null\r\n            description    = \"Accounts older than this number in days.\"\r\n        }\r\n    )\r\n}<\/pre>\n<p>&nbsp;<\/p>\n\n<div class=\"in-context-cta\"><p>Accedi a oltre 700 script nel Dojo di NinjaOne<\/p>\n<p><a href=\"https:\/\/www.ninjaone.com\/it\/prova-gratuita\/\">Ottieni l&#8217;accesso<\/a><\/p>\n<\/div>\n<h2 aria-level=\"2\"><span data-contrast=\"none\">Vantaggi principali: Oltre le basi<\/span><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h2>\n<h3 aria-level=\"3\"><b><span data-contrast=\"none\">Sicurezza<\/span><\/b><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"none\">Come accennato in precedenza, gli account locali inutilizzati vengono spesso lasciati senza controllo, diventando potenziali punti di accesso per i criminali informatici. Questo script aiuta a identificare in modo proattivo questi account.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;201341983&quot;:0,&quot;335559738&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h3 aria-level=\"3\"><b><span data-contrast=\"none\">Efficienza<\/span><\/b><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"none\">Individuare gli account locali inutilizzati potrebbe richiedere ore di lavoro manuale, ma con questo script basteranno solo pochi minuti. Soprattutto per gli MSP che gestiscono pi\u00f9 clienti, l&#8217;efficienza \u00e8 fondamentale.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;201341983&quot;:0,&quot;335559738&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<h3 aria-level=\"3\"><b><span data-contrast=\"none\">Flessibilit\u00e0<\/span><\/b><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h3>\n<p><span data-contrast=\"none\">Non sei vincolato al periodo predefinito di 30 giorni. Puoi personalizzare l&#8217;intervallo di tempo in base ai criteri della tua azienda per verificare la presenza di account locali inutilizzati.<\/span><\/p>\n<h2 aria-level=\"2\"><span data-contrast=\"none\">Funzionalit\u00e0 estese<\/span><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h2>\n<p><span data-contrast=\"none\">Se individuare gli account inutilizzati \u00e8 fondamentale, altrettanto importante \u00e8 agire sulla base di queste informazioni. Lo script pu\u00f2 anche essere configurato per esportare i risultati in un file o inviare una notifica via e-mail quando vengono scoperti account inutilizzati. Questo migliora la capacit\u00e0 di tracciare e gestire questi account in modo efficace.<\/span><\/p>\n<h2 aria-level=\"2\"><span data-contrast=\"none\">Come usarlo<\/span><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h2>\n<p><span data-contrast=\"none\">Per distribuire lo script, utilizza il seguente comando:<\/span><\/p>\n\n<p>Potrebbe interessarti anche il nostro post sul blog, <a href=\"https:\/\/www.ninjaone.com\/blog\/how-to-disable-local-account-windows-powershell\/\">Come disabilitare un account locale in Windows utilizzando PowerShell.<\/a><\/p>\n<h2 aria-level=\"2\"><span data-contrast=\"none\">NinjaOne: Ampliare il tuo arsenale<\/span><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h2>\n<p><span data-contrast=\"none\">Anche se questo script PowerShell \u00e8 uno strumento prezioso, resta comunque solo un pezzo del puzzle. Piattaforme come NinjaOne offrono un approccio pi\u00f9 completo, consentendo di gestire non solo gli account locali inutilizzati, ma l&#8217;intero ecosistema IT. NinjaOne pu\u00f2 anche eseguire script come <\/span><b><span data-contrast=\"none\">Test-UnusedLocalAccounts.ps1<\/span><\/b><span data-contrast=\"none\"> su pi\u00f9 sistemi contemporaneamente.<\/span><\/p>\n<h2 aria-level=\"2\"><span data-contrast=\"none\">Considerazioni finali<\/span><span data-ccp-props=\"{&quot;134245418&quot;:true,&quot;134245529&quot;:true,&quot;201341983&quot;:0,&quot;335559738&quot;:40,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/h2>\n<p><span data-contrast=\"none\">Nel grande schema della sicurezza informatica, ogni piccola cosa conta. Gli account locali inutilizzati nei sistemi Windows possono sembrare una questione banale, ma se non vengono gestiti correttamente possono diventare il tuo tallone d&#8217;Achille. Lo script <\/span><b><span data-contrast=\"none\">Test-UnusedLocalAccounts.ps1<\/span><\/b><span data-contrast=\"none\"> \u00e8 una soluzione valida e automatizzata per controllare questo aspetto spesso trascurato della gestione del sistema. E abbinandolo a piattaforme come NinjaOne e ad altri strumenti, i professionisti IT e gli MSP disporranno di un ampio kit di soluzioni per garantire che le loro reti non vengano compromesse.<\/span><span data-ccp-props=\"{&quot;134233117&quot;:false,&quot;201341983&quot;:0,&quot;335559738&quot;:0,&quot;335559739&quot;:160,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"none\">Quindi, ecco a te. Fai in modo di avere gli strumenti e le conoscenze giuste per salvaguardare efficacemente il tuo ambiente IT. Continua a seguire questo spazio per ulteriori soluzioni IT aziendali.<\/span><span data-ccp-props=\"{&quot;134233118&quot;:false,&quot;201341983&quot;:0,&quot;335559739&quot;:0,&quot;335559740&quot;:259}\">\u00a0<\/span><\/p>\n","protected":false},"author":35,"featured_media":206982,"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":[4277],"class_list":["post-208106","script_hub","type-script_hub","status-publish","has-post-thumbnail","hentry","script_hub_category-windows"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/script_hub\/208106","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/comments?post=208106"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/media\/206982"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/media?parent=208106"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/operating_system?post=208106"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/use_cases?post=208106"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}