Powershell 更改工作流的序列化方法
更新: 经过一番挖掘,我找到了一个页面,其中有一个方法说明: -序列化方法Powershell 更改工作流的序列化方法,powershell,azure,azure-powershell,azure-resource-manager,Powershell,Azure,Azure Powershell,Azure Resource Manager,更新: 经过一番挖掘,我找到了一个页面,其中有一个方法说明: -序列化方法 字符串:将类型序列化为字符串。可以使用StringSerializationSource指定要用作序列化结果的类型的属性。否则,将使用对象的ToString方法序列化该类型 这似乎是我遇到的问题,但是我无法在工作流中运行updatetypedata 原始问题 我有以下代码: workflow Deploy-Template { Param ( $Credentials, $resource
字符串:将类型序列化为字符串。可以使用StringSerializationSource指定要用作序列化结果的类型的属性。否则,将使用对象的ToString方法序列化该类型 这似乎是我遇到的问题,但是我无法在工作流中运行
updatetypedata
原始问题
我有以下代码:
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
我四处摸索并改变了一些事情,似乎在工作流$deploy
中运行时,DeploymentVariable变成了字符串
如果我只是跑:
$deploy = New-AzureRmResourceGroupDeployment -Name ([guid]::NewGuid()).guid.tostring() `
-ResourceGroupName $resourcegroup `
-TemplateFile "E:\tmp\storage.json"
我得到:
PS > $deploy.Outputs.storageAccountName.Value
y74ek7r67mq6c
这正是我所期待的。(在工作流
中运行时,没有值
属性)
我尝试通过converttojson
运行它,但它也在做同样的事情
为什么我不能从工作流中获取对象
编辑以添加
storage.json
文件的相关部分是
"outputs": {
"storageAccountName": {
"type": "string",
"value": "[variables('storageAccount')]"
在工作流之外运行
$deploy.Outputs.storageAccountName.GetType()
IsPublic IsSerial Name BaseType
----------------------
True False DeploymentVariable System.Object
而在工作流中
给出
$value[0].output.Outputs.storageAccountName.gettype()
IsPublic IsSerial Name BaseType
----------------------
真字符串系统。对象
内联运行代码会产生相同的结果
$deploy = InlineScript
{
New-AzureRmResourceGroupDeployment -Name ([guid]::NewGuid()).guid.tostring() `
-ResourceGroupName $Using:resourcegroup `
-TemplateFile "E:\Git\Simplifed-Azure-Templates\storage.json"
}
当需要运行一个或多个脚本时,InlineScript活动非常有用
作为传统PowerShell脚本而不是PowerShell的命令
工作流程。工作流中的命令发送到Windows工作流时
在内联脚本块中处理命令的基础是
由Windows PowerShell处理
来源是上面的链接
您可能必须将调用包装在InlineScript
中:
通过将输出分配给
变数
试试这个:
workflow Deploy-Template
{
Param
(
$Credentials, $resourcegroup, $count
)
$PSDisableSerializationPreference = $true
$results = @()
$collection = (1..$count)
sequence
{
foreach -parallel ($item in $collection)
{
$workflow:results += InlineScript {
$subs = Add-AzureRmAccount -Credential $Credentials
$deploy = New-AzureRmResourceGroupDeployment -Name ([guid]::NewGuid()).guid.tostring() `
-ResourceGroupName $resourcegroup `
-TemplateFile "E:\tmp\storage.json"
New-Object -type PSObject -Property @{
output = $deploy
}
}
}
Write-Output $results
}
}
$value = Deploy-Template -Credentials $TenantObject.credential -resourcegroup $resourcegroup -count 1
显示为数据类型名称的数据应放在“$()”@SavindraSingh putoutput=$($deploy.outputs.storageAccountName)
中,返回类型是否相同?Eg$value[0]。如果您只运行新AzureRmResourceGroupDeployment
cmdlet,是否在工作流和$deploy.GetType()
上输出.GetType()
?另外,您的工作区中是否有Value属性?@jisaak这是我不理解的部分,我有两种不同的返回类型,您可以在问题的新部分中看到。在工作流之外运行时,只有value属性。当它在工作区内时,它会变成一个字符串,没有值属性。$PSDisableSerializationPreference=$true
应该停止反序列化成为问题-并且在工作流中运行时会给出相同的输出(我将修改问题)-顺便说一句,您的代码实际上没有inlinescript位;)您是否尝试访问“工作流”中的InlineScript
中的$deploy.Outputs.storageAccountName.Value
?我尝试了,但因为$deploy.Outputs.storageAccountName
仍然是一个字符串,因此没有值
hmm,抱歉。那我就没有更多的想法了。没问题,谢谢你的想法!我想这可能是物体深度的问题,但我还没有证明这一点