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

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

相关推荐
Vex2une15 小时前
JDK 8 下载安装与环境变量配置完整指南(Windows新手图文教程)
java·windows·环境配置·环境变量·jdk8·jdk下载安装·java入门教程
星空孤辰21 小时前
【camera 008】android camera id 注册、状态监控等状态变化 全流程梳理
android·windows
全方位办公软件1 天前
Windows音频服务架构解析:AudioSrv与AudioEndpointBuilder排障
windows·命令行·powershell·音频服务·驱动修复·mmdevices·audiosrv
Vex2une2 天前
电脑装双系统怎么弄?Win+Win 与 Win+Linux 安装及启动菜单管理全攻略
linux·windows·电脑·uefi·双系统安装·bcdedit启动项
无情的西瓜皮2 天前
eMudhra 根证书自 11-16 起失去微软产品默认信任:4 步 PowerShell 自查你的 Windows 是否已收到变更(Win11 实测)
windows·powershell
Funlang3 天前
在 Windows NT 3.5 上跑 Fun
windows
xx z4 天前
directx修复工具下载(DirectX Repair 增强版 使用说明)
windows·系统·工具·软件
xx z4 天前
pcl2启动器下载(Minecraft PCL2 启动器 最新版 安装与使用说明)
windows·游戏·工具·软件
凯瑟琳.奥古斯特4 天前
我开源了一个 Windows 截图取字工具:全局热键 + 离线 OCR + 标注打码,不上传任何数据
windows·ocr
Funlang5 天前
在 Windows 95 上跑 Fun
windows