【发布时间】:2016-10-11 13:12:09
【问题描述】:
更新:
经过一番挖掘,我找到了一个Update-TypeData 的页面,其中有一个方法:
-序列化方法
String:将类型序列化为字符串。您可以使用 StringSerializationSource 指定要用作序列化结果的类型的属性。否则,使用对象的 ToString 方法对类型进行序列化。
这似乎是我遇到的问题,但是我无法在工作流程中运行 Update-TypeData。
原始问题
我有以下代码:
workflow Deploy-Template
{
Param
(
$Credentials, $resourcegroup, $count
)
$PSDisableSerializationPreference = $true
$results = @()
$collection = (1..$count)
sequence
{
foreach -parallel ($item in $collection)
{
$subs = Add-AzureRmAccount -Credential $Credentials
$deploy = New-AzureRmResourceGroupDeployment -Name ([guid]::NewGuid()).guid.tostring() `
-ResourceGroupName $resourcegroup `
-TemplateFile "E:\tmp\storage.json"
$obj= New-Object -type PSObject -Property @{
output = $deploy
}
$workflow:results += $obj
}
Write-Output $results
}
}
$value = Deploy-Template -Credentials $TenantObject.credential -resourcegroup $resourcegroup -count 1
当我运行它并尝试查询我得到的结果时:
PS > $value[0].output.Outputs.storageAccountName
Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentVariable
PS > $value[0].output.Outputs.storageAccountName | gm
TypeName: System.String
我已经四处寻找并改变了一些东西,似乎当在Workflow$deploy 中运行时,DeploymentVariable 变成了string。
如果我只是跑步:
$deploy = New-AzureRmResourceGroupDeployment -Name ([guid]::NewGuid()).guid.tostring() `
-ResourceGroupName $resourcegroup `
-TemplateFile "E:\tmp\storage.json"
我明白了:
PS > $deploy.Outputs.storageAccountName.Value
y74ek7r67mq6c
这是我所期待的。 (在workflow 中运行时没有value 属性)
我尝试通过convertto-json 运行它,但它正在做同样的事情。
为什么我不能让我的对象脱离我的工作流程?
编辑添加
storage.json文件的相关部分是
"outputs": {
"storageAccountName": {
"type": "string",
"value": "[variables('storageAccount')]"
在workflow之外运行
$deploy.Outputs.storageAccountName.GetType()
IsPublic IsSerial 名称 BaseType
-------- -------- ---- --------
True False DeploymentVariable System.Object
虽然在workflow里面给出了
$value[0].output.Outputs.storageAccountName.gettype()
IsPublic IsSerial 名称 BaseType
-------- -------- ---- --------
True True 字符串 System.Object
内联运行代码会产生相同的结果
$deploy = InlineScript
{
New-AzureRmResourceGroupDeployment -Name ([guid]::NewGuid()).guid.tostring() `
-ResourceGroupName $Using:resourcegroup `
-TemplateFile "E:\Git\Simplifed-Azure-Templates\storage.json"
}
【问题讨论】:
-
显示为数据类型名称的数据应该放在“$()”里面。
-
@SavindraSingh put
output = $($deploy.outputs.storageAccountName)也给出相同的结果(以及在末尾添加 .value) -
返回类型一样吗? e. G。
$value[0].output.GetType()在workflow 和$deploy.GetType()上,如果您只运行New-AzureRmResourceGroupDeploymentcmdlet?另外,您的工作区内是否有 Value 属性? -
@jisaak 那是我不明白的部分,我有两种不同的返回类型,正如您在问题的新部分中看到的那样。当它在工作流之外运行时,只有一个值属性。当它在工作空间内时,它变成一个字符串并且没有 value 属性。
标签: powershell azure azure-powershell azure-resource-manager