{"id":810792,"date":"2026-05-21T11:59:00","date_gmt":"2026-05-21T11:59:00","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=810792"},"modified":"2026-05-21T11:59:00","modified_gmt":"2026-05-21T11:59:00","slug":"como-usar-o-powershell-para-encontrar-administradores-locais","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/pt-br\/script-hub\/como-usar-o-powershell-para-encontrar-administradores-locais\/","title":{"rendered":"Como usar o PowerShell para localizar administradores locais"},"content":{"rendered":"<p>Na era digital atual, a administra\u00e7\u00e3o de sistemas e o gerenciamento de seguran\u00e7a geralmente exigem o uso de scripts. Um aspecto vital da manuten\u00e7\u00e3o da seguran\u00e7a do sistema \u00e9 o controle dos administradores locais em m\u00e1quinas Windows. Usar o PowerShell para obter esses dados pode ser um divisor de \u00e1guas para muitos profissionais de TI. Leia este artigo para saber <strong>como usar o PowerShell para localizar administradores locais.&nbsp;<\/strong><\/p>\n<h2>Hist\u00f3rico<\/h2>\n<p>O PowerShell evoluiu como uma linguagem de script e um shell robustos. Especialmente para profissionais de TI e <a href=\"https:\/\/www.ninjaone.com\/what-is-an-msp\/\">provedores de servi\u00e7os gerenciados (MSPs)<\/a>, scripts como o fornecido tornam-se indispens\u00e1veis. Os MSPs geralmente gerenciam v\u00e1rios ambientes de clientes, o que torna dif\u00edcil monitorar cada detalhe manualmente. Ao utilizar scripts para obter informa\u00e7\u00f5es, como a lista de administradores locais, os MSPs podem garantir que somente indiv\u00edduos autorizados tenham acesso elevado, protegendo-se contra poss\u00edveis amea\u00e7as e atividades mal-intencionadas.<\/p>\n<h2>O roteiro<\/h2>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"powershell\">&lt;#\r\n.SYNOPSIS\r\n    Updates a custom field with a list of local admins.\r\n.DESCRIPTION\r\n    Updates a custom field with a list of local admins.\r\n.EXAMPLE\r\n    No parameter needed\r\n    \r\n    Local Admins Found: Administrator, kbohlander, TESTDomain Admins\r\n    Attempting to set Custom Field: LocalAdmins\r\n\r\nPARAMETER: -CustomField \"ReplaceWithAnyTextCustomField\"    \r\n    Updates the custom field you specified (defaults to \"LocalAdmins\"). The Custom Field needs to be writable by scripts (otherwise the script will report it as not found).\r\n\r\nPARAMETER: -Delimiter \"ReplaceWithYourDesiredDelimiter\"\r\n    Places whatever is entered encased of quotes between each user name. See below example.\r\n.EXAMPLE\r\n    -Delimiter \" - \"\r\n    \r\n    Local Admins Found: Administrator - kbohlander - TESTDomain Admins\r\n    Attempting to set Custom Field: LocalAdmins\r\n.OUTPUTS\r\n    None\r\n.NOTES\r\n    Minimum OS Architecture Supported: Windows 7, Windows Server 2008\r\n    Release Notes:\r\n    Switched to using net localgroup as it's the most reliable. Removed PowerShell 5.1 requirement.\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]$CustomField = \"LocalAdmins\",\r\n    [Parameter()]\r\n    [String]$Delimiter = ', '\r\n)\r\n\r\nbegin {\r\n    if ($env:customFieldName -and $env:customFieldName -notlike \"null\") { $CustomField = $env:customFieldName }\r\n    if ($env:delimiter -and $env:delimiter -notlike \"null\") { $Delimiter = $env:delimiter }\r\n    $CheckNinjaCommand = \"Ninja-Property-Set\"\r\n}\r\nprocess {\r\n    # Get objects in the Administrators group, includes user objects and groups\r\n    $Users = net.exe localgroup \"Administrators\" | Where-Object { $_ -AND $_ -notmatch \"command completed successfully\" } | Select-Object -Skip 4\r\n\r\n    if (-not $Users) {\r\n        Write-Error \"[Error] No user's found! This is extremely unlikely is something blocking access to 'net localgroup administrators'?\"\r\n        exit 1\r\n    }\r\n\r\n    Write-Host \"Local Admins Found (Users &amp; Groups): $($Users -join $Delimiter)\"\r\n    if ($(Get-Command $CheckNinjaCommand -ErrorAction SilentlyContinue).Name -like $CheckNinjaCommand -and -not [string]::IsNullOrEmpty($CustomField) -and -not [string]::IsNullOrWhiteSpace($CustomField)) {\r\n        Write-Host \"Attempting to set Custom Field: $CustomField\"\r\n        Ninja-Property-Set -Name $CustomField -Value $($Users -join $Delimiter)\r\n    }\r\n    else {\r\n        Write-Warning \"Unable to set customfield either due to legacy OS or this script is not running as an elevated user.\"\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 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>O script \u00e9 iniciado com a defini\u00e7\u00e3o de par\u00e2metros padr\u00e3o, principalmente visando a um campo personalizado chamado &#8220;LocalAdmins&#8221; e usando uma v\u00edrgula como <a href=\"https:\/\/www.ninjaone.com\/blog\/what-is-a-delimiter\/\">delimitador<\/a> padr\u00e3o. Veja como funciona:<\/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>Inicializa\u00e7\u00e3o<\/strong>: O script come\u00e7a configurando os comandos necess\u00e1rios,<strong>&#8220;Get-LocalGroupMember<\/strong>&#8221; para buscar membros de grupos locais e<strong>&#8220;Ninja-Property-Set<\/strong>&#8221; para definir propriedades no NinjaOne, uma renomada plataforma de gerenciamento de TI.<\/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>Obten\u00e7\u00e3o de administradores<\/strong>: No bloco de <strong>processo<\/strong>, o script verifica se o comando<strong>&#8220;Get-LocalGroupMember<\/strong>&#8221; est\u00e1 dispon\u00edvel. Em caso afirmativo, ele usa isso para buscar administradores locais. Caso contr\u00e1rio, o padr\u00e3o \u00e9 usar o comando <strong>net.exe<\/strong>.<\/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>Formata\u00e7\u00e3o da sa\u00edda<\/strong>: Depois de recuperar a lista de administradores, ele formata os nomes de usu\u00e1rio, separando-os de qualquer dom\u00ednio ou nome de m\u00e1quina.<\/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>Integra\u00e7\u00e3o com o NinjaOne<\/strong>: Por fim, o script verifica se o comando<strong>&#8220;Ninja-Property-Set<\/strong>&#8221; est\u00e1 dispon\u00edvel e, em seguida, atualiza o campo personalizado no NinjaOne com a lista de administradores locais.<\/li>\n<\/ul>\n<h2>Casos de uso em potencial<\/h2>\n<p>Imagine ser um administrador de TI de uma empresa de m\u00e9dio porte com uma for\u00e7a de trabalho remota em expans\u00e3o. Com os funcion\u00e1rios fazendo login em diferentes locais e dispositivos, torna-se crucial garantir que somente o pessoal autorizado tenha acesso administrativo. Ao implementar esse script, um profissional de TI pode obter a lista de todos os administradores locais em v\u00e1rias esta\u00e7\u00f5es de trabalho, o que lhe permite auditar o acesso e tomar medidas corretivas, se necess\u00e1rio.<\/p>\n<h2>Compara\u00e7\u00f5es<\/h2>\n<p>Embora existam v\u00e1rias maneiras de recuperar uma lista de administradores locais, como usar interfaces gr\u00e1ficas de usu\u00e1rio ou ferramentas de terceiros,<a href=\"https:\/\/www.ninjaone.com\/blog\/how-to-automate-tasks-with-powershell\/\">os scripts<\/a> do PowerShell<a href=\"https:\/\/www.ninjaone.com\/blog\/how-to-automate-tasks-with-powershell\/\">oferecem automa\u00e7\u00e3o<\/a>, escalabilidade e f\u00e1cil integra\u00e7\u00e3o. Por exemplo, enquanto a GUI nativa &#8220;Computer Management&#8221; permite verificar os administradores locais em uma \u00fanica esta\u00e7\u00e3o de trabalho, nosso script pode ser dimensionado para v\u00e1rias m\u00e1quinas, proporcionando uma maneira mais eficiente de obter esses dados, especialmente para MSPs que lidam com v\u00e1rios ambientes de clientes.<\/p>\n<h2>Implica\u00e7\u00f5es<\/h2>\n<p>Entender quem tem privil\u00e9gios administrativos \u00e9 fundamental para a seguran\u00e7a de TI. Administradores n\u00e3o autorizados ou desonestos podem fazer altera\u00e7\u00f5es no sistema, instalar software malicioso ou acessar informa\u00e7\u00f5es confidenciais. Ao monitorar e auditar regularmente os administradores locais, as organiza\u00e7\u00f5es podem reduzir significativamente os poss\u00edveis riscos \u00e0 seguran\u00e7a.<\/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\"><strong>Auditorias regulares<\/strong>: Execute esse script periodicamente para manter uma lista atualizada de administradores locais.<\/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>Integrar com o monitoramento<\/strong>: Integre a sa\u00edda com solu\u00e7\u00f5es de monitoramento para receber alertas sobre altera\u00e7\u00f5es na lista de administradores locais.<\/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>Documenta\u00e7\u00e3o<\/strong>: Mantenha a documenta\u00e7\u00e3o de todos os usu\u00e1rios aos quais foram concedidos direitos administrativos locais, garantindo que haja um motivo comercial v\u00e1lido para cada atribui\u00e7\u00e3o.<\/li>\n<\/ul>\n<h2>Considera\u00e7\u00f5es finais<\/h2>\n<p>Embora os scripts do PowerShell, como o fornecido, facilitem muito o processo de obten\u00e7\u00e3o e gerenciamento de administradores locais, plataformas como o NinjaOne elevam essas funcionalidades. O <a href=\"https:\/\/www.ninjaone.com\/pt-br\/integracoes\/\">recurso de integra\u00e7\u00e3o perfeita<\/a> do NinjaOne, aliado a <a href=\"https:\/\/www.ninjaone.com\/pt-br\/\">ferramentas robustas de gerenciamento de TI<\/a>, garante que os administradores de sistemas estejam sempre no controle, possam responder rapidamente \u00e0s mudan\u00e7as e garantir a seguran\u00e7a e o desempenho ideais do sistema.<\/p>\n","protected":false},"author":35,"featured_media":144365,"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-810792","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\/810792","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=810792"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/media\/144365"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/media?parent=810792"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/operating_system?post=810792"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/use_cases?post=810792"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}