diff --git a/src/internal/functions/New-AzOpsDeployment.ps1 b/src/internal/functions/New-AzOpsDeployment.ps1 index b0d3a5cd..89e03eb4 100644 --- a/src/internal/functions/New-AzOpsDeployment.ps1 +++ b/src/internal/functions/New-AzOpsDeployment.ps1 @@ -106,10 +106,9 @@ return } else { - Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfResults' -StringValues ($results | Out-String) -Target $scopeObject - Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfFile' -Target $scopeObject - $output = 'WhatIf Results:{0}```json{0}{1}{0}```{0}' -f [environment]::NewLine, ($results.Changes | ConvertTo-Json -Depth 5) - Set-Content -Path '/tmp/OUTPUT.md' -Value $output -WhatIf:$false + Write-PSFMessage -Level Verbose -String 'Set-AzOpsWhatIfOutput.WhatIfResults' -StringValues ($results | Out-String) -Target $scopeObject + Write-PSFMessage -Level Verbose -String 'Set-AzOpsWhatIfOutput.WhatIfFile' -Target $scopeObject + Set-AzOpsWhatIfOutput -results $results } $parameters.Name = $DeploymentName @@ -148,8 +147,7 @@ else { Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfResults' -StringValues ($results | Out-String) -Target $scopeObject Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfFile' -Target $scopeObject - $output = 'WhatIf Results:{0}```json{0}{1}{0}```{0}' -f [environment]::NewLine, ($results.Changes | ConvertTo-Json -Depth 5) - Set-Content -Path '/tmp/OUTPUT.md' -Value $output -WhatIf:$false + Set-AzOpsWhatIfOutput -results $results } $parameters.Name = $DeploymentName @@ -197,8 +195,7 @@ else { Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfResults' -StringValues ($results | Out-String) -Target $scopeObject Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfFile' -Target $scopeObject - $output = 'WhatIf Results:{0}```json{0}{1}{0}```{0}' -f [environment]::NewLine, ($results.Changes | ConvertTo-Json -Depth 5) - Set-Content -Path '/tmp/OUTPUT.md' -Value $output -WhatIf:$false + Set-AzOpsWhatIfOutput -results $results } $parameters.Name = $DeploymentName @@ -242,8 +239,7 @@ else { Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfResults' -StringValues ($results | Out-String) -Target $scopeObject Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfFile' -Target $scopeObject - $output = 'WhatIf Results:{0}```json{0}{1}{0}```{0}' -f [environment]::NewLine, ($results.Changes | ConvertTo-Json -Depth 5) - Set-Content -Path '/tmp/OUTPUT.md' -Value $output -WhatIf:$false + Set-AzOpsWhatIfOutput -results $results } $parameters.Name = $DeploymentName @@ -283,8 +279,7 @@ else { Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfResults' -StringValues ($results | Out-String) -Target $scopeObject Write-PSFMessage -Level Verbose -String 'New-AzOpsDeployment.WhatIfFile' -Target $scopeObject - $output = 'WhatIf Results:{0}```json{0}{1}{0}```{0}' -f [environment]::NewLine, ($results.Changes | ConvertTo-Json -Depth 5) - Set-Content -Path '/tmp/OUTPUT.md' -Value $output -WhatIf:$false + Set-AzOpsWhatIfOutput -results $results } $parameters.Name = $DeploymentName diff --git a/src/internal/functions/Set-AzOpsWhatIfOutput.ps1 b/src/internal/functions/Set-AzOpsWhatIfOutput.ps1 new file mode 100644 index 00000000..719c7f1a --- /dev/null +++ b/src/internal/functions/Set-AzOpsWhatIfOutput.ps1 @@ -0,0 +1,30 @@ +function Set-AzOpsWhatIfOutput { + + <# + .SYNOPSIS + Logs the output from a What-If deployment + .DESCRIPTION + Logs the output from a What-If deployment + .PARAMETER results + The WhatIf result from a deployment + .EXAMPLE + > et-WhatIfOutput -results $results + #> + + [CmdletBinding()] + param ( + [Parameter(Mandatory = $true)] + $results + ) + + process { + Write-PSFMessage -Level Verbose -String 'Set-AzOpsWhatIfOutput.WhatIfFile' + + $resultJson=($results.Changes | ConvertTo-Json -Depth 5) + $mdOutput = 'WhatIf Results:{0}```json{0}{1}{0}```{0}' -f [environment]::NewLine, $resultJson + + Set-Content -Path '/tmp/OUTPUT.md' -Value $mdOutput -WhatIf:$false + Set-Content -Path '/tmp/OUTPUT.json' -Value $resultJson -WhatIf:$false + } + +} \ No newline at end of file diff --git a/src/localized/en-us/Strings.psd1 b/src/localized/en-us/Strings.psd1 index 35805b2d..3cbd75d9 100644 --- a/src/localized/en-us/Strings.psd1 +++ b/src/localized/en-us/Strings.psd1 @@ -233,4 +233,5 @@ 'Save-AzOpsManagementGroupChildren.Subscription.NotFound' = 'Unable to locate subscription: {0} within AzOpsSubscriptions object' #child.Name 'Set-AzOpsContext.Change' = 'Changing active subscription from {0} to {1} ({2})' # $context.Subscription.Name, $ScopeObject.SubscriptionDisplayName, $ScopeObject.Subscription -} \ No newline at end of file + 'Set-AzOpsWhatIfOutput.WhatIfFile' = 'Creating WhatIf markdown and json files' # +}