函数返回json而不是仅返回值

时间:2019-01-11 11:51:45

标签: json powershell

我有带有RDP,测试等标签的ec2实例。

我创建了一个函数来根据标签建立WinRM连接:

value5

当我打电话时:

value2

对于RDP-可以。但另一方面:

function PSconnector($IP){
# code to get instance tag
#....

if ($instance_tag -match 'RDP') {
   $user = "foo"
   $pass = "bar"
}
else{
  # donwload config
  #....

  $config = Get-Content .\$config_name| Out-String | ConvertFrom-Json
  $user = $config.Server.ServerUser
  $pass = $config.Server.ServerPassword
}
# running echo to check only
echo $user
echo $pass
#
return ($user, $pass)
}

同时,函数中的echo显示正确的varaibales,不带json,仅显示:

$creds =  PSconnector($ip)
$creds

EDIT1

使用aws cli下载配置文件

{
    "AcceptRanges": "bytes",
    "LastModified": "Fri, 11 Jan 2019 09:56:53 GMT",
    "ContentLength": 2919,
    "ETag": "\"1f5ace2cfc81ba53ffde4b0e66cb65da\"",
    "ContentType": "application/json",
    "Metadata": {}
}
foobar
barfoo

EDIT2 如果我使用foobar barfoo ,则 aws s3api get-object --bucket $bucket --key $key/$config_name $config_name 的结果类似:

Get-S3Object

问题出在哪里?

1 个答案:

答案 0 :(得分:3)

<div class="sld-h"> <i class="fa fa-chevron-left"></i> <ul class="slides"> <li class="slide"><img id="1" src="https://picsum.photos/150/150/?random"/></li> <li class="slide"><img id="2" src="https://picsum.photos/150/150/?random"/></li> <li class="slide"><img id="3" src="https://picsum.photos/150/150/?random"/></li> <li class="slide"><img id="4" src="https://picsum.photos/150/150/?random"/></li> </ul> <i class="fa fa-chevron-right"></i> </div> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>移至Read-S3Object以停止返回命令输出:

Out-Null