改造开始前的完整状态,作为可回退的基点。此提交之后:Pester 175 项、零依赖套件 101 项全绿;PowerShell 5.1 尚不可用(源文件无 BOM)。 包含此前未提交的在制品:安全描述符套件、Hyper-V 实验环境(tools/lab)、agent 约定(AGENTS.md 与 docs/agents)。 .gitignore 增加 *.key / *.pfx:BackupConfig.psd1 的 PasswordFile 此前默认指向仓库内的 baknret.key,一次 git add -A 就会把口令提交进版本库。默认值在后续提交中改为空。
45 lines
1.8 KiB
PowerShell
45 lines
1.8 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
在 VM 内跑 tests\Restore-Drill.ps1,并把条目数组安全地传进去。
|
|
|
|
.DESCRIPTION
|
|
为什么需要这一层:跨进程传数组参数是坏的。
|
|
经 `pwsh -File Restore-Drill.ps1 -Entries A B C` 传进去时,只有第一个值能绑到
|
|
`[string[]]$Entries`,后面的会被当成多余的位置参数:
|
|
|
|
A positional parameter cannot be found that accepts argument '...'
|
|
|
|
而 JSON / 带引号的字符串又会在 Start-Process 拼命令行时被引号转义搞坏,
|
|
所以这里用 `;` 分隔的纯文本传条目,再在 PowerShell 内部用真正的数组绑定调用钻取脚本。
|
|
|
|
用法:pwsh -File run-drill.ps1 -BackupDir <归档目录> -ConfigPath <配置> -EntriesCsv 'A;B;C'
|
|
#>
|
|
|
|
[CmdletBinding()]
|
|
param(
|
|
[Parameter(Mandatory)][string]$BackupDir,
|
|
[Parameter(Mandatory)][string]$ConfigPath,
|
|
[string]$EntriesCsv = '',
|
|
[switch]$KeepWorkRoot,
|
|
[switch]$AllowChanged
|
|
)
|
|
|
|
$ErrorActionPreference = 'Continue'
|
|
|
|
$entries = @()
|
|
if ($EntriesCsv) {
|
|
$entries = @($EntriesCsv.Split(';') | Where-Object { $_ -and $_.Trim() } | ForEach-Object { $_.Trim() })
|
|
}
|
|
|
|
# 必须用**哈希表** splat:数组 splat 会把 -Entries A B C 拆成三个独立参数,
|
|
# 只有 A 绑得上,B 会被当成多余的位置参数(A positional parameter cannot be found ...)。
|
|
$drillParams = [ordered]@{
|
|
BackupDir = $BackupDir
|
|
ConfigPath = $ConfigPath
|
|
}
|
|
if ($entries.Count -gt 0) { $drillParams['Entries'] = $entries }
|
|
if ($KeepWorkRoot) { $drillParams['KeepWorkRoot'] = $true }
|
|
if ($AllowChanged) { $drillParams['AllowChanged'] = $true }
|
|
|
|
Write-Host ("[lab] 恢复演练:{0} 个条目 -> {1}" -f $entries.Count, ($entries -join ' | '))
|
|
& 'C:\BakNRet\tests\Restore-Drill.ps1' @drillParams |