🛡️ Windows VSS 快照管理专家 (VSS Manager)
掌控磁盘的时间维度,让数据无惧误删与崩溃。
📖 工具简介
VSS Manager 是一款基于 Windows 卷影复制服务(Volume Shadow Copy Service)开发的专业级管理工具。它通过 PowerShell 深度调用底层接口,将原本隐藏在系统深处、仅供服务器运维使用的“快照”技术,封装成一个交互直观、操作简便的控制台。
无论是由于软件测试、系统误操作还是数据被恶意篡改,您都可以利用本工具随时“穿越”回过去,秒级找回数据。
🚀 脚本核心功能
1. 即时快照创建 (Live Snapshot)
2. 全局视图管理 (Global Overview)
3. 极速挂载与数据提取 (Smart Mount)
4. 空间与服务自检 (Auto Config)
5. 安全清理与维护 (Secure Cleanup)
支持单条删除、指定盘符清空或全系统快照核平清理。
自动解除关联的挂载目录,保持系统环境整洁。
🛠️ 适用场景
软件测试:在安装高风险或未知软件前建立快照,随时对比文件变化。
误删找回:手滑删除了重要文档?直接从快照镜像中拷贝回来。
病毒防御:在遭受小规模感染或配置篡改后,作为恢复数据的最后一道防线。
开发调试:快速回滚配置文件或数据库文件的状态。
🔍 索引关键词 (Keywords)
Windows VSS 卷影副本管理 磁盘快照 数据恢复 PowerShell 运维脚本 文件回滚 快照挂载 系统还原点管理 Shadow Copy 磁盘保护
💡 开发者说明
本工具采用 PowerShell 原生开发,无需安装任何第三方依赖。通过严格的对象化校验与正则过滤,确保在管理底层硬件卷时的安全性与稳定性。
提示:建议在进行大规模系统变更前,优先使用本工具创建快照,为数据安全增加一层保险。
保存后右键poweshell运行脚本。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
| # ========================================== # VSS 快照高级管理控制台 v3.2 (功能完备版) # ==========================================
# --- 1. 自动提权 --- if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) { Write-Host "检测到普通权限,正在呼叫管理员身份..." -ForegroundColor Yellow Start-Sleep -Seconds 1 Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs Exit }
$MountBaseDir = "C:\VSS_Mounts"
function Format-WmiDate($wmiDate) { if ([string]::IsNullOrWhiteSpace($wmiDate)) { return "未知时间" } try { return [Management.ManagementDateTimeconverter]::ToDateTime($wmiDate).ToString("yyyy-MM-dd HH:mm:ss") } catch { return "时间格式异常" } }
# --- 2. 核心大升级:全局快照扫描 --- function Get-AllValidSnapshots { $volumes = Get-WmiObject Win32_Volume | Where-Object { $_.DriveLetter -ne $null } $volMap = @{} foreach ($v in $volumes) { $key = $v.DeviceID.TrimEnd('\').ToLower() $volMap[$key] = $v.DriveLetter }
$shadows = Get-WmiObject Win32_ShadowCopy $validList = @() if ($null -ne $shadows) { foreach ($s in $shadows) { if ($s.ID -match "^\{[A-Fa-f0-9\-]{36}\}$" -and !([string]::IsNullOrWhiteSpace($s.ID))) { $lookupKey = $s.VolumeName.TrimEnd('\').ToLower() $drive = $volMap[$lookupKey] if ([string]::IsNullOrEmpty($drive)) { $drive = "未知盘" }
$validList += [PSCustomObject]@{ Drive = $drive ID = $s.ID Date = Format-WmiDate $s.InstallDate DeviceObject = $s.DeviceObject } } } } if ($validList.Count -eq 0) { return @() } return @($validList | Sort-Object Drive, Date -Descending) }
# --- 3. 辅助防呆输入 --- function Get-CreateDriveInput { while ($true) { $input = Read-Host "`n请输入目标盘符 (例如 D, 输入 'b' 返回菜单)" if ($input -eq 'b') { return $null } $drive = $input.Trim().ToUpper() if ($drive -match "^[A-Z]$") { return $drive + ":" } else { Write-Host "⚠️ 输入格式错误,请只输入一个英文字母。" -ForegroundColor Red } } }
function Show-Menu { Clear-Host Write-Host "=========================================" -ForegroundColor Cyan Write-Host " VSS 快照高级管理控制台 v3.2 " -ForegroundColor Yellow Write-Host "=========================================" -ForegroundColor Cyan Write-Host " [1] 创建新快照 (Create)" Write-Host " [2] 全局总览并【挂载】快照 (Mount)" Write-Host " [3] 全局总览并【删除】快照 (Delete / All)" Write-Host " [4] 查看底层物理全表 (Debug List)" Write-Host " [5] 开启 VSS 服务并配置磁盘保护 (Service)" Write-Host " [0] 安全退出 (Exit)" Write-Host "=========================================" -ForegroundColor Cyan }
# --- 4. 核心业务 --- while ($true) { Show-Menu $choice = Read-Host "请选择操作编号"
switch ($choice) { '1' { $drive = Get-CreateDriveInput if ($null -ne $drive) { Write-Host "正在为 $drive 调度 VSS 服务创建快照..." -ForegroundColor Yellow $res = (Get-WmiObject -list Win32_ShadowCopy).Create("$drive\", "ClientAccessible") if ($res.ReturnValue -eq 0) { Write-Host "✅ 快照创建成功!" -ForegroundColor Green } else { Write-Host "❌ 创建失败!错误码: $($res.ReturnValue)" -ForegroundColor Red Write-Host "提示:请确保已通过选项 [5] 开启了 $drive 的磁盘保护空间。" -ForegroundColor Gray } } Pause }
'2' { $list = @(Get-AllValidSnapshots) if ($list.Count -eq 0) { Write-Host "`n❌ 当前系统没有任何有效的快照记录。" -ForegroundColor Red } else { Write-Host "`n--- 当前系统全局有效快照一览 ---" -ForegroundColor Cyan for ($i=0; $i -lt $list.Count; $i++) { Write-Host " [$($i+1)] 来源: $($list[$i].Drive) | 创建时间: $($list[$i].Date)" } while ($true) { $idx = Read-Host "`n请输入要挂载的编号 (输入 'b' 取消)" if ($idx -eq 'b') { break } if ($idx -match "^\d+$" -and $idx -ge 1 -and $idx -le $list.Count) { $selected = $list[$idx-1] $path = $selected.DeviceObject + "\" $targetFolder = "$MountBaseDir\Snapshot_$($selected.Drive[0])" if (Test-Path $targetFolder) { cmd /c rmdir "`"$targetFolder`"" } if (!(Test-Path $MountBaseDir)) { New-Item -ItemType Directory -Path $MountBaseDir | Out-Null } cmd /c mklink /d "`"$targetFolder`"" "`"$path`"" > $null if ($LASTEXITCODE -eq 0) { Write-Host "✅ 已挂载至: $targetFolder" -ForegroundColor Green Invoke-Item $targetFolder } break } else { Write-Host "⚠️ 编号不存在。" -ForegroundColor Red } } } Pause }
'3' { $list = @(Get-AllValidSnapshots) if ($list.Count -eq 0) { Write-Host "`n❌ 当前系统没有任何可以删除的快照。" -ForegroundColor Red } else { Write-Host "`n--- 当前系统全局有效快照一览 ---" -ForegroundColor Red for ($i=0; $i -lt $list.Count; $i++) { Write-Host " [$($i+1)] 来源: $($list[$i].Drive) | 时间: $($list[$i].Date) | ID: $($list[$i].ID)" } while ($true) { $idx = Read-Host "`n请输入要删除的编号 (输入盘符如 'C', 输入 'all' 删除全部, 'b' 取消)" if ($idx -eq 'b') { break } if ($idx -eq 'all') { Write-Host "⚠️ 警告:正在物理抹除系统内【所有】卷影副本..." -ForegroundColor Yellow vssadmin delete shadows /all /quiet Write-Host "✅ 全局快照已清理。" -ForegroundColor Green break } if ($idx -match "^[a-zA-Z]$") { $drive = $idx.ToUpper() + ":" vssadmin delete shadows /for=$drive /quiet Write-Host "✅ 已清空 $drive 的所有快照。" -ForegroundColor Green break } if ($idx -match "^\d+$" -and $idx -ge 1 -and $idx -le $list.Count) { vssadmin delete shadows /shadow=$($list[$idx-1].ID) /quiet Write-Host "✅ 指定快照已删除。" -ForegroundColor Green break } } } Pause }
'4' { vssadmin list shadows Pause }
'5' { Write-Host "`n--- VSS 服务与磁盘保护配置 ---" -ForegroundColor Cyan # 1. 激活 VSS 核心服务 Write-Host "[1/2] 正在检查 Volume Shadow Copy 服务..." -ForegroundColor Yellow Set-Service VSS -StartupType Automatic Start-Service VSS -ErrorAction SilentlyContinue Write-Host "✅ VSS 服务已设定为自动启动并已尝试开启。" -ForegroundColor Green
# 2. 磁盘保护空间引导 $drive = Get-CreateDriveInput if ($null -ne $drive) { Write-Host "`n当前磁盘: $drive" -ForegroundColor White Write-Host "提示:创建快照前,Windows 需要在该盘分配一定的‘阴影存储空间’。" -ForegroundColor Gray $maxSize = Read-Host "请输入要分配的最大保护空间 (例如: 5GB, 或 10%, 直接回车则设为不限)" $sizeParam = if ([string]::IsNullOrWhiteSpace($maxSize)) { "unbounded" } else { $maxSize } # 尝试调整空间(如果不存在则先创建) Write-Host "正在配置磁盘保护空间..." -ForegroundColor Yellow vssadmin resize shadowstorage /for=$drive /on=$drive /maxsize=$sizeParam 2>$null if ($LASTEXITCODE -ne 0) { # 如果 resize 失败,可能是还没初始化,尝试 add vssadmin add shadowstorage /for=$drive /on=$drive /maxsize=$sizeParam 2>$null } if ($LASTEXITCODE -eq 0) { Write-Host "✅ $drive 磁盘保护空间配置成功 ($sizeParam)!" -ForegroundColor Green Write-Host "现在您可以返回选项 [1] 创建快照了。" -ForegroundColor Green } else { Write-Host "❌ 配置失败!可能是权限不足或参数格式错误。" -ForegroundColor Red } } Pause }
'0' { Exit } } }
|