{"id":810788,"date":"2026-05-21T11:58:12","date_gmt":"2026-05-21T11:58:12","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=810788"},"modified":"2026-05-21T11:58:12","modified_gmt":"2026-05-21T11:58:12","slug":"como-redefinir-senhas-de-usuario-usando-o-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/pt-br\/script-hub\/como-redefinir-senhas-de-usuario-usando-o-powershell\/","title":{"rendered":"Como redefinir senhas de usu\u00e1rio usando o PowerShell"},"content":{"rendered":"<p>A capacidade de gerenciar o acesso e as credenciais dos usu\u00e1rios \u00e9 um componente essencial da administra\u00e7\u00e3o de TI. Seja em uma grande organiza\u00e7\u00e3o com necessidades complexas de TI ou em uma empresa menor com requisitos simples, uma tarefa comum \u00e9 o gerenciamento de senhas. O script fornecido apresenta um m\u00e9todo para <strong>redefinir senhas de usu\u00e1rios usando o PowerShell<\/strong>, seja para usu\u00e1rios locais do Windows ou em um ambiente do Active Directory.<\/p>\n<h2>Hist\u00f3rico<\/h2>\n<p>O script foi projetado principalmente para oferecer aos profissionais de TI e aos <a href=\"https:\/\/www.ninjaone.com\/what-is-an-msp\/\">provedores de servi\u00e7os gerenciados (MSPs)<\/a> uma abordagem simplificada para redefinir as senhas dos usu\u00e1rios sem se aprofundar nas interfaces de usu\u00e1rio do sistema. Com o n\u00famero cada vez maior de usu\u00e1rios e a necessidade constante de aplicar pr\u00e1ticas de seguran\u00e7a, ter uma ferramenta que realize essas opera\u00e7\u00f5es de forma r\u00e1pida e confi\u00e1vel \u00e9 inestim\u00e1vel. Esse script, especialmente quando combinado com ferramentas como o NinjaOne, oferece <a href=\"https:\/\/www.ninjaone.com\/pt-br\/rmm\/automacao-de-ti\/\">automa\u00e7\u00e3o e efici\u00eancia<\/a> para essas tarefas.<\/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    Resets a users password.\r\n.DESCRIPTION\r\n    Resets a users password. Either a local user that this script runs on, or in Active directory.\r\n.EXAMPLE\r\n     -UserName \"Fred\" -Password \"Somepass1\"\r\n    Resets Fred's password to Somepass1 .\r\n.EXAMPLE\r\n     -UserName \"Fred\" -Password \"Somepass1\" -IsDomainUser\r\n    Resets Fred's password to Somepass1 in Active Directory.\r\n.EXAMPLE\r\n    PS C:&gt; .Reset-User-Password.ps1 -UserName \"Fred\" -Password \"Somepass1\" -IsDomainUser\r\n    Resets Fred's password to Somepass1 in Active Directory.\r\n.OUTPUTS\r\n    None\r\n.NOTES\r\n    Minimum OS Architecture Supported: Windows 10, Windows Server 2012\r\n    The RSAT feature for Active Directory needs to be installed on the computer this runs on.\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.COMPONENT\r\n    ManageUsers\r\n#&gt;\r\n\r\n[CmdletBinding()]\r\nparam (\r\n    [Parameter(Mandatory = $true)]\r\n    [String]\r\n    $UserName,\r\n    [Parameter(Mandatory = $true)]\r\n    [String]\r\n    $Password,\r\n    [Switch]\r\n    $IsDomainUser\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        if ($p.IsInRole([System.Security.Principal.WindowsBuiltInRole]::Administrator))\r\n        { Write-Output $true }\r\n        else\r\n        { Write-Output $false }\r\n    }\r\n}\r\n    \r\nprocess {\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    if ($IsDomainUser) {\r\n        # Active Directory\r\n        # Check if the ActiveDirectory module is installed\r\n        if ((Get-Module -Name ActiveDirectory -ListAvailable -ErrorAction SilentlyContinue)) {\r\n            try {\r\n                # Try to import the ActiveDirectory module\r\n                Import-Module -Name ActiveDirectory\r\n            }\r\n            catch {\r\n                Write-Error -Message \"Ninja Agent could not access AD, either RSAT was not installed or that the agent does not have permissions to add and remove users from groups.\"\r\n                exit 5 # Access Denied exit code\r\n            }\r\n            try {\r\n                $User = Get-ADUser -Identity $UserName\r\n                Set-ADAccountPassword -Identity $User -Reset -NewPassword $(ConvertTo-SecureString -String $Password -AsPlainText -Force)    \r\n                Write-Host \"Reset Password for user: $UserName\"\r\n                exit 0\r\n            }\r\n            catch {\r\n                Write-Host \"Failed to Reset Password for user: $UserName\"\r\n                exit 1\r\n            }\r\n        }\r\n        else {\r\n            Write-Host \"User ($UserName) does not exist.\"\r\n            exit 1\r\n        }\r\n    }\r\n    else {\r\n        $User = Get-LocalUser -Name $UserName -ErrorAction SilentlyContinue\r\n        if ($User) {\r\n            try {\r\n                Set-LocalUser -Name $UserName -Password $(ConvertTo-SecureString -String $Password -AsPlainText -Force) -Confirm:$false\r\n                Write-Host \"Reset Password for user: $UserName\"\r\n                exit 0\r\n            }\r\n            catch {\r\n                Write-Host \"Failed to Reset Password for user: $UserName\"\r\n                exit 1\r\n            }\r\n        }\r\n        else {\r\n            Write-Host \"User ($UserName) does not exist.\"\r\n            exit 1\r\n        }    \r\n    }\r\n}\r\n    \r\nend {}<\/pre>\n<p>&nbsp;<\/p>\n\n<div class=\"in-context-cta\"><p style=\"text-align: center;\">Acesse mais de 300 scripts no NinjaOne Dojo<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.ninjaone.com\/freetrialform\/\">Obter acesso<\/a><\/p>\n<\/div>\n<h2>Detalhamento<\/h2>\n<p>Par\u00e2metros: O script come\u00e7a definindo os par\u00e2metros necess\u00e1rios, ou seja, o UserName e a Password. H\u00e1 tamb\u00e9m uma chave opcional para IsDomainUser que, quando usada, especifica que a opera\u00e7\u00e3o se destina a um usu\u00e1rio do Active Directory.<\/p>\n<h3>Inicializa\u00e7\u00e3o:<\/h3>\n<p>Antes da opera\u00e7\u00e3o principal, o script verifica se est\u00e1 sendo executado com privil\u00e9gios de administrador. Isso \u00e9 feito usando a fun\u00e7\u00e3o Test-IsElevated, que verifica a fun\u00e7\u00e3o de execu\u00e7\u00e3o atual do script.<\/p>\n<h3>Processo:<\/h3>\n<p>Dependendo do valor da chave IsDomainUser, o script se divide em duas opera\u00e7\u00f5es distintas:<\/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>Active Directory:<\/strong> Se a op\u00e7\u00e3o IsDomainUser estiver definida, o script verificar\u00e1 a presen\u00e7a do m\u00f3dulo ActiveDirectory, importar\u00e1 o m\u00f3dulo e tentar\u00e1 redefinir a senha do usu\u00e1rio no Active Directory.<\/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>Usu\u00e1rio local:<\/strong> Sem a op\u00e7\u00e3o IsDomainUser, o script visa um usu\u00e1rio local, verificando sua exist\u00eancia e tentando redefinir a senha.<\/li>\n<\/ul>\n<h2>Casos de uso em potencial<\/h2>\n<p>Imagine um administrador de TI, John, gerenciando a infraestrutura de rede de uma empresa de m\u00e9dio porte. Ele recebeu v\u00e1rias solicita\u00e7\u00f5es de funcion\u00e1rios que esqueceram suas senhas. Em vez de redefini-los manualmente por meio da GUI, John usa este script. Com um \u00fanico comando, ele agora pode redefinir a senha de cada usu\u00e1rio, economizando tempo e garantindo uma abordagem consistente.<\/p>\n<h2>Compara\u00e7\u00f5es<\/h2>\n<p>Tradicionalmente, a redefini\u00e7\u00e3o de senhas no Windows ou no Active Directory exigiria ferramentas baseadas em GUI, como &#8220;Gerenciamento de computadores&#8221; para usu\u00e1rios locais ou &#8220;Usu\u00e1rios e computadores do Active Directory&#8221; para usu\u00e1rios do AD. Embora essas ferramentas sejam robustas e ricas em recursos, elas geralmente envolvem v\u00e1rias etapas. Esse script do PowerShell oferece uma abordagem de linha de comando mais simplificada, que pode ser facilmente integrada aos fluxos de trabalho de automa\u00e7\u00e3o.<\/p>\n<h2>Implica\u00e7\u00f5es<\/h2>\n<p>Embora o script ofere\u00e7a efici\u00eancia, ele tamb\u00e9m carrega o peso da seguran\u00e7a. O uso indevido pode resultar em acesso n\u00e3o intencional ou bloqueio de contas. Certifique-se sempre de que as senhas sejam redefinidas de forma respons\u00e1vel e com o conhecimento do usu\u00e1rio.<\/p>\n<h2>Recomenda\u00e7\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\">Sempre fa\u00e7a um backup antes de fazer altera\u00e7\u00f5es em grande escala.<\/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\">Teste o script em um ambiente controlado antes de us\u00e1-lo na produ\u00e7\u00e3o.<\/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\">Use senhas fortes e exclusivas ao redefinir.<\/li>\n<\/ul>\n<h2>Considera\u00e7\u00f5es finais<\/h2>\n<p>Para os profissionais de TI que buscam mais automa\u00e7\u00e3o e opera\u00e7\u00f5es simplificadas, ferramentas como o NinjaOne podem complementar esse script. A NinjaOne fornece <a href=\"https:\/\/www.ninjaone.com\/pt-br\/gestao-ti-empresarial\/\">solu\u00e7\u00f5es<\/a> robustas <a href=\"https:\/\/www.ninjaone.com\/pt-br\/gestao-ti-empresarial\/\">de gerenciamento de TI<\/a> que se integram bem a scripts personalizados como esse, permitindo que os profissionais obtenham o m\u00e1ximo de sua infraestrutura.&nbsp;Garantir que os usu\u00e1rios possam acessar suas contas com seguran\u00e7a \u00e9 fundamental no gerenciamento de TI. Ao aproveitar o PowerShell e ferramentas como o NinjaOne, as complexidades de tarefas como redefini\u00e7\u00f5es de senha podem ser reduzidas, permitindo que as equipes de TI se concentrem em quest\u00f5es mais urgentes.<\/p>\n","protected":false},"author":35,"featured_media":144352,"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-810788","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\/810788","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=810788"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/media\/144352"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/media?parent=810788"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/operating_system?post=810788"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/use_cases?post=810788"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}