powershell - Sysprep 后无法解密安全字符串

标签 powershell securestring sysprep

我正在为 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/

相关文章:

powershell - Nuget 包管理器控制台

c++ - 将 Powershell SecureString 传递给 C++ 程序?

c# - 在 C# dotnet 核心控制台应用程序中保护密码输入

azure - 在管道中使用 PowerShell 任务 Sysprep Azure VM

sql-server - 在不使用 sysprep azure-virtual-machine 的情况下将服务器迁移到 IaaS

azure - 如何将放置在 azure 文件存储中的 .csv 文件的内容复制到 powershell 变量?

powershell - powershell-Invoke-Command:FilePath参数的值必须是Windows PowerShell脚本文件

c# - 在 SQL Server 中存储、检索和验证密码 (SecureString)

windows - Windows.miracastview 上的 Sysprep 失败

windows - Windows 开发人员应该知道命令行吗?