首页 > 解决方案 > 将批处理文件变量设置为 Powshell 脚本的输出

问题描述

此 powershell 脚本接受一个参数并返回一个值:

解密密码.ps1

# Decrypts KMS Encrypted password payload by executing the "aws kms decrypt" command
# Arguments: File path containing a password payload as CypherTextBlob
# Returns: Decrypted Password

$file_path=$args[0]

# Remove encryption
$encoded_pass = aws kms decrypt --ciphertext-blob "fileb://$file_path" --query Plaintext --output text --region us-east-1

# Remove base64 encoding from pass
$decrypted = [Text.Encoding]::Utf8.GetString([System.Convert]::FromBase64String($encoded_pass))

return $decrypted

然后在这个批处理文件中,我想为这个脚本的输出设置一个变量。我尝试了以下命令,但它只是将 PASS 的值设置为整个字符串......它不调用该函数

set PASS = powershell.exe -ExecutionPolicy Bypass -Command "C:\installation_files\decrypt_password.ps1 'C:\installation_files\encrypted'"

如何获得decrypt_password.ps1存储在 PASS 变量中的输出?

标签: powershellbatch-file

解决方案


推荐阅读