win_dsc - return warning from DSC invocation (#51927)

This commit is contained in:
Jordan Borean 2019-02-12 13:50:00 +10:00 committed by GitHub
commit 179cbb9891
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 2 deletions

View file

@ -236,7 +236,11 @@ try
{
#Defined variables in strictmode
$TestError, $TestError = $null
$TestResult = Invoke-DscResource @Config -Method Test -ModuleName $Module -ErrorVariable TestError -ErrorAction SilentlyContinue
$TestResult = Invoke-DscResource @Config -Method Test -ModuleName $Module -ErrorVariable TestError -ErrorAction SilentlyContinue -WarningVariable TestWarn
foreach ($warning in $TestWarn) {
Add-Warning -obj $result -message $warning.Message
}
if ($TestError)
{
throw ($TestError[0].Exception.Message)
@ -245,7 +249,10 @@ try
{
if ($check_mode -eq $False)
{
$SetResult = Invoke-DscResource -Method Set @Config -ModuleName $Module -ErrorVariable SetError -ErrorAction SilentlyContinue -WarningAction SilentlyContinue
$SetResult = Invoke-DscResource -Method Set @Config -ModuleName $Module -ErrorVariable SetError -ErrorAction SilentlyContinue -WarningVariable SetWarn
foreach ($warning in $SetWarn) {
Add-Warning -obj $result -message $warning.Message
}
if ($SetError -and ($SetResult -eq $null))
{
#If SetError was filled, throw to exit out of the try/catch loop