0
我有一个小的包装函数,它只是将几个变量传递给New-Ec2Tag函数。当我运行它时,它会将我的Amazon.Runtime.AWSCredentials 转换为System.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"})
谢谢,我不能相信我忽视了 – Shadowzee