2016-09-15 4 views
0

나는 딜레마가있다.Powershell 및 다른 사용자로 예약 된 작업 실행

다른 사용자 (액세스 권한이 있지만 로그온 권한이없는 서비스 계정)로 powershell 스크립트를 실행하는 예약 된 작업을 Windows에서 설정하려고합니다. 문제는 암호로 코드를 작성하지 말라는 보안 그룹의 말 (분명히 좋은 충고)이지만 SQL의 연결 문자열은 일반 텍스트로 필요합니다. 내가 암호 파일을 생성하여이 문제를 얻고 다음하다가하지만

$credential = Get-Credential 
$credential.Password | ConvertFrom-SecureString | Set-Content e:\temp\password.txt 

그리고 일반 텍스트로 다시 변환 스크립트 (연결 문자열에 사용되는)를

$password = cat E:\temp\password.txt | ConvertTo-SecureString 
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($password) 
$UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) 

$connectionString = "Data Source=<mydatabase>;Initial Catalog='<mytable>';User ID=tng ;Password=$Unsecurepassword;" 

입니다 내가 패스워드 파일을 만들고 스크립트를 스스로 실행하면 훌륭하게 작동하지만 스케줄 된 작업으로 실행할 수는 없다. 과거 경험에 비추어 볼 때 패스워드 파일이 예약 된 작업을 실행하는 서비스 계정에 의해 생성 될 필요가있는 곳을 알았지 만 로컬 로그온 권한이 없으면 어떻게 작성해야할지 모르겠습니다. 이견있는 사람?

나는 this technet article을 시도했지만 여전히 다른 계정의 로컬 로그온이 필요합니다.

+0

덕분에 발견 [리 nk] (http://www.adminarsenal.com/admin-arsenal-blog/secure-password-with-powershell-encrypting-credentials-part-2/) – jdolluc

답변

0

답을 찾을 수 - 나는 보안 문자열에 키를 추가하는 데 필요한 :

파일을 생성 -은 $ 키를 추가 :

[byte[]] $key = (1..16) 
$credential = Get-Credential 
$credential.Password | ConvertFrom-SecureString -key $key | Set-Content e:\temp\password.txt 

그리고이 다음에 다시 읽을 때 :

$passwordfile = "E:\temp\password.txt" 
[byte[]] $key = (1..16) 
$securePassword = Get-Content $passwordfile | ConvertTo-SecureString -Key $key 
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($securepassword) 
$UnsecurePassword = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR) 

대답 그럼 난 뭔가가있을 수 있습니다 생각 this link