{"id":208171,"date":"2024-01-22T14:06:45","date_gmt":"2024-01-22T14:06:45","guid":{"rendered":"https:\/\/www.ninjaone.com\/script-hub\/come-creare-un-account-utente-locale-con-powershell\/"},"modified":"2024-03-04T18:15:03","modified_gmt":"2024-03-04T18:15:03","slug":"come-creare-un-account-utente-locale-con-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/it\/script-hub\/come-creare-un-account-utente-locale-con-powershell\/","title":{"rendered":"Come creare un account utente locale con PowerShell"},"content":{"rendered":"<h2>Punti chiave<\/h2>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&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>Efficienza di PowerShell<\/strong>: Lo script utilizza PowerShell per creare un account utente locale e gestirlo in modo efficiente.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&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>Funzionalit\u00e0 avanzate<\/strong>: Lo script per creare un account utente locale include la pianificazione per l&#8217;abilitazione\/disabilitazione degli account e l&#8217;aggiunta di utenti ai gruppi di amministrazione.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&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>Sicurezza automatizzata<\/strong>: Lo script per creare un account utente locale genera automaticamente password sicure, migliorando la sicurezza degli account.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&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>Gestione del tempo<\/strong>: Risparmio di tempo nella gestione degli account utente, particolarmente utile per gli MSP.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&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>Script personalizzabile<\/strong>: Lo script per creare un account utente locale consente la personalizzazione attraverso parametri definiti dall&#8217;utente.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&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>Pianificazione delle attivit\u00e0<\/strong>: Lo script per creare un account utente locale \u00e8 in grado di pianificare attivit\u00e0 per abilitare o disabilitare gli account in momenti specifici.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&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\"><strong>Gestione del gruppo<\/strong>: Facilita l&#8217;aggiunta di utenti a gruppi specifici, compresi gli amministratori.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&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\"><strong>Adattabilit\u00e0 per la creazione di account in blocco<\/strong>: Pur essendo stato progettato per gli account individuali, pu\u00f2 essere adattato per la creazione di utenti in blocco.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&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\"><strong>Implicazioni per la sicurezza<\/strong>: Si evidenzia la necessit\u00e0 di un controllo rigoroso degli accessi e di una verifica regolare.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&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\"><strong>Compatibilit\u00e0 con NinjaOne<\/strong>: Lo script per creare un account utente locale pu\u00f2 essere integrato con NinjaOne per una gestione IT centralizzata.<\/li>\n<\/ul>\n<p>Nell&#8217;attuale panorama digitale, la gestione efficiente degli account utente \u00e8 fondamentale per i professionisti IT. PowerShell, un potente linguaggio di scripting con una shell a riga di comando, offre un modo dinamico per gestire queste attivit\u00e0. In questo articolo viene analizzato uno script PowerShell utile non solo per creare un account utente locale, ma che fornisce anche opzioni per la pianificazione e la gestione dei gruppi, mostrando la sua utilit\u00e0 in vari ambienti IT.<\/p>\n<h2>Background<\/h2>\n<p>Questo script PowerShell per creare un account utente locale si distingue per la capacit\u00e0 di creare account utente locali con funzionalit\u00e0 avanzate, come la pianificazione delle date di attivazione\/disattivazione e l&#8217;aggiunta di utenti al gruppo di amministrazione locale. Queste funzionalit\u00e0 sono particolarmente importanti per i professionisti IT e i <a href=\"https:\/\/www.ninjaone.com\/what-is-an-msp\/\">Managed Service Provider (MSP)<\/a> che gestiscono un gran numero di account utente e devono garantire un accesso tempestivo e sicuro ai sistemi.<\/p>\n<h2>Lo script per creare un account utente locale:<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">#Requires -Version 5.1\r\n\r\n&lt;#\r\n.SYNOPSIS\r\n    Create a local user account with options to enable and disable at specific dates, and add to local admin group. Saves randomly generated password to a custom field.\r\n.DESCRIPTION\r\n    You can specify when the account will be enabled and\/or disabled.\r\n    You can have the account be added as a member of the local Administrators group.\r\n\r\nPARAMETER: -UserNameToAdd \"JohnTSmith\" -Name \"John T Smith\"\r\n    Create use with the name JohnTSmith and display name of John T Smith.\r\n.EXAMPLE\r\n    -UserNameToAdd \"JohnTSmith\" -Name \"John T Smith\"\r\n    ## EXAMPLE OUTPUT ##\r\n    User JohnTSmith has been created successfully.\r\n    User JohnTSmith was added to the local Users group.\r\n\r\nPARAMETER: -UserNameToAdd \"JohnTSmith\" -Name \"John T Smith\" -DateAndTimeToEnable \"Monday, January 1, 2020 1:00:00 PM\"\r\n    Create use with the name JohnTSmith and display name of John T Smith.\r\n    The user will start out disabled.\r\n    A scheduled task will be create to enable the user after \"Monday, January 1, 2020 1:00:00 PM\"\r\n.EXAMPLE\r\n    -UserNameToAdd \"JohnTSmith\" -Name \"John T Smith\" -DateAndTimeToEnable \"Monday, January 1, 2020 1:00:00 PM\"\r\n    ## EXAMPLE OUTPUT ##\r\n    User JohnTSmith has been created successfully.\r\n    User JohnTSmith was added to the local Users group.\r\n    Created Scheduled Task: Enable User JohnTSmith\r\n    User JohnTSmith will be able to login after Monday, January 1, 2020 1:00:00 PM.\r\n\r\nPARAMETER: -UserNameToAdd \"JohnTSmith\" -Name \"John T Smith\" -DisableAfterDays 10\r\n    Create use with the name JohnTSmith and display name of John T Smith.\r\n    The user will be disabled after 10 days after the user's creation.\r\n.EXAMPLE\r\n    -UserNameToAdd \"JohnTSmith\" -Name \"John T Smith\" -DisableAfterDays 10\r\n    ## EXAMPLE OUTPUT ##\r\n    User JohnTSmith has been created successfully.\r\n    User JohnTSmith was added to the local Users group.\r\n\r\nPARAMETER: -UserNameToAdd \"JohnTSmith\" -Name \"John T Smith\" -AddToLocalAdminGroup\r\n    Create use with the name JohnTSmith and display name of John T Smith.\r\n    User will be added as a member of the local Administrators group.\r\n.EXAMPLE\r\n    -UserNameToAdd \"JohnTSmith\" -Name \"John T Smith\" -AddToLocalAdminGroup\r\n    ## EXAMPLE OUTPUT ##\r\n    User JohnTSmith has been created successfully.\r\n    User JohnTSmith was added to the local Users group.\r\n    User JohnTSmith was added to the local Administrators group.\r\n.OUTPUTS\r\n    None\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]$UserNameToAdd,\r\n    [Parameter()]\r\n    [String]$Name,\r\n    [Parameter()]\r\n    [String]$PasswordCustomField,\r\n    [Parameter()]\r\n    [int]$PasswordLength,\r\n    [Parameter()]\r\n    [DateTime]$DateAndTimeToEnable,\r\n    [Parameter()]\r\n    [int]$DisableAfterDays,\r\n    [Parameter()]\r\n    [Switch]$AddToLocalAdminGroup,\r\n    [Parameter()]\r\n    $PasswordOptions\r\n)\r\n\r\nbegin {\r\n    function Test-IsElevated {\r\n        $id = [System.Security.Principal.WindowsIdentity]::GetCurrent()\r\n        $p = New-Object System.Security.Principal.WindowsPrincipal($id)\r\n        $p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator)\r\n    }\r\n    function New-SecurePassword {\r\n        [CmdletBinding()]\r\n        param (\r\n            [Parameter(Mandatory = $false)]\r\n            [int]$Length = 16,\r\n            [Parameter(Mandatory = $false)]\r\n            [bool]$IncludeSpecialCharacters = $true\r\n        )\r\n        # .NET class for generating cryptographically secure random numbers\r\n        $cryptoProvider = New-Object System.Security.Cryptography.RNGCryptoServiceProvider\r\n        $SpecialCharacters = if ($IncludeSpecialCharacters) { '!@#$%&amp;-' }\r\n        $passwordChars = \"abcdefghjknpqrstuvwxyzABCDEFGHIJKMNPQRSTUVWXYZ0123456789$SpecialCharacters\"\r\n        $password = for ($i = 0; $i -lt $Length; $i++) {\r\n            $byte = [byte[]]::new(1)\r\n            $cryptoProvider.GetBytes($byte)\r\n            $charIndex = $byte[0] % $passwordChars.Length\r\n            $passwordChars[$charIndex]\r\n        }\r\n        return $password -join ''\r\n    }\r\n    function New-LocalUserFromNinja {\r\n        param(\r\n            [string]$Username,\r\n            [string]$Name,\r\n            [string]$PasswordCustomField,\r\n            [DateTime]$EnableDate,\r\n            [int]$DisableAfterDays,\r\n            [switch]$AddToLocalAdminGroup\r\n        )\r\n        # Generate a secure localUserPassword\r\n        $Password = New-SecurePassword -Length $PasswordLength -IncludeSpecialCharacters $true\r\n        if ($Username -and $Name) {\r\n            # Check if the user already exists\r\n            if (-not (Get-LocalUser -Name $Username -ErrorAction SilentlyContinue)) {\r\n                # Create new local user\r\n                $UserSplat = @{\r\n                    Name                 = \"$Username\"\r\n                    FullName             = \"$Name\"\r\n                    Password             = ConvertTo-SecureString -String $($Password -join '') -AsPlainText -Force\r\n                    Description          = \"User account created on $(Get-Date)\"\r\n                    PasswordNeverExpires = $false\r\n                }\r\n\r\n                if ($EnableDate -and $EnableDate -gt (Get-Date)) {\r\n                    $UserSplat['Disabled'] = $true\r\n                }\r\n\r\n                if (-not $EnableDate -and $DisableAfterDays) {\r\n                    $UserSplat['AccountExpires'] = $(Get-Date).AddDays($DisableAfterDays)\r\n                }\r\n                elseif ($DisableAfterDays) {\r\n                    $UserSplat['AccountExpires'] = $(Get-Date $EnableDate).AddDays($DisableAfterDays)\r\n                }\r\n\r\n                if ($env:passwordOptions -like 'Password Never Expires' -or $PasswordOptions -like 'Password Never Expires') {\r\n                    $UserSplat['PasswordNeverExpires'] = $true\r\n                }\r\n\r\n                New-LocalUser @UserSplat\r\n                if ($env:passwordOptions -like 'User Must Change Password' -or $PasswordOptions -like 'User Must Change Password') {\r\n                    net.exe user $Username \/logonpasswordchg:yes\r\n                }\r\n                # Write it to a secure custom field\r\n                if ((Get-LocalUser -Name $Username -ErrorAction SilentlyContinue)) {\r\n                    Write-Host \"User $Username has been created successfully.\"\r\n                    if ($PasswordCustomField -like \"null\") {\r\n                        Write-Host \"CustomField not specified.\"\r\n                        Write-Host \"Password set to: $Password\"\r\n                    }\r\n                    else {\r\n                        Ninja-Property-Set -Name \"$PasswordCustomField\" -Value \"$Password\"\r\n                        Write-Host \"Password saved to $PasswordCustomField Custom Field.\"\r\n                    }\r\n                }\r\n                else {\r\n                    throw \"Failed to create User $Username.\"\r\n                }\r\n\r\n                Add-LocalGroupMember -Group $(Get-LocalGroup -Name \"Users\") -Member $Username\r\n\r\n                Write-Host \"User $UserName was added to the local Users group.\"\r\n\r\n                # If date to enable account is specified, disable account until then\r\n                if ($EnableDate) {\r\n                    if ($EnableDate -gt (Get-Date)) {\r\n                        # Schedule a job to enable the user at the specified date\r\n                        $TaskSplat = @{\r\n                            Description = \"Ninja Automation Enable User $Username\"\r\n                            Action      = New-ScheduledTaskAction -Execute \"powershell.exe\" -Argument \"-NoProfile -WindowStyle Hidden -Command &amp; {Enable-LocalUser -Name `\"$Username`\"}\"\r\n                            Trigger     = New-ScheduledTaskTrigger -Once -At $EnableDate\r\n                            Principal   = New-ScheduledTaskPrincipal -UserId \"SYSTEM\" -LogonType ServiceAccount\r\n                        }\r\n\r\n                        try {\r\n                            New-ScheduledTask @TaskSplat | Register-ScheduledTask -User \"System\" -TaskName \"Enable User $Username\" | Out-Null\r\n                            if ($(Get-ScheduledTask -TaskName \"Enable User $Username\")) {\r\n                                Write-Host \"Created Scheduled Task: Enable User $Username\"\r\n                            }\r\n                            else {\r\n                                throw \"Failed to find scheduled task with the name 'Enable User $Username'\"\r\n                            }\r\n                        }\r\n                        catch {\r\n                            Write-Error $_\r\n                            throw \"Failed to create Enable User scheduled task.\"\r\n                        }\r\n\r\n                        Write-Host \"User $Username will be able to login after $EnableDate.\"\r\n                    }\r\n                }\r\n                else {\r\n                    Write-Host \"No Enable Date is Set, $UserName is able to login now.\"\r\n                }\r\n\r\n                # Add to local admin group if specified\r\n                if ($AddToLocalAdminGroup) {\r\n                    Add-LocalGroupMember -Group $(Get-LocalGroup -Name \"Administrators\") -Member $Username\r\n                    if (-not (Get-LocalGroupMember -Group $(Get-LocalGroup -Name \"Administrators\") -Member $Username)) {\r\n                        throw \"Failed to add user to local Administrators group.\"\r\n                    }\r\n                    Write-Host \"User $UserName was added to the local Administrators group.\"\r\n                }\r\n            }\r\n            else {\r\n                Write-Host \"User $Username already exists.\"\r\n            }\r\n        }\r\n        else {\r\n            throw \"Username and Name are required to create a local account.\"\r\n        }\r\n    }\r\n}\r\nprocess {\r\n    if ($env:usernameToAdd -and $env:usernameToAdd -like \"null\") {\r\n        Write-Error \"usernameToAdd($env:usernameToAdd) parameter is invalid.\"\r\n        exit 1\r\n    }\r\n    if ($env:name -and $env:name -like \"null\") {\r\n        Write-Error \"name($env:name) parameter is invalid.\"\r\n        exit 1\r\n    }\r\n    if ($env:passwordCustomField -and $env:passwordCustomField -like \"null\") {\r\n        Write-Error \"passwordCustomField($env:passwordCustomField) parameter is invalid.\"\r\n        exit 1\r\n    }\r\n    if (-not (Test-IsElevated)) {\r\n        Write-Error -Message \"Access Denied. Please run with Administrator privileges.\"\r\n        exit 1\r\n    }\r\n    $params = @{\r\n        Username = if ($PSBoundParameters.ContainsKey(\"UserNameToAdd\")) { $UserNameToAdd }else { $env:usernameToAdd }\r\n        Name     = if ($PSBoundParameters.ContainsKey(\"Name\")) { $Name }else { $env:name }\r\n    }\r\n    # Conditionally add EnableDate\r\n    if ($env:dateAndTimeToEnable -and $env:dateAndTimeToEnable -notlike \"null\") {\r\n        $params[\"EnableDate\"] = Get-Date \"$env:dateAndTimeToEnable\"\r\n    }\r\n    elseif ($PSBoundParameters.ContainsKey(\"DateAndTimeToEnable\") -and $DateAndTimeToEnable) {\r\n        $params[\"EnableDate\"] = $DateAndTimeToEnable\r\n    }\r\n    # Conditionally add DisableAfterDays\r\n    if ($env:disableAfterDays -notlike \"null\") {\r\n        $params[\"DisableAfterDays\"] = $env:disableAfterDays\r\n    }\r\n    elseif ($PSBoundParameters.ContainsKey(\"DisableAfterDays\")) {\r\n        $params[\"DisableAfterDays\"] = $DisableAfterDays\r\n    }\r\n\r\n    # Conditionally add AddToLocalAdminGroup\r\n    if ([Convert]::ToBoolean($env:addToLocalAdminGroup)) {\r\n        $params[\"AddToLocalAdminGroup\"] = $true\r\n    }\r\n    elseif ($PSBoundParameters.ContainsKey(\"AddToLocalAdminGroup\")) {\r\n        $params[\"AddToLocalAdminGroup\"] = $AddToLocalAdminGroup\r\n    }\r\n    # Conditionally add AddToLocalAdminGroup\r\n    if ($env:passwordCustomField -notlike \"null\") {\r\n        $params[\"PasswordCustomField\"] = $env:passwordCustomField\r\n    }\r\n    elseif ($env:passwordCustomField -like \"null\") {\r\n        Write-Error \"passwordCustomField: is Required\"\r\n        exit 1\r\n    }\r\n    elseif ($PSBoundParameters.ContainsKey(\"PasswordCustomField\")) {\r\n        $params[\"PasswordCustomField\"] = $PasswordCustomField\r\n    }\r\n\r\n    if ($env:passwordLength -notlike \"null\") {\r\n        $PasswordLength = $env:passwordLength\r\n    }\r\n    elseif (-not $passwordLength) {\r\n        $PasswordLength = 20\r\n    }\r\n\r\n    try {\r\n        New-LocalUserFromNinja @params\r\n    }\r\n    catch {\r\n        Write-Error $_\r\n        exit 1\r\n    }\r\n}\r\nend {\r\n    \r\n    \r\n    \r\n}<\/pre>\n<p>&nbsp;<\/p>\n\n<div class=\"in-context-cta\"><p>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>Analisi dettagliata dello script per creare un account utente locale<\/h2>\n<p>Lo script per creare un account utente locale \u00e8 strutturato in diverse sezioni chiave, ognuna delle quali svolge un compito specifico:<\/p>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&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>Definizione dei parametri<\/strong>: Vengono dichiarati parametri come <strong>UserNameToAdd<\/strong>, <strong>Name<\/strong> e <strong>DateAndTimeToEnable<\/strong>, che consentono di personalizzare l&#8217;input dell&#8217;utente.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&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>Funzioni<\/strong>: Vengono definite funzioni critiche come <strong>Test-IsElevated<\/strong>, <strong>New-SecurePassword<\/strong> e <strong>New-LocalUserFromNinja<\/strong>. <strong>Test-IsElevated<\/strong> verifica la presenza di privilegi amministrativi, <strong>New-SecurePassword<\/strong> genera una password sicura e <strong>New-LocalUserFromNinja<\/strong> racchiude la funzionalit\u00e0 principale di creazione e gestione degli utenti.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&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>Creazione e gestione degli utenti<\/strong>: Lo script per creare un account utente locale controlla se l&#8217;utente specificato esiste, crea un nuovo utente in caso contrario e imposta propriet\u00e0 come password, descrizione e scadenza dell&#8217;account. Gestisce inoltre l&#8217;aggiunta di utenti ai gruppi e pianifica le attivit\u00e0 di abilitazione\/disabilitazione degli account.<\/li>\n<\/ul>\n<h2>Casi d&#8217;uso potenziali dello script per creare un account utente locale<\/h2>\n<p>Immaginate un MSP che gestisce l&#8217;IT di un&#8217;azienda con personale temporaneo. Pu\u00f2 utilizzare questo script per creare un account utente locale in modo da automatizzare la creazione di account per i nuovi dipendenti, impostando date specifiche di attivazione e disattivazione, risparmiando tempo e riducendo gli errori manuali.<\/p>\n<h2>Confronti<\/h2>\n<p>Tradizionalmente, la gestione degli account utente pu\u00f2 comportare processi manuali o l\u2019utilizzo di script di base che mancano di funzionalit\u00e0 avanzate come la generazione di password sicure o l&#8217;attivazione\/disattivazione programmata. Questo script per creare un account utente locale offre un approccio pi\u00f9 sofisticato, sicuro ed efficiente in termini di tempo.<\/p>\n<h2>Domande frequenti sullo script per creare un account utente locale<\/h2>\n<ul>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&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>Questo script per creare un account utente locale pu\u00f2 gestire la creazione di utenti in blocco?<\/strong><br \/>\nSebbene sia stato progettato per account individuali, pu\u00f2 essere adattato per la creazione di grandi quantit\u00e0 con delle modifiche.<\/li>\n<li data-leveltext=\"\uf0b7\" data-font=\"Symbol\" data-listid=\"1\" data-list-defn-props=\"{&quot;335552541&quot;:1,&quot;335559684&quot;:-2,&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>\u00c8 sicuro da usare per gli ambienti sensibili?<\/strong><br \/>\nS\u00ec, include funzioni come la generazione di password sicure.<\/li>\n<\/ul>\n<h2>Implicazioni<\/h2>\n<p>L&#8217;uso di uno script di questo tipo per creare un account utente locale aumenta la sicurezza e l&#8217;efficienza, ma si deve sottolineare la necessit\u00e0 di un controllo e di un monitoraggio rigorosi degli accessi, poich\u00e9 la creazione automatica di account pu\u00f2 essere un potenziale vettore di accesso non autorizzato se non viene gestita correttamente.<\/p>\n<h2>Raccomandazioni<\/h2>\n<p>Le best practice includono la revisione regolare dello script per creare un account utente locale, l&#8217;utilizzo in combinazione con solidi criteri di auditing e la garanzia che solo il personale autorizzato abbia accesso allo script per creare un account utente locale e alle sue funzionalit\u00e0.<\/p>\n<h2>Considerazioni finali<\/h2>\n<p>NinjaOne, una piattaforma nota per la <a href=\"https:\/\/www.ninjaone.com\/it\/\">semplificazione delle attivit\u00e0 di gestione IT<\/a>, pu\u00f2 integrare script come quello per creare un account utente locale fornendo un&#8217;interfaccia centralizzata e di facile utilizzo per la gestione di questi processi automatizzati. L&#8217;integrazione di script PowerShell in un ambiente NinjaOne potrebbe migliorare in modo significativo l&#8217;<a href=\"https:\/\/www.ninjaone.com\/it\/efficienza-it\">efficienza operativa<\/a> e la sicurezza della gestione IT.<\/p>\n","protected":false},"author":35,"featured_media":207382,"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-208171","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\/208171","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=208171"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/media\/207382"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/media?parent=208171"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/operating_system?post=208171"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/it\/wp-json\/wp\/v2\/use_cases?post=208171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}