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