{"id":22363207,"url":"https://github.com/oanderoficial/clean-system-server-","last_synced_at":"2025-03-26T15:18:04.724Z","repository":{"id":159006597,"uuid":"577008038","full_name":"oanderoficial/clean-system-server-","owner":"oanderoficial","description":"clean-system-server ","archived":false,"fork":false,"pushed_at":"2024-06-05T18:19:22.000Z","size":17,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-31T16:22:37.281Z","etag":null,"topics":["clean","clear","powershell","powershell-script","system","windows"],"latest_commit_sha":null,"homepage":"","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oanderoficial.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-12-11T17:34:19.000Z","updated_at":"2024-06-05T18:19:25.000Z","dependencies_parsed_at":null,"dependency_job_id":"31279ce6-7346-4ef3-83a0-1bf6405ff3f8","html_url":"https://github.com/oanderoficial/clean-system-server-","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oanderoficial%2Fclean-system-server-","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oanderoficial%2Fclean-system-server-/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oanderoficial%2Fclean-system-server-/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oanderoficial%2Fclean-system-server-/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oanderoficial","download_url":"https://codeload.github.com/oanderoficial/clean-system-server-/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245678901,"owners_count":20654738,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["clean","clear","powershell","powershell-script","system","windows"],"created_at":"2024-12-04T17:14:05.675Z","updated_at":"2025-03-26T15:18:04.703Z","avatar_url":"https://github.com/oanderoficial.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1\u003e clean-system-server \u003c/h1\u003e\n\n\n\u003cp\u003e Esse código tem como objetivo limpar a pasta de cache do SCCM (System Center Configuration Manager). Ele faz isso verificando os arquivos na pasta de cache e os objetos WMI associados, e excluindo aqueles que não são referenciados há mais de 30 dias. Além disso, ele remove pastas e objetos WMI órfãos que não têm correspondência na pasta de cache no disco. \u003c/p\u003e\n\n\u003cstrong\u003e Obter o Caminho do Cache do SCCM: \u003c/strong\u003e\n\n```ps1\n$SCCMCachePath = ([wmi]\"ROOT\\ccm\\SoftMgmtAgent:CacheConfig.ConfigKey='Cache'\").Location\n```\n\u003cp\u003e Esta linha usa o WMI (Windows Management Instrumentation) para recuperar a localização do cache do SCCM do registro. \u003c/p\u003e\n\n\u003cstrong\u003e Verificar a Existência do Caminho: \u003c/strong\u003e\n\n```ps1\nif (!(Test-Path $SCCMCachePath)) {...}\n```\n\n\u003cp\u003e Este bloco verifica se o caminho do cache recuperado existe e é acessível usando o cmdlet  \u003cstrong\u003eTest-Path \u003c/strong\u003e.\u003c/p\u003e\n\u003cp\u003e Se não, uma mensagem de erro é escrita e o script é encerrado.\u003c/p\u003e\n\n\u003cstrong\u003e Obter Objetos de Cache Obsoletos: \u003c/strong\u003e\n```ps1\n$StaleCacheObjects = Get-WmiObject -Query \"SELECT * FROM CacheInfoEx\" -Namespace \"ROOT\\ccm\\SoftMgmtAgent\" | Where-Object { ... }\n```\n\u003cp\u003e Esta linha recupera todas as informações do cache usando \u003cstrong\u003eGet-WmiObject \u003c/strong\u003e com a classe \u003cstrong\u003eCacheInfoEx \u003c/strong\u003e no namespace \u003cstrong\u003eROOT\\ccm\\SoftMgmtAgent \u003c/strong\u003e. \u003c/p\u003e\n\u003cp\u003eA cláusula \u003cstrong\u003eWhere-Object \u003c/strong\u003e subsequente filtra os resultados para objetos onde a diferença entre a data atual e a propriedade \u003cstrong\u003eLastReferenced\u003c/strong\u003e  (convertida em um objeto \u003cstrong\u003edatetime\u003c/strong\u003e) é maior que 30 dias. Essencialmente, ele encontra objetos de cache não acessados em mais de 30 dias.\u003c/p\u003e\n\n\u003cstrong\u003e Excluir Objetos Obsoletos do Disco: \u003c/strong\u003e\n```ps1\nforeach ($StaleCacheObject in $StaleCacheObjects) {... }\n```\n\u003cp\u003eEste loop itera por cada objeto de cache obsoleto encontrado na etapa anterior.\u003c/p\u003e\n\u003cp\u003eDentro do loop:\u003c/p\u003e\n\n```ps1 \nRemove-Item -Path $StaleCacheObject.Location -Recurse -Force \n```\n\u003cp\u003eTenta excluir a localização do objeto (o arquivo ou pasta) do disco.\u003c/p\u003e\n\n\u003cp\u003e \u003cstrong\u003e-Recurse \u003c/strong\u003e garante a exclusão de subpastas dentro da localização do objeto de cache.\u003c/p\u003e\n\u003cp\u003e \u003cstrong\u003e-Force \u003c/strong\u003e ignora solicitações de confirmação durante a exclusão.\u003c/p\u003e\n\u003cp\u003eO bloco \u003cstrong\u003etry...catch \u003c/strong\u003e lida com exceções potenciais (erros) durante a exclusão.\u003c/p\u003e\n\u003cp\u003eSe um erro ocorrer, ele grava uma mensagem de erro com a localização do objeto.\u003c/p\u003e\n\n\u003cstrong\u003e  Excluir Objetos Obsoletos do WMI (Opcional): \u003c/strong\u003e\n\n\u003cp\u003eO bloco \u003cstrong\u003etry...catch\u003c/strong\u003e tenta excluir os objetos de cache obsoletos do repositório WMI usando \u003cstrong\u003eRemove-WmiObject\u003c/strong\u003e. \u003c/p\u003e\n\n\u003cp\u003eEsta etapa é opcional e pode não ser necessária dependendo de seus requisitos.\u003c/p\u003e\n\u003cp\u003eSe um erro ocorrer, ele grava uma mensagem de erro genérica sobre a falha na exclusão do WMI.\u003c/p\u003e\n\n\u003ch2\u003e \u003cstrong\u003e Código \u003c/strong\u003e \u003c/h2\u003e\n\n``` ps1\n\n# Get the SCCM cache path\n$SCCMCachePath = ([wmi]\"ROOT\\ccm\\SoftMgmtAgent:CacheConfig.ConfigKey='Cache'\").Location\n\n# Check if the cache path exists and is accessible\nif (!(Test-Path $SCCMCachePath))\n{\n    Write-Error \"The SCCM cache path does not exist or is not accessible: $SCCMCachePath\"\n    return\n}\n\n# Get cache objects that have not been referenced for more than 30 days\n$StaleCacheObjects = Get-WmiObject -Query \"SELECT * FROM CacheInfoEx\" -Namespace \"ROOT\\ccm\\SoftMgmtAgent\" | Where-Object { ([datetime](Date) - ([System.Management.ManagementDateTimeConverter]::ToDateTime($_.LastReferenced))).Days -gt 30  }\n\n# Delete stale cache objects from disk\nforeach ($StaleCacheObject in $StaleCacheObjects)\n{\n    try\n    {\n        Remove-Item -Path $StaleCacheObject.Location -Recurse -Force\n    }\n    catch [System.Exception]\n    {\n        Write-Error \"Failed to delete stale cache object from disk: $($StaleCacheObject.Location)\"\n    }\n}\n\n# Delete stale cache objects from WMI\ntry\n{\n    $StaleCacheObjects | Remove-WmiObject\n}\ncatch [System.Exception]\n{\n    Write-Error \"Failed to delete stale cache objects from WMI.\"\n}\n\n# Get all cached folders from disk\n$\n\n```\n\n# Limpeza de Atualizações do Windows\n\n\u003cstrong\u003e Dism.exe \u003c/strong\u003e \n\u003cbr\u003e\n\u003cbr\u003e\n\u003cstrong\u003e Reduzir o Tamanho da Pasta WinSxS \u003c/strong\u003e \n\u003cbr\u003e\n- Abra o Prompt de Comando como administrador.\n- Execute os seguintes comandos para limpar as atualizações\n\u003cbr\u003e\n\n\u003cstrong\u003e  Analisar a pasta WinSxS e fornecer um relatório sobre o uso de espaço: \u003c/strong\u003e\n\n```cmd\nDism.exe /online /Cleanup-Image /AnalyzeComponentStore\n```\n\u003cstrong\u003e Remover os componentes obsoletos e reduzir o tamanho da pasta: \u003c/strong\u003e\n```cmd\nDISM.exe /Online /Cleanup-Image /StartComponentCleanup /ResetBase\n```\n\u003cstrong\u003e Remove pacotes de service pack substituídos: \u003c/strong\u003e \n```cmd\ndism.exe /online /Cleanup-Image /SPSuperseded\n```\n\u003cstrong\u003e Referência: https://learn.microsoft.com/pt-br/windows-hardware/manufacture/desktop/clean-up-the-winsxs-folder?view=windows-11 \u003c/strong\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foanderoficial%2Fclean-system-server-","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foanderoficial%2Fclean-system-server-","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foanderoficial%2Fclean-system-server-/lists"}