创建加密文件并授予用户访问权限

时间:2021-06-03 07:39:22

标签: powershell

我使用下面的代码创建了一个加密的密码文件

# password vault.
$vault = "D:\pwd.txt"

# the password.
$password = "Passw0rd1#"

# save the password.
convertto-securestring -string $password -asplaintext -force | convertfrom-securestring | out-file $vault
# retrieve the password.
$securestring = convertto-securestring -string (get-content $vault)
$bstr = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($securestring)
$passwsord = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($bstr)

现在,当我使用我登录的 ID 执行此操作时,这工作正常。

如果我使用其他用户登录并尝试访问加密文件,我将无法访问该文件。

请让我知道如何通过代码或任何其他方式授予对文件的访问权限,使用登录到服务器的人应该能够访问该文件并对其进行解密。

0 个答案:

没有答案