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

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

相关推荐
2601_9623649724 分钟前
红外活体模组,Windows 设备安全身份入口解析
windows·安全·电脑
易点云徐源1 小时前
(已解决)Photoshop 2020 点击“选择主体”闪退:不用重装,1 个配置切回旧算法解决
windows·photoshop
云计算练习生2 小时前
什么是系统调用?为什么程序访问硬件必须经过它
linux·windows·操作系统·系统调用·操作系统原理
其实防守也摸鱼8 小时前
DeepSeek Harness 开源贡献手记:从入门到合入主线
服务器·数据库·windows·https·ssl
qqww15510 小时前
Win11更新后Edge卡顿掉帧?隐私窗口流畅解决办法
windows·edge·优化·卡顿
其实防守也摸鱼11 小时前
堆叠注入(Stacked Injection)详解
服务器·数据库·windows·https·ssl
郝学胜-神的一滴11 小时前
C++20模板元编程 05:吃透变参模板,解锁编译期万能参数能力
服务器·开发语言·c++·windows·vscode
是店小二呀13 小时前
鸿蒙PC_Dart-Sass-ohos适配全记录
linux·运维·windows
2601_962364971 天前
不止指纹和人脸:Windows Hello如何重塑PC生物识别安全?
windows·安全·电脑
ι:1 天前
单相桥式全控整流仿真从零复现教学
windows·学习·matlab·simulink