{"id":815650,"date":"2026-05-28T12:24:15","date_gmt":"2026-05-28T12:24:15","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=815650"},"modified":"2026-05-28T12:24:15","modified_gmt":"2026-05-28T12:24:15","slug":"como-criar-uma-nova-conta-de-usuario-local-com-o-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/pt-br\/script-hub\/como-criar-uma-nova-conta-de-usuario-local-com-o-powershell\/","title":{"rendered":"Como criar uma nova conta de usu\u00e1rio local com o PowerShell"},"content":{"rendered":"<h2>Principais conclus\u00f5es<\/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>Efici\u00eancia do PowerShell<\/strong>: Utiliza o PowerShell para criar e gerenciar contas de usu\u00e1rios locais com efici\u00eancia.<\/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>Recursos avan\u00e7ados<\/strong>: Inclui agendamento para ativar\/desativar contas e adicionar usu\u00e1rios a grupos de administradores.<\/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>Seguran\u00e7a automatizada<\/strong>: Gera senhas seguras automaticamente, aumentando a seguran\u00e7a da conta.<\/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>Gerenciamento de tempo<\/strong>: Economiza tempo no gerenciamento de contas de usu\u00e1rios, o que \u00e9 particularmente \u00fatil para MSPs.<\/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 personaliz\u00e1vel<\/strong>: Permite a personaliza\u00e7\u00e3o por meio de par\u00e2metros definidos pelo usu\u00e1rio.<\/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>Agendar tarefas<\/strong>: Capaz de agendar tarefas para ativar ou desativar contas em hor\u00e1rios espec\u00edficos.<\/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>Gerenciamento de grupos<\/strong>: Facilita a adi\u00e7\u00e3o de usu\u00e1rios a grupos espec\u00edficos, incluindo administradores.<\/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>Adapt\u00e1vel para cria\u00e7\u00e3o em massa<\/strong>: Embora tenha sido projetado para contas individuais, pode ser adaptado para a cria\u00e7\u00e3o de usu\u00e1rios em massa.<\/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>Implica\u00e7\u00f5es de seguran\u00e7a<\/strong>: Destaca a necessidade de controles de acesso rigorosos e auditorias regulares.<\/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>NinjaOne Compatibilidade<\/strong>: Pode ser integrado ao NinjaOne para gerenciamento centralizado de TI.<\/li>\n<\/ul>\n<p>No cen\u00e1rio digital atual, o gerenciamento eficiente das contas de usu\u00e1rio \u00e9 crucial para os profissionais de TI. O PowerShell, uma poderosa linguagem de script e shell de linha de comando, oferece uma maneira din\u00e2mica de lidar com essas tarefas. Esta postagem do blog explora um script do PowerShell que n\u00e3o apenas cria contas de usu\u00e1rio locais, mas tamb\u00e9m oferece op\u00e7\u00f5es de agendamento e gerenciamento de grupos, mostrando sua utilidade em v\u00e1rios ambientes de TI.<\/p>\n<h2>Hist\u00f3rico<\/h2>\n<p>Esse script do PowerShell se destaca por sua capacidade de criar contas de usu\u00e1rio locais com recursos avan\u00e7ados, como agendamento de datas de ativa\u00e7\u00e3o\/desativa\u00e7\u00e3o e adi\u00e7\u00e3o de usu\u00e1rios ao grupo de administradores locais. Essas funcionalidades s\u00e3o particularmente relevantes para profissionais de TI e <a href=\"https:\/\/www.ninjaone.com\/what-is-an-msp\/\">provedores de servi\u00e7os gerenciados (MSPs)<\/a> que gerenciam um grande n\u00famero de contas de usu\u00e1rios e precisam garantir o acesso seguro e em tempo h\u00e1bil aos sistemas.<\/p>\n<h2>O roteiro:<\/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>Acesse mais de 300 scripts no NinjaOne Dojo<\/p>\n<p><a href=\"https:\/\/www.ninjaone.com\/freetrialform\/\">Obter acesso<\/a><\/p>\n<\/div>\n<h2>Detalhamento<\/h2>\n<p>O script \u00e9 estruturado em v\u00e1rias se\u00e7\u00f5es principais, cada uma executando uma tarefa espec\u00edfica:<\/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>Defini\u00e7\u00e3o do par\u00e2metro<\/strong>: Par\u00e2metros como <strong>UserNameToAdd<\/strong>, <strong>Name<\/strong> e <strong>DateAndTimeToEnable<\/strong> s\u00e3o declarados, permitindo a personaliza\u00e7\u00e3o da entrada do usu\u00e1rio.<\/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>Fun\u00e7\u00f5es<\/strong>: Fun\u00e7\u00f5es cr\u00edticas como <strong>Test-IsElevated<\/strong>, <strong>New-SecurePassword<\/strong> e <strong>New-LocalUserFromNinja<\/strong> s\u00e3o definidas. <strong>O Test-IsElevated<\/strong> verifica se h\u00e1 privil\u00e9gios administrativos, o <strong>New-SecurePassword<\/strong> gera uma senha segura e <strong>o New-LocalUserFromNinja<\/strong> encapsula a funcionalidade principal de cria\u00e7\u00e3o e gerenciamento de usu\u00e1rios.<\/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>Cria\u00e7\u00e3o e gerenciamento de usu\u00e1rios<\/strong>: O script verifica se o usu\u00e1rio especificado existe, cria um novo usu\u00e1rio se n\u00e3o existir e define propriedades como senha, descri\u00e7\u00e3o e expira\u00e7\u00e3o da conta. Ele tamb\u00e9m lida com a adi\u00e7\u00e3o de usu\u00e1rios a grupos e agenda tarefas para ativar\/desativar contas.<\/li>\n<\/ul>\n<h2>Casos de uso em potencial<\/h2>\n<p>Imagine um MSP gerenciando a TI de uma empresa com equipe tempor\u00e1ria. Eles podem usar esse script para automatizar a cria\u00e7\u00e3o de contas para novos funcion\u00e1rios, definindo datas espec\u00edficas de ativa\u00e7\u00e3o e desativa\u00e7\u00e3o, economizando tempo e reduzindo erros manuais.<\/p>\n<h2>Compara\u00e7\u00f5es<\/h2>\n<p>Tradicionalmente, o gerenciamento de contas de usu\u00e1rio pode envolver processos manuais ou scripts b\u00e1sicos que n\u00e3o possuem recursos avan\u00e7ados, como gera\u00e7\u00e3o de senhas seguras ou ativa\u00e7\u00e3o\/desativa\u00e7\u00e3o programada. Esse script oferece uma abordagem mais sofisticada, segura e eficiente em termos de tempo.<\/p>\n<h2>Implica\u00e7\u00f5es<\/h2>\n<p>O uso desse script aumenta a seguran\u00e7a e a efici\u00eancia, mas tamb\u00e9m ressalta a necessidade de controles de acesso e monitoramento rigorosos, pois a cria\u00e7\u00e3o automatizada de contas pode ser um poss\u00edvel vetor de acesso n\u00e3o autorizado se n\u00e3o for gerenciada adequadamente.<\/p>\n<h2>Recomenda\u00e7\u00f5es<\/h2>\n<p>As pr\u00e1ticas recomendadas incluem a revis\u00e3o regular do script, o uso em conjunto com pol\u00edticas de auditoria robustas e a garantia de que somente o pessoal autorizado tenha acesso ao script e \u00e0s suas funcionalidades.<\/p>\n<h2>Considera\u00e7\u00f5es finais<\/h2>\n<p>O NinjaOne, uma plataforma conhecida por <a href=\"https:\/\/www.ninjaone.com\/pt-br\/\">simplificar as tarefas de gerenciamento de TI<\/a>, pode complementar esses scripts fornecendo uma interface centralizada e f\u00e1cil de usar para gerenciar esses processos automatizados. A incorpora\u00e7\u00e3o de scripts do PowerShell em um ambiente NinjaOne pode aumentar significativamente <a href=\"https:\/\/www.ninjaone.com\/pt-br\/eficiencia\/\">a efici\u00eancia operacional<\/a> e a seguran\u00e7a no gerenciamento de TI.<\/p>\n","protected":false},"author":35,"featured_media":193900,"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":[12435],"class_list":["post-815650","script_hub","type-script_hub","status-publish","has-post-thumbnail","hentry","script_hub_category-windows"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/script_hub\/815650","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/script_hub"}],"about":[{"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/types\/script_hub"}],"author":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/comments?post=815650"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/media\/193900"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/media?parent=815650"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/operating_system?post=815650"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/use_cases?post=815650"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}