我有一个整数变量,例如$int = (1,2,3)
我需要使用Invoke-RestMethod
获得该值,例如$var = Invoke-RestMethod -Headers @{"Metadata-Flavor" = "Google"} -Uri http://169.254.169.254/computeMetadata/v1/instance/attributes/numbers
的问题是,Invoke-RestMethod返回的值是字符串而不是整数。
也无法将其转换为整数[int]$var = $int
它返回一个错误:
Cannot convert value "(1,2,3)" to type "System.Int32". Error: "Input string was not in a correct format."
如果我不使用Invoke-RestMethod来检索值,则它会按预期工作,因为$int = (1,2,3)
创建了System.Int32。
答案 0 :(得分:1)
您需要指定caching
可以是数组。
int
帮助这有帮助!
编辑**
从字符串中删除括号,并在逗号处将其分割。
[int[]]$var = $int