Windows powershell下实现空间释放

前提条件

  • 开启wmi,配置网卡,参考

创建一键清理脚本

  • PowerShell 脚本以管理员身份运行,关闭休眠释放磁盘空间,调用 DISM 清理系统旧组件,并停止服务后清除 Windows 更新缓存,最后恢复相关服务并输出运行状态。

    powershell-Windows-Clean-cache-space.ps1

    <# Powershell Clean up cache space
    +++++++++++++++++++++++++++++++++++++++++++++++++++++

    • _____ _____ _ _ _ +
    • | __ \ / ____| | | | |+
    • | |) |____ _____ _ | ( | |__ ___| | |+
    • | / _ \ \ /\ / / _ \ '__ | '_ \ / _ \ | |+
    • | | | (_) \ V V / __/ | ____) | | | | __/ | |+
    • || _/ _/_/ _|| |___/|| ||_|||+
    • +++++++++++++++++++++++++++++++++++++++++++++++++++

    #Clean up cache space

    .\powershell-Windows-Clean-cache-space.ps1

    #>

    Resume sleep mode

    powercfg /h on

    Write-Host "Sleep off" -ForegroundColor Green
    powercfg /h off

    Write-Host "DISM component cleaning" -ForegroundColor Green
    DISM /Online /Cleanup-Image /StartComponentCleanup

    Write-Host "Stop Windows update related services" -ForegroundColor Green
    Stop-Service -Name wuauserv -Force
    Stop-Service -Name bits -Force

    Write-Host "Update cache cleaning" -ForegroundColor Green
    downloadPath = "C:\Windows\SoftwareDistribution\Download" if(Test-Path downloadPath){
    Get-ChildItem -Path "$downloadPath*" -Recurse -Force -ErrorAction SilentlyContinue | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
    }

    Write-Host "start Windows update related services" -ForegroundColor Green
    Start-Service -Name wuauserv
    Start-Service -Name bits

    Write-Host "View service startup status" -ForegroundColor Green
    Get-Service wuauserv,bits

执行

复制代码
cd d:; .\powershell-Windows-Clean-cache-space.ps1

输出结果,验证磁盘空间变大了

相关推荐
AxureMost2 小时前
NeeView图像查看
windows
赵广陆9 小时前
Model I/O进阶
windows
问商十三载14 小时前
RAG 检索效果差怎么排查?2026 五层诊断法完整指南
开发语言·人工智能·windows·python·算法
Zguigo15 小时前
第25-26讲:计算机操作系统存储管理——分页机制、页表与快表(TLB)
linux·windows·笔记
垂直昵称21 小时前
多线程实现网页接口并发压力测试
linux·服务器·windows
%d%d21 天前
Windows 本地部署小红书 MCP + OpenAI Tunnel + ChatGPT 接入全流程
windows·chatgpt
90后小陈老师2 天前
Windows 10 下 Gitee SSH 连接配置详解(附常见问题解决)
windows·gitee·ssh
Light Gao2 天前
MCPHub 路由原理:一个入口如何管理并调用上百个 MCP Server
windows·microsoft
郭涤生2 天前
Windows + Ubuntu 双系统启动故障修复
linux·windows·ubuntu