Skip to content

掌控磁盘的时间维度,让数据无惧误删与崩溃。


📖 工具简介

VSS Manager 是一款基于 Windows 卷影复制服务(Volume Shadow Copy Service)开发的专业级管理工具。它通过 PowerShell 深度调用底层接口,将原本隐藏在系统深处、仅供服务器运维使用的“快照”技术,封装成一个交互直观、操作简便的控制台。

无论是由于软件测试、系统误操作还是数据被恶意篡改,您都可以利用本工具随时“穿越”回过去,秒级找回数据。


🚀 脚本核心功能

1. 即时快照创建 (Live Snapshot)

  • 无需关闭程序,无需停止工作。

  • 在系统运行状态下瞬间锁定磁盘全量状态,生成“只读镜像”。

2. 全局视图管理 (Global Overview)

  • 自动扫描全盘快照,精准映射 C、D、E 等各盘符对应关系。

  • 多维度展示创建时间与底层设备 ID,告别盲目操作。

3. 极速挂载与数据提取 (Smart Mount)

  • 支持将任意快照挂载为自定义目录。

  • 通过资源管理器直接访问“过去的磁盘”,实现单个文件或文件夹的秒级找回。

4. 空间与服务自检 (Auto Config)

  • 一键开启系统 VSS 服务。

  • 图形化引导配置各盘符的快照存储空间(Shadow Storage),确保快照创建成功。

5. 安全清理与维护 (Secure Cleanup)

  • 支持单条删除、指定盘符清空或全系统快照核平清理。

  • 自动解除关联的挂载目录,保持系统环境整洁。


🛠️ 适用场景

  • 软件测试:在安装高风险或未知软件前建立快照,随时对比文件变化。

  • 误删找回:手滑删除了重要文档?直接从快照镜像中拷贝回来。

  • 病毒防御:在遭受小规模感染或配置篡改后,作为恢复数据的最后一道防线。

  • 开发调试:快速回滚配置文件或数据库文件的状态。


🔍 索引关键词 (Keywords)

Windows VSS 卷影副本管理 磁盘快照 数据恢复 PowerShell 运维脚本 文件回滚 快照挂载 系统还原点管理 Shadow Copy 磁盘保护


💡 开发者说明

本工具采用 PowerShell 原生开发,无需安装任何第三方依赖。通过严格的对象化校验与正则过滤,确保在管理底层硬件卷时的安全性与稳定性。

提示:建议在进行大规模系统变更前,优先使用本工具创建快照,为数据安全增加一层保险。

保存后右键poweshell运行脚本。

text

# ==========================================
# 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 }
    }
}