作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在运行以下PowerShell代码,我需要保持原始哈希表键的顺序。
function New-GetServiceConnectionTask( $serviceConnectionId)
{
@{
environment = @{ }
taskId = '0a9fdc5e-3f3a-4d3d-9f63-a4f007f9a1fe'
version = "1.*"
name = 'Get Service Endpoint Credentials'
refName = ''
enabled = $true
alwaysRun = $false
continueOnError = $false
timeoutInMinutes = 0
definitionType = 'task'
overrideInputs = @{ }
condition = 'succeeded()'
inputs = @{
connectedServiceNameARM = $serviceConnectionId
}
}
}
New-GetServiceConnectionTask xxx | ConvertTo-Json -Depth 99
{
"version": "1.*",
"refName": "",
"definitionType": "task",
"overrideInputs": {},
"name": "Get Service Endpoint Credentials",
"environment": {},
"inputs": {
"connectedServiceNameARM": "xxx"
},
"timeoutInMinutes": 0,
"taskId": "0a9fdc5e-3f3a-4d3d-9f63-a4f007f9a1fe",
"enabled": true,
"condition": "succeeded()",
"continueOnError": false,
"alwaysRun": false
}
最佳答案
您可以通过在@符号前面添加[ordered]来创建有序哈希,如下所示:
[ordered]@{
environment = @{ }
taskId = '0a9fdc5e-3f3a-4d3d-9f63-a4f007f9a1fe'
version = "1.*"
name = 'Get Service Endpoint Credentials'
refName = ''
enabled = $true
alwaysRun = $false
continueOnError = $false
timeoutInMinutes = 0
definitionType = 'task'
overrideInputs = @{ }
condition = 'succeeded()'
inputs = @{
connectedServiceNameARM = $serviceConnectionId
}
}
关于powershell - ConvertTo-Json如何保持哈希表字段的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61804610/
我是一名优秀的程序员,十分优秀!