Update:
After some digging around, I have found a page for Update-TypeData that that has a method that states:
-SerializationMethod
String: Serialize the type as a string. You can use the StringSerializationSource to specify a property of the type to use as the serialization result. Otherwise, the type is serialized by using the ToString method of the object.
This appears to be the problem I am having, however I can't run Update-TypeData in a workflow.
Original Question
I have the following code:
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
When I run it and try to query the result I get:
PS > $value[0].output.Outputs.storageAccountName
Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.DeploymentVariable
PS > $value[0].output.Outputs.storageAccountName | gm
TypeName: System.String
I've poked around and changed things and it seems that when run within a Workflow $deploy the DeploymentVariable is made a string.
If I just run:
$deploy = New-AzureRmResourceGroupDeployment -Name ([guid]::NewGuid()).guid.tostring() `
-ResourceGroupName $resourcegroup `
-TemplateFile "E:\tmp\storage.json"
I get:
PS > $deploy.Outputs.storageAccountName.Value
y74ek7r67mq6c
Which is what I'm expecting. (there is no value property when it runs in a workflow)
I tried running it through convertto-json but it is doing the same.
Why can't I get my object out of my workflow?
edited to add
The relevant section of the storage.json file is
"outputs": {
"storageAccountName": {
"type": "string",
"value": "[variables('storageAccount')]"
Run outside of the workflow
$deploy.Outputs.storageAccountName.GetType()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True False DeploymentVariable System.Object
While inside the workflow gives
$value[0].output.Outputs.storageAccountName.gettype()
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True String System.Object
Running the code inline produces the same result
$deploy = InlineScript
{
New-AzureRmResourceGroupDeployment -Name ([guid]::NewGuid()).guid.tostring() `
-ResourceGroupName $Using:resourcegroup `
-TemplateFile "E:\Git\Simplifed-Azure-Templates\storage.json"
}
output = $($deploy.outputs.storageAccountName)gives the same result also (as well as adding .value on the end)$value[0].output.GetType()on the workflow and$deploy.GetType()if you just run theNew-AzureRmResourceGroupDeploymentcmdlet? Also, do you have the Value property within your workspace?