2016-09-01 2 views
0

암호를 안전하게 저장하고 파일에 저장하려고하므로 스크립트를 실행할 때마다 입력 할 필요가 없습니다.프롬프트없이 여러 명의 사용자에게 보안 암호 사용

첫 번째 단계에서는 다음을 실행하여 E : \ cred.txt 파일에 저장된 암호를 입력했습니다. 이제 txt 파일에 암호화 된 비밀번호가 포함됩니다.

(Get-Credential).Password | ConvertFrom-SecureString | Out-File "E:\cred.txt" 

둘째, 나는 스크립트 아래의 실행 :

$File = "E:\cred.txt" 
$User = "[email protected]" 

#### I have two different user accounts, one for admin and other for operator, 
#### however both user accounts use same password. 

$adminuser = $User 
$operator = $User -replace "@domain.com" 

#### I would need to read $File to get only the password 

$pass = New-Object -TypeName System.Management.Automation.PSCredential ` 
    -ArgumentList (Get-Content $File | ConvertTo-SecureString) 

$adminuser 
$operator 
$pass 

출력 : 출력에서 ​​

[email protected] 
jason 

UserName             Password 
--------             -------- 

, 새로운 객체가 사용자 이름과 암호를 모두 지칭합니다 보인다. 그리고 시스템에 연결하려고하면 인증 오류로 실패합니다. 스크립트 내에서 두 개의 다른 사용자 이름이 이미 하드 코딩되어 있으므로 $ pass에 저장된 암호 만 얻는 방법은 무엇입니까? 또는 모든 사용자 이름 ($ User, $ adminuser, $ operator)을 cred.txt 파일에 포함시킬 수 있습니까?

답변

0

이 시도 :

#saving credentials 
Get-Credential | Export-CliXml -Path c:\credential.xml 

#importing credentials to a variable 
$Credential = Import-CliXml -Path c:\credential.xml 

또는이 :

#you could then write it to a file or, i say its a better approach to a registry key 
$SecurePassword = ConvertTo-SecureString -String '[email protected]' -AsPlainText -Force | ConvertFrom-SecureString 

#now you are taking it back as a secure string 
$RegistrySecureString = $SecurePassword | ConvertTo-SecureString 

#you can aslo see the password 
$UserName = "NULL" 
$Credentials = New-Object System.Management.Automation.PSCredential -ArgumentList $UserName, $RegistrySecureString 
$Password = $Credentials.GetNetworkCredential().Password 
#[email protected] 
+0

하는 빠른했다. :-) 감사합니다 KirillPashkov – user3331975

관련 문제