
专门针对 Windows Server 2012 设计。它会自动扫描所有磁盘的卷影副本Shadow Copies占用情况并安全地清理旧数据最后汇报释放了多少空间。 脚本功能自动扫描检查所有磁盘的卷影存储占用。安全清理删除除最新一份以外的所有旧卷影副本。空间限制将卷影副本最大占用限制为磁盘的5%防止再次爆满。结果汇报显示清理前后的空间变化。 使用方法在桌面新建一个文本文件命名为Clean_SVI.ps1。将下方代码完整复制进去# Windows Server 2012 System Volume Information 安全清理脚本 # 必须以管理员身份运行 if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] Administrator)) { Write-Warning 请右键点击 PowerShell选择【以管理员身份运行】 pause exit } Write-Host -ForegroundColor Cyan Write-Host System Volume Information 安全清理工具 -ForegroundColor Cyan Write-Host -ForegroundColor Cyan Write-Host # 1. 显示当前卷影存储占用 Write-Host [1/3] 正在检查卷影副本占用情况... -ForegroundColor Yellow vssadmin list shadowstorage | Select-String -Pattern 卷|Volume|已用|Used|最大|Maximum | ForEach-Object { Write-Host $_.Line.Trim() } Write-Host # 2. 清理旧卷影副本保留最新的一个 Write-Host [2/3] 正在清理旧卷影副本保留最新1份... -ForegroundColor Yellow try { # 获取所有卷影副本 $shadows Get-WmiObject -Class Win32_ShadowCopy if ($shadows) { $count ($shadows | Measure-Object).Count Write-Host 发现 $count 个卷影副本正在清理... # 按安装日期排序保留最新的删除其余的 $shadows | Sort-Object InstallDate -Descending | Select-Object -Skip 1 | ForEach-Object { Write-Host 删除: $($_.DeviceObject) -ForegroundColor Gray $_.Delete() | Out-Null } Write-Host 清理完成 -ForegroundColor Green } else { Write-Host 未发现卷影副本无需清理。 -ForegroundColor Green } } catch { Write-Warning 清理过程出现警告通常是因为文件被占用可忽略。 } Write-Host # 3. 限制卷影存储大小防止未来爆满 Write-Host [3/3] 正在设置卷影存储上限磁盘的 5%... -ForegroundColor Yellow $drives Get-WmiObject -Class Win32_LogicalDisk -Filter DriveType3 foreach ($drive in $drives) { $driveLetter $drive.DeviceID $maxSize [math]::Round($drive.Size * 0.05 / 1GB, 2) Write-Host 设置 $driveLetter 上限为 ${maxSize}GB... -ForegroundColor Gray vssadmin resize shadowstorage /on$driveLetter /for$driveLetter /MaxSize${maxSize}GB | Out-Null } Write-Host Write-Host -ForegroundColor Cyan Write-Host 操作完成请检查磁盘空间是否释放。 -ForegroundColor Green Write-Host -ForegroundColor Cyan pause右键点击Clean_SVI.ps1→ 选择使用 PowerShell 运行或右键 PowerShell → 以管理员身份运行 → 输入.\Clean_SVI.ps1。⚠️ 注意事项不要手动删除文件夹脚本只清理里面的“卷影副本”不会动系统索引等核心文件。服务器环境如果你的服务器正在运行SQL Server或Exchange它们可能正在使用卷影副本进行备份。建议在非备份窗口期运行此脚本。保留策略脚本默认保留1份最新副本。如果你需要保留更多修改代码中的Select-Object -Skip 1为Skip 3保留3份。