Powershell 格式问题 - arm 模板 -WhatIf [ANSI escape/color]
Powershell formatting issue - arm template -WhatIf [ANSI escape/color]
我不是 powershell 向导,但我得到了一些有趣的结果,格式中包含日期时间戳。我已经在我的管道中对 arm 模板和 terraform 进行了假设测试,但我没有找到修复它的运气。
假设我是 运行 测试臂模板的假设:
Get-AzResourceGroupDeploymentWhatIfResult -TemplateFile ./test-arm.json -TemplateParameterFile ./test-arm.params.json -ResourceGroupName whatIfRg -ResultFormat FullResourcePayloads
或简化版
New-AzResourceGroupDeployment -ResourceGroupName whatIfRg -TemplateFile ./test-arm.json -TemplateParameterFile ./test-arm.params.json -WhatIf
这运行正常,但我返回的结果如下所示:
Resource and property changes are indicated with this symbol:
[38;5;77m+[0m Create
The deployment will update the following scope:
Scope: /subscriptions/[removed]/resourceGroups/whatIfRg
[38;5;77m
+ Microsoft.Network/networkSecurityGroups/DefaultNSG[0m [2019-11-01][38;5;77m
apiVersion[0m:[38;5;77m "2019-11-01"
id[0m:[38;5;77m "/subscriptions/[removed]/resourceGroups/whatIfRg/providers/Microsoft.Network/networkSecurityGroups/DefaultNSG"
location[0m:[38;5;77m "eastus"
name[0m:[38;5;77m "DefaultNSG"
type[0m:[38;5;77m "Microsoft.Network/networkSecurityGroups"
+ Microsoft.Network/virtualNetworks/firstVnet[0m [2019-11-01][38;5;77m
apiVersion[0m:[38;5;77m "2019-11-01"
id[0m:[38;5;77m "/subscriptions/[removed]/resourceGroups/whatIfRg/providers/Microsoft.Network/virtualNetworks/firstVnet"
location[0m:[38;5;77m "eastus"
name[0m:[38;5;77m "firstVnet"
properties.addressSpace.addressPrefixes[0m:[38;5;77m [0m[[38;5;77m
0[0m:[38;5;77m "192.168.10.0/24"
[0m][38;5;77m
properties.subnets[0m:[38;5;77m [0m[[38;5;77m
0[0m:[38;5;77m
name[0m:[38;5;77m "firstSubnet"
properties.addressPrefix[0m:[38;5;77m "192.168.10.0/25"
properties.networkSecurityGroup.ID[0m:[38;5;77m
"/subscriptions/[removed]/resourceGroups/whatIfRg/providers/Microsoft.Network/networkSecurityGroups/DefaultNSG"
[0m][38;5;77m
type[0m:[38;5;77m "Microsoft.Network/virtualNetworks"
[0m
Resource changes: 2 to create.
我希望格式看起来像这样:
Resource and property changes are indicated with this symbol:
Create
The deployment will update the following scope:
Scope: /subscriptions/[removed]/resourceGroups/whatIfRg
+ Microsoft.Network/networkSecurityGroups/DefaultNSG
apiVersion "2019-11-01"
id "/subscriptions/[removed]/resourceGroups/whatIfRg/providers/Microsoft.Network/networkSecurityGroups/DefaultNSG"
location "eastus"
name "DefaultNSG"
type "Microsoft.Network/networkSecurityGroups"
+ Microsoft.Network/virtualNetworks/firstVnet
apiVersion "2019-11-01"
id "/subscriptions/[removed]/resourceGroups/whatIfRg/providers/Microsoft.Network/virtualNetworks/firstVnet"
location "eastus"
name "firstVnet"
properties.addressSpace.addressPrefixes
"192.168.10.0/24"
properties.subnets
name "firstSubnet"
properties.addressPrefix "192.168.10.0/25"
properties.networkSecurityGroup.ID
"/subscriptions/[removed]/resourceGroups/whatIfRg/providers/Microsoft.Network/networkSecurityGroups/DefaultNSG"
type "Microsoft.Network/virtualNetworks"
Resource changes: 2 to create.
我很难找到文档来删除结果中的 date/time 标记。如果有人知道要传递的参数,或者我的 PowerShell 需要修改为不显示邮票,我们将不胜感激。
在进行更多故障排除并将文本粘贴到记事本++之后,我能够看到 ESC 字符以及我认为与 date/time 相关的数字。
问题与 ANSI 转义颜色相关,默认情况下在 Windows 10 中禁用支持。
此问题的最佳解决方案是更新到支持 ANSI escapes/colors 的 PowerShell 7.2。低于此版本的任何版本均无效。
我不是 powershell 向导,但我得到了一些有趣的结果,格式中包含日期时间戳。我已经在我的管道中对 arm 模板和 terraform 进行了假设测试,但我没有找到修复它的运气。
假设我是 运行 测试臂模板的假设:
Get-AzResourceGroupDeploymentWhatIfResult -TemplateFile ./test-arm.json -TemplateParameterFile ./test-arm.params.json -ResourceGroupName whatIfRg -ResultFormat FullResourcePayloads
或简化版
New-AzResourceGroupDeployment -ResourceGroupName whatIfRg -TemplateFile ./test-arm.json -TemplateParameterFile ./test-arm.params.json -WhatIf
这运行正常,但我返回的结果如下所示:
Resource and property changes are indicated with this symbol:
[38;5;77m+[0m Create
The deployment will update the following scope:
Scope: /subscriptions/[removed]/resourceGroups/whatIfRg
[38;5;77m
+ Microsoft.Network/networkSecurityGroups/DefaultNSG[0m [2019-11-01][38;5;77m
apiVersion[0m:[38;5;77m "2019-11-01"
id[0m:[38;5;77m "/subscriptions/[removed]/resourceGroups/whatIfRg/providers/Microsoft.Network/networkSecurityGroups/DefaultNSG"
location[0m:[38;5;77m "eastus"
name[0m:[38;5;77m "DefaultNSG"
type[0m:[38;5;77m "Microsoft.Network/networkSecurityGroups"
+ Microsoft.Network/virtualNetworks/firstVnet[0m [2019-11-01][38;5;77m
apiVersion[0m:[38;5;77m "2019-11-01"
id[0m:[38;5;77m "/subscriptions/[removed]/resourceGroups/whatIfRg/providers/Microsoft.Network/virtualNetworks/firstVnet"
location[0m:[38;5;77m "eastus"
name[0m:[38;5;77m "firstVnet"
properties.addressSpace.addressPrefixes[0m:[38;5;77m [0m[[38;5;77m
0[0m:[38;5;77m "192.168.10.0/24"
[0m][38;5;77m
properties.subnets[0m:[38;5;77m [0m[[38;5;77m
0[0m:[38;5;77m
name[0m:[38;5;77m "firstSubnet"
properties.addressPrefix[0m:[38;5;77m "192.168.10.0/25"
properties.networkSecurityGroup.ID[0m:[38;5;77m
"/subscriptions/[removed]/resourceGroups/whatIfRg/providers/Microsoft.Network/networkSecurityGroups/DefaultNSG"
[0m][38;5;77m
type[0m:[38;5;77m "Microsoft.Network/virtualNetworks"
[0m
Resource changes: 2 to create.
我希望格式看起来像这样:
Resource and property changes are indicated with this symbol:
Create
The deployment will update the following scope:
Scope: /subscriptions/[removed]/resourceGroups/whatIfRg
+ Microsoft.Network/networkSecurityGroups/DefaultNSG
apiVersion "2019-11-01"
id "/subscriptions/[removed]/resourceGroups/whatIfRg/providers/Microsoft.Network/networkSecurityGroups/DefaultNSG"
location "eastus"
name "DefaultNSG"
type "Microsoft.Network/networkSecurityGroups"
+ Microsoft.Network/virtualNetworks/firstVnet
apiVersion "2019-11-01"
id "/subscriptions/[removed]/resourceGroups/whatIfRg/providers/Microsoft.Network/virtualNetworks/firstVnet"
location "eastus"
name "firstVnet"
properties.addressSpace.addressPrefixes
"192.168.10.0/24"
properties.subnets
name "firstSubnet"
properties.addressPrefix "192.168.10.0/25"
properties.networkSecurityGroup.ID
"/subscriptions/[removed]/resourceGroups/whatIfRg/providers/Microsoft.Network/networkSecurityGroups/DefaultNSG"
type "Microsoft.Network/virtualNetworks"
Resource changes: 2 to create.
我很难找到文档来删除结果中的 date/time 标记。如果有人知道要传递的参数,或者我的 PowerShell 需要修改为不显示邮票,我们将不胜感激。
在进行更多故障排除并将文本粘贴到记事本++之后,我能够看到 ESC 字符以及我认为与 date/time 相关的数字。
问题与 ANSI 转义颜色相关,默认情况下在 Windows 10 中禁用支持。
此问题的最佳解决方案是更新到支持 ANSI escapes/colors 的 PowerShell 7.2。低于此版本的任何版本均无效。