2017-05-25 18 views
0

New-Ec2Tag関数にいくつかの変数を渡す小さなラッパー関数があります。私がそれを実行すると、Amazon.Runtime.AWSCredentialsSystem.Object []に変換され、変換されてエラーが返されます。AWS Powershell関数は、AWSCredentialsをSystem.Objectに変換します。

この機能を動作させる方法はありますか?

機能

function addTag ($awscred, $instanceID, $TagName, $TagValue){ 
    Write-output $awscred.gettype() 
    New-Ec2Tag -region 'ap-southeast-2' -Resource $instanceID -Tag @{Key=$TagName;Value=$TagValue} -Credential $AwsCredentials} 

私は機能でそれをラップしていない場合、私は

write-output $AwsCredentials.gettype() 
addTag($AwsCredentials,$instanceid,"Creator","123456") 

コマンド出力

IsPublic IsSerial Name          BaseType                              
-------- -------- ----          --------                              
True  False SessionAWSCredentials     Amazon.Runtime.AWSCredentials                         
True  True  Object[]         System.Array  

New-EC2Tag : Cannot convert 'System.Object[]' to the type 'Amazon.Runtime.AWSCredentials' required by parameter 'Credential'. Specified method is not supported. 

コマンドの動作を実行するコマンド

New-Ec2Tag -region 'ap-southeast-2' -Credential $AwsCredentials -Resource $instanceID -Tag (@{Key="Name";Value="test"}) 

答えて

0

代わりにこのようなあなたの関数を呼び出します。PowerShellで

addTag $AwsCredentials $instanceid "Creator" "123456"

を、関数のパラメータは、あなたのパラメータは、オブジェクトの配列にキャストされている理由です、括弧やカンマを使用して呼び出されていません。

+0

ありがとう、私はそれを見落としたとは思わない – Shadowzee

関連する問題