创建注册表项 SID REG_BINARY

时间:2021-07-25 12:24:27

标签: windows powershell acl regedit

我正在通过 PowerShell 创建一个新的本地帐户并在其中创建他们的个人资料

Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\

也是。

我可以通过以下方式获取用户的 SID; ([System.Security.Principal.WindowsIdentity]::GetCurrent()).User.Value

但是,在用户的 SID 键中,有一个名为 SID 的值,类型为 REG_BINARY。这是如何创建的?有人可以帮我吗?

我需要这个的原因是我正在将域帐户迁移到本地用户并保留所有设置,但由于此密钥它不起作用。

这是我目前所拥有的:

pic1

这是缺少的关键,我不确定它来自哪里:

pic2

1 个答案:

答案 0 :(得分:3)

您可以将 SID 转换为其二进制表示并将其写入注册表,如下所示:

# Replace this with the actual target SID string
$SIDString = 'S-1-5-21-1518175382-1413263562-1473642471-31061' 

# Parse as SecurityIdentifier struct
$SID = [System.Security.Principal.SecurityIdentifier]::new($SIDString)

# Create a byte array to hold the binary representation
$binarySID = [byte[]]::new($SID.BinaryLength)

# Copy binary SID to byte array
$SID.GetBinaryForm($binarySID, 0)

# Write binary SID to registry
$path = "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\${SIDString}"
New-ItemProperty -Path $path -Name SID -PropertyType Binary -Value $binarySID
相关问题