我正在为 Windows 7 镜像构建两个 PowerShell 脚本。在图像之前我运行 PRE-IMAGE.ps1
, 里面有这样一行:
$JoinDomainPassword = Read-Host -Prompt "Please enter the password for $joinDomainUser" -AsSecureString
$strPass = $joinDomainPassword | ConvertFrom-SecureString
然后我保存
$strPass
将字符串安全保存到注册表,然后运行 sysprep。使用 sysprep 重新启动后,
POST-IMAGE.ps1
然后拉$strPass
从注册表中,并有这样的一行:$strPass = $strPass | ConvertTo-SecureString
$credentials = New-Object System.Management.Automation.PSCredential ($JoinDomainUser, $strPass)
但是,
POST-IMAGE.ps1
中的这些行运行 convertto-securestring
时会出现“ key 无效”错误和 convertfrom-securestring
作为不同的 Windows 用户。 ( similiar to this question ) - 但这里的问题是我 -AM- 使用同一个用户在安全字符串之间进行转换。我猜这与 sysprep 有关 - 但我无法理解它。如果之前有人问过这个问题,我深表歉意,我发现了一些涉及部分内容的问题,但不要描述我的确切问题。
最佳答案
如果您没有为 ConvertFrom-SecureString 命令指定 key ,它将使用 DPAPI 来加密字符串。 Sysprep 显然重新初始化了 DPAPI 使用的 key 。来自 http://www.mombu.com/microsoft/security-crypto/t-local-machine-masterkey-in-dpapi-1053937-print.html
DPAPI will generate the local system master key during the specialization phase of sysprep.
关于powershell - Sysprep 后无法解密安全字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27808392/