{"id":809299,"date":"2026-05-18T07:38:24","date_gmt":"2026-05-18T07:38:24","guid":{"rendered":"https:\/\/www.ninjaone.com\/?post_type=script_hub&#038;p=809299"},"modified":"2026-05-18T07:38:24","modified_gmt":"2026-05-18T07:38:24","slug":"access-store-windows-user-profile-sizes-powershell","status":"publish","type":"script_hub","link":"https:\/\/www.ninjaone.com\/pt-br\/script-hub\/access-store-windows-user-profile-sizes-powershell\/","title":{"rendered":"Como acessar e armazenar tamanhos de perfis de usu\u00e1rio do Windows com o PowerShell"},"content":{"rendered":"<p>\u00c9 ineg\u00e1vel que o PowerShell revolucionou a maneira como os profissionais de TI gerenciam os sistemas Windows, <a href=\"https:\/\/www.ninjaone.com\/blog\/it-process-automation-common-it-tasks-to-automate\/\">automatizam tarefas rotineiras<\/a> e se aprofundam nos diagn\u00f3sticos do sistema. Hoje, vamos nos aprofundar em um script do PowerShell desenvolvido para <strong>avaliar o tamanho dos perfis de usu\u00e1rio no Windows<\/strong>, uma ferramenta crucial para administradores de sistemas e <a href=\"https:\/\/www.ninjaone.com\/what-is-an-msp\/\">provedores de servi\u00e7os gerenciados (MSPs)<\/a>.<\/p>\n<h2>Hist\u00f3rico<\/h2>\n<p>Com o aumento do big data e dos aplicativos cada vez mais sofisticados, o gerenciamento do armazenamento e a garantia da utiliza\u00e7\u00e3o eficiente do disco se tornaram fundamentais. Os profissionais de TI e os MSPs frequentemente enfrentam desafios decorrentes do ac\u00famulo de grandes quantidades de dados pelos usu\u00e1rios, \u00e0s vezes sem saber. Esse script aborda essa preocupa\u00e7\u00e3o, permitindo que os profissionais de TI determinem rapidamente os tamanhos dos perfis de usu\u00e1rio, garantindo o gerenciamento ideal do armazenamento e a integridade do sistema.<\/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    Updates a Custom Field with the total size of all User Profiles.\r\n    If the Max parameter is specified then it will return an exit code of 1\r\n     for any profile being over that Max threshold in GB.\r\n.DESCRIPTION\r\n    Updates a Custom Field with the total size of all User Profiles.\r\n    If the Max parameter is specified then it will return an exit code of 1\r\n     for any profile being over that Max threshold in GB.\r\n.EXAMPLE\r\n     -Max 60\r\n    Returns and exit code of 1 if any profile is over 60GB\r\n.EXAMPLE\r\n     -CustomField \"Something\"\r\n    Specifies the name of the custom field to update.\r\n.EXAMPLE\r\n    No Parameter needed.\r\n    Uses the default custom field name: TotalUsersProfileSize\r\n.OUTPUTS\r\n    None\r\n.NOTES\r\n    Minimum OS Architecture Supported: Windows 10, Windows Server 2016\r\n    Release Notes:\r\n    Initial Release\r\nBy using this script, you indicate your acceptance of the following legal terms as well as our Terms of Use at https:\/\/www.ninjaone.com\/terms-of-use.\r\n    Ownership Rights: NinjaOne owns and will continue to own all right, title, and interest in and to the script (including the copyright). NinjaOne is giving you a limited license to use the script in accordance with these legal terms. \r\n    Use Limitation: You may only use the script for your legitimate personal or internal business purposes, and you may not share the script with another party. \r\n    Republication Prohibition: Under no circumstances are you permitted to re-publish the script in any script library or website belonging to or under the control of any other software provider. \r\n    Warranty Disclaimer: The script is provided \u201cas is\u201d and \u201cas available\u201d, without warranty of any kind. NinjaOne makes no promise or guarantee that the script will be free from defects or that it will meet your specific needs or expectations. \r\n    Assumption of Risk: Your use of the script is at your own risk. You acknowledge that there are certain inherent risks in using the script, and you understand and assume each of those risks. \r\n    Waiver and Release: You will not hold NinjaOne responsible for any adverse or unintended consequences resulting from your use of the script, and you waive any legal or equitable rights or remedies you may have against NinjaOne relating to your use of the script. \r\n    EULA: If you are a NinjaOne customer, your use of the script is subject to the End User License Agreement applicable to you (EULA).\r\n#&gt;\r\n\r\n[CmdletBinding()]\r\nparam (\r\n    [Parameter()]\r\n    [Alias(\"MaxSize\", \"Size\", \"ms\", \"m\", \"s\")]\r\n    [Double]\r\n    $Max,\r\n    [Parameter()]\r\n    [Alias(\"Custom\", \"Field\", \"cf\", \"c\", \"f\")]\r\n    [String]\r\n    $CustomField = \"TotalUsersProfileSize\"\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 Format-FileSize {\r\n        param($Length)\r\n        switch ($Length) {\r\n            { $_ \/ 1TB -gt 1 } { \"$([Math]::Round(($_ \/ 1TB),2)) TB\"; break }\r\n            { $_ \/ 1GB -gt 1 } { \"$([Math]::Round(($_ \/ 1GB),2)) GB\"; break }\r\n            { $_ \/ 1MB -gt 1 } { \"$([Math]::Round(($_ \/ 1MB),2)) MB\"; break }\r\n            { $_ \/ 1KB -gt 1 } { \"$([Math]::Round(($_ \/ 1KB),2)) KB\"; break }\r\n            Default { \"$_ Bytes\" }\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\r\n    $Profiles = Get-ChildItem -Path \"C:Users\"\r\n    $ProfileSizes = $Profiles | ForEach-Object {\r\n        [PSCustomObject]@{\r\n            Name   = $_.BaseName\r\n            Length = Get-ChildItem -Path $_.FullName -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue | Select-Object -Property Sum -ExpandProperty Sum\r\n        }\r\n    }\r\n    $Largest = $ProfileSizes | Sort-Object -Property Length -Descending | Select-Object -First 1\r\n\r\n    $Size = $ProfileSizes | Measure-Object -Property Length -Sum -ErrorAction SilentlyContinue | Select-Object -Property Sum -ExpandProperty Sum\r\n\r\n    $FormattedSize = Format-FileSize -Length $Size\r\n\r\n    $AllProfiles = $ProfileSizes | Sort-Object -Property Length -Descending | ForEach-Object {\r\n        $FormattedSizeUser = Format-FileSize -Length $_.Length\r\n        \"$($_.Name) $($FormattedSizeUser)\"\r\n    }\r\n\r\n    Write-Host \"All Profiles - $FormattedSize, $($AllProfiles -join ', ')\"\r\n\r\n    Ninja-Property-Set -Name $CustomField -Value \"$AllProfiles\"\r\n\r\n    if ($Max -and $Max -gt 0) {\r\n        if ($Largest.Length -gt $Max * 1GB) {\r\n            Write-Host \"Found profile over the max size of $Max GB.\"\r\n            Write-Host \"$($Largest.Name) profile is $($Largest.Length \/ 1GB) GB\"\r\n            exit 1\r\n        }\r\n    }\r\n    exit 0\r\n}\r\nend {}<\/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 em quest\u00e3o \u00e9 segmentado nas seguintes se\u00e7\u00f5es:<\/p>\n<ul>\n<li><strong>Vincula\u00e7\u00e3o e par\u00e2metros de cmdlet<\/strong>: O script come\u00e7a definindo par\u00e2metros, como <strong>Max<\/strong>, que define um limite opcional para o tamanho do perfil, e <strong>CustomField<\/strong>, que especifica o nome do campo personalizado a ser atualizado.<\/li>\n<li><strong>Iniciar se\u00e7\u00e3o<\/strong>: Aqui, temos duas fun\u00e7\u00f5es de utilidade:\n<ul>\n<li><strong>Test-IsElevated<\/strong>: Verifica se o script \u00e9 executado com privil\u00e9gios de administrador.<\/li>\n<li><strong>Format-FileSize<\/strong>: Converte bytes em um formato de tamanho de arquivo leg\u00edvel.<\/li>\n<\/ul>\n<\/li>\n<li><strong>Se\u00e7\u00e3o de Processos<\/strong>:\n<ul>\n<li>O script verifica se h\u00e1 privil\u00e9gios de administrador.<\/li>\n<li>Em seguida, ele obt\u00e9m todos os perfis de usu\u00e1rio de &#8220;C:Users&#8221; e calcula seus tamanhos.<\/li>\n<li>Os perfis s\u00e3o classificados e o tamanho total \u00e9 calculado.<\/li>\n<li>Os dados s\u00e3o enviados para o host e a fun\u00e7\u00e3o &#8220;Ninja-Property-Set&#8221; atualiza o campo personalizado.<\/li>\n<li>Se um par\u00e2metro Max for especificado, o script verificar\u00e1 se h\u00e1 perfis que excedem esse tamanho e sair\u00e1 com um c\u00f3digo apropriado.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>Casos de uso em potencial<\/h2>\n<p>Considere um MSP que supervisiona o armazenamento de um cliente corporativo. De repente, a empresa se depara com restri\u00e7\u00f5es de armazenamento. Em vez de optar por upgrades de armazenamento caros, o MSP usa esse script para identificar qualquer perfil de usu\u00e1rio superdimensionado. Munidos desses dados, eles podem entrar em contato com usu\u00e1rios ou departamentos espec\u00edficos para gerenciar e otimizar melhor o armazenamento.<\/p>\n<h2>Compara\u00e7\u00e3o<\/h2>\n<p>Tradicionalmente, a obten\u00e7\u00e3o de tamanhos cumulativos de perfis de usu\u00e1rios do Windows exigia navega\u00e7\u00e3o manual pelas propriedades, aplicativos de terceiros ou scripts complicados. Esse script do PowerShell oferece uma abordagem simplificada, usando as funcionalidades nativas do Windows para fornecer insights precisos e acion\u00e1veis.<\/p>\n<h2>Implica\u00e7\u00f5es<\/h2>\n<p>Embora esse script seja imensamente ben\u00e9fico, se n\u00e3o for utilizado corretamente, pode gerar problemas de privacidade. A extra\u00e7\u00e3o e o poss\u00edvel compartilhamento de tamanhos de perfis de usu\u00e1rios podem ser vistos como invasivos por alguns usu\u00e1rios. Al\u00e9m disso, para a seguran\u00e7a de TI, compreender os padr\u00f5es de armazenamento do usu\u00e1rio pode ser uma maneira proativa de detectar picos incomuns nos dados, o que pode indicar <a href=\"https:\/\/www.ninjaone.com\/it-hub\/seguranca-de-endpoints\/what-is-malware\/\">malware<\/a> ou uma poss\u00edvel <a href=\"https:\/\/www.ninjaone.com\/it-hub\/seguranca-de-endpoints\/what-is-a-data-breach\/\">viola\u00e7\u00e3o de dados<\/a>.<\/p>\n<h2>Recomenda\u00e7\u00f5es<\/h2>\n<ul>\n<li>Sempre execute scripts de diagn\u00f3stico fora do hor\u00e1rio de pico para evitar poss\u00edveis atrasos no sistema.<\/li>\n<li>Certifique-se de ter obtido as permiss\u00f5es necess\u00e1rias e informado as partes interessadas antes da execu\u00e7\u00e3o.<\/li>\n<li>Atualize e mantenha o script regularmente para atender \u00e0s mudan\u00e7as nas estruturas e nos requisitos do sistema.<\/li>\n<\/ul>\n<h2>Considera\u00e7\u00f5es finais<\/h2>\n<p>Uma <a href=\"https:\/\/www.ninjaone.com\/pt-br\/\">plataforma de gerenciamento de TI<\/a> como o NinjaOne pode aumentar significativamente a utilidade desse script, fornecendo aos profissionais de TI uma vis\u00e3o mais hol\u00edstica da integridade, do desempenho e das anomalias do sistema. A integra\u00e7\u00e3o desses scripts no NinjaOne pode oferecer percep\u00e7\u00f5es em tempo real, tornando o gerenciamento de armazenamento uma tarefa f\u00e1cil.<\/p>\n","protected":false},"author":35,"featured_media":142626,"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-809299","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\/809299","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=809299"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/media\/142626"}],"wp:attachment":[{"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/media?parent=809299"}],"wp:term":[{"taxonomy":"script_hub_category","embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/operating_system?post=809299"},{"taxonomy":"use_cases","embeddable":true,"href":"https:\/\/www.ninjaone.com\/pt-br\/wp-json\/wp\/v2\/use_cases?post=809299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}