2016-06-06 2 views
1

저는 XAMPP (php/mysql/apache) 및 PowerShell v3으로 Windows 2012 R2 서버를 실행하고 있습니다. 지난 몇 개월 동안, 내 코드는 암호화 된 암호를 저장하고 검색하기 위해 잘 작동했습니다.원격으로 PHP 응용 프로그램에서 PowerShell 스크립트를 실행하기위한 자격 증명 저장

내 질문은 Powershell 스크립트에서 사용할 암호를 어떻게 저장할 수 있습니까? 스크립트는 로컬에서 실행하면 제대로 작동하지만 원격 클라이언트의 PHP 응용 프로그램에서 실행하면 "서버에서 클라이언트 자격 증명을 거부했습니다."라는 메시지가 나타납니다. 오류.

나는이 방법으로 암호 파일을 만드는 시도했다 :이처럼 사용

$PasswordFile = "D:\path\to\password.txt" 
[Byte[]] $key = (1..16) 
$credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "domain\username", (Get-Content $PasswordFile | ConvertTo-SecureString -Key $key) 

을 다음 :

get-wmiobject Win32_Service -ComputerName $dc.name -credential $credential | select systemname,name,startmode,caption,state 

답변

0

$File = "D:\path\to\password.txt" 
[Byte[]] $key = (1..16) 
$Password = "myPassword" | ConvertTo-SecureString -AsPlainText -Force 
$Password | ConvertFrom-SecureString -key $key | Out-File $File 

그리고 검색이처럼 사용 Here 약간 다른 명령 사용

은 아마 당신은 자신의 길을

$SecureString = Read-Host -AsSecureString 
$EncryptedPW = ConvertFrom-SecureString -SecureString $SecureString 
Set-Content -Path "C:\tmp\mypw.txt" -Value $EncryptedPW 

을 시도하고 나는 아직 그것을 시도하지 않았다

$EncryptedPW = Get-Content -Path "C:\tmp\mypw.txt" 
$SecureString = ConvertTo-SecureString -String $EncryptedPW 
$Credentials = New-Object System.Management.Automation.PSCredential "User", $SecureString 

으로 검색 할. 그러나 그것은 가치가있다.

관련 문제