Baseline throws a silent error. Suggestion for a quick fix in BaselineLocalInstall.ps1

%3CLINGO-SUB%20id%3D%22lingo-sub-1951221%22%20slang%3D%22en-US%22%3EBaseline%20throws%20a%20silent%20error.%20Suggestion%20for%20a%20quick%20fix%20in%20BaselineLocalInstall.ps1%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1951221%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ethe%20BaselineLocalInstall.ps1%20in%20SCT%201.0%20for%20Server%202019%20throws%20a%20silent%20error%20under%20certain%20circumstances%20that%20is%20added%20to%20the%20error%20variable.%20Responsible%20is%20line%20147%3A%3C%2FP%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3CP%3E%3CSTRONG%3E%3CSPAN%3Eif%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B(%3C%2FSPAN%3E%3CSPAN%3E%24null%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B-eq%26nbsp%3B(%3C%2FSPAN%3E%3CSPAN%3EGet-Command%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSPAN%3ELGPO.exe%3C%2FSPAN%3E%3CSPAN%3E%26nbsp%3B-ErrorAction%26nbsp%3BSilentlyContinue))%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EWhen%20the%20script%20runs%20successful%2C%20this%20is%20the%20only%20error%20in%20%24Error.%20Since%20%24Error%20is%20currently%20the%20only%20way%20to%20check%20whether%20the%20baseline%20script%20ran%20successful%20or%20not%2C%20this%20causes%20an%20issue.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThe%20fix%20is%20simple%2C%20however.%20Please%20replace%20the%20error%20action%20with%20%3CSTRONG%3EIgnore%3C%2FSTRONG%3E.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3E%3CSTRONG%3Eif%26nbsp%3B(%24null%26nbsp%3B-eq%26nbsp%3B(Get-Command%26nbsp%3BLGPO.exe%26nbsp%3B-ErrorAction%26nbsp%3BIgnore))%3C%2FSTRONG%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%3EThis%20acts%20like%20SilentlyContinue%20but%20does%20not%20add%20the%20error%20to%20the%20%24Error%20variable%2C%20and%20if%20the%20script%20ran%20successful%20%24Error%20will%20be%20empty.%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1951238%22%20slang%3D%22en-US%22%3ERe%3A%20Baseline%20throws%20a%20silent%20error.%20Suggestion%20for%20a%20quick%20fix%20in%20BaselineLocalInstall.ps1%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1951238%22%20slang%3D%22en-US%22%3E%3CP%3EAlso%20pinging%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F272514%22%20target%3D%22_blank%22%3E%40Rick_Munck%3C%2FA%3E%26nbsp%3B%20for%20that%20to%20see.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Regular Contributor

Hi,

 

the BaselineLocalInstall.ps1 in SCT 1.0 for Server 2019 throws a silent error under certain circumstances that is added to the error variable. Responsible is line 147:

 

if ($null -eq (Get-Command LGPO.exe -ErrorAction SilentlyContinue))

 

When the script runs successful, this is the only error in $Error. Since $Error is currently the only way to check whether the baseline script ran successful or not, this causes an issue.

 

The fix is simple, however. Please replace the error action with Ignore.

 

if ($null -eq (Get-Command LGPO.exe -ErrorAction Ignore))

 

This acts like SilentlyContinue but does not add the error to the $Error variable, and if the script ran successful $Error will be empty.

 

3 Replies

@Daniel Niccoli @Rick_Munck - that change makes sense to me. Good idea - thanks.

@Daniel Niccoli we greatly appreciate the suggestion and will make the change in the Final 20H2 package we are planning to release towards the middle of the month!