【发布时间】:2022-01-11 02:15:35
【问题描述】:
我想在 PowerShell 中围绕 New-AzResourceGroupDeployment 编写一个包装器。所以让我们假设以下脚本:
New-AzResourceGroupDeployment `
-Name 'test' `
-ResourceGroupName 'rg-test' `
-TemplateFile .\main.bicep `
-TemplateParameterFile .\parameters\parameters.json `
-Verbose `
-WhatIf
这将输出如下内容:
VERBOSE: Using Bicep v0.4.1008
...
What if: Performing the operation "Creating Deployment" on target "rg-test".
所以这里的问题是我不会从WhatIf 得到任何结果。我猜是因为WhatIf 在后台运行了一个不同的进程。
那么有没有办法捕获WhatIf 的输出?
【问题讨论】:
-
你的意思是如何捕获
WhatIf的输出? -
@SantiagoSquarzon 是的。我更新了问题。
-
我不认为你可以,
-WhatIf不会去任何类似于$testVar = [console]::WriteLine('hello') *>&1的PowerShell output Streams 也无法捕获。 -
Start-Transcript可以实际捕获它,但我认为这不是您的意图,您希望它在变量上吗? -
@SantiagoSquarzon 感谢您的建议。我想我不能以干净的方式做到这一点。但很高兴知道一些解决方法;)
标签: powershell azure-powershell