문제
스크립트에서 사용자 이름과 암호를 사용해야 하며 Windows를 사용합니다.
해결책
나중에 검색할 수 있도록 RunProgram을 통해 powershell을 호출하여 Credential Manager에 암호를 저장합니다(시작 표시줄에서 검색).
Names default to here(1);
loadmodule = "
if (!(Get-Module -ListAvailable -Name CredentialManager)) {
Install-Module CredentialManager -force -Scope CurrentUser
}
";
//Function to run command in powershell, strips trailing line breaks
RunPowershell = Function( {command},
Regex(RunProgram(
Executable( "powershell.exe" ),
Options( {"/c", command } ),
ReadFunction( "text" )
), "^(.*?)[\r\n]+$", "\1")
);
// Set password
SetPass = Function( {target,user,pass},
RunPowershell(
"$target = '" || target || "'
$usr = '" || user || "'
$pswd = '" || pass || "'
" || loadmodule || "
New-StoredCredential -Target $target -UserName $usr -Password $pswd" -Persist LocalMachine
);
1; //password is returned as free text, don't return the response
);
// Get password
GetPass = Function( {target},
RunPowershell(
"$target = '" || target || "'
" || loadmodule || "
$creds = Get-StoredCredential -Target $target
$creds.GetNetworkCredential().Password"
)
);
// Get username
GetUser = Function( {target},
RunPowershell(
"$target = '" || target || "'
" || loadmodule || "
$creds = Get-StoredCredential -Target $target
$creds.GetNetworkCredential().UserName"
)
);
'Windows 자격 증명 저장소'를 사용하여 이러한 테스트 자격 증명을 삭제할 수 있습니다.
이상적으로 이러한 자격 증명은 메모리에 저장되지 않습니다. 다음과 같이 필요할 때 호출할 수 있습니다.
request = New HTTP Request(
URL( "https://myserver" ),
Method("GET"),
Username( GetUser( undesc ) ),
Password( GetPass( undesc ) )
);
이 함수가 실제로 실행하는 powershell 명령은 다음과 같습니다.
SetCred:
param( $target, $usr, $pswd )
if (!Get-Module -ListAvailable -Name SomeModule) {
Install-Module CredentialManager -force -Scope CurrentUser
}
New-StoredCredential -Target $target -UserName $usr -Password $pswd -Persist LocalMachine
GetCred:
param( $target )
if (!Get-Module -ListAvailable -Name SomeModule) {
Install-Module CredentialManager -force -Scope CurrentUser
}
$creds = Get-StoredCredential -Target $target
$creds.GetNetworkCredential().UserName
$creds.GetNetworkCredential().Password훌륭한 솔루션입니다. 공유해 주셔서 감사합니다.