2016-12-28 61 views
1

我們有多個需要技術用戶憑據的PowerShell腳本。如何在PowerShell中保存技術用戶的憑證

  • 什麼是安全地存儲這些證書/散列的好方法,同時讓每個有權限運行腳本的用戶都可以使用它們?

我們嘗試將散列作爲安全字符串,但這需要每個用戶散列憑證,因爲安全字符串與用戶的配置文件相關聯。

我是不成功的嘗試執行這樣的事情:

「運行腳本以管理員身份 - >單擊是對話框 - >開關技術用戶 - > unhash憑據 - >作爲登錄的用戶翻版 - >保存到文件」

(該用戶不具有管理員特權時)

我可以讓每個用戶輸入一次憑據,然後用戶特定的哈希值保存到一個文件。但我認爲這是我尚未找到的最佳做法。

回答

2
$username = "[email protected]" 
$pwdTxt = Get-Content "C:\temp\Stored_Password.txt" 
$securePwd = $pwdTxt | ConvertTo-SecureString 
$credObject = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securePwd 
# Now, $credObject is having the credentials stored and you can pass it wherever you want. 


## Import Password with AES 

$username = "[email protected]" 
$AESKey = Get-Content $AESKeyFilePath 
$pwdTxt = Get-Content $SecurePwdFilePath 
$securePwd = $pwdTxt | ConvertTo-SecureString -Key $AESKey 
$credObject = New-Object System.Management.Automation.PSCredential -ArgumentList $username, $securePwd 

# Now, $credObject is having the credentials stored with AES Key and you can pass it wherever you want. 

你可以把任何密鑰來加密憑證,同樣可以解密。 希望它有幫助。

+0

您的AES示例正是我一直在尋找的。謝謝! – Lerkes

+0

@Lerkes:如果這個例子幫助了你,那麼你可以讚揚這個例子,因爲這也會幫助其他人。 –