File tree Expand file tree Collapse file tree 3 files changed +38
-5
lines changed
Expand file tree Collapse file tree 3 files changed +38
-5
lines changed Original file line number Diff line number Diff line change @@ -584,9 +584,17 @@ private List<ExternalRule> GetExternalRule(string[] moduleNames)
584584 // using Update-Help. This results in an interactive prompt - which we cannot handle
585585 // Workaround to prevent Update-Help from running is to set the following reg key
586586 // HKLM:\Software\Microsoft\PowerShell\DisablePromptToUpdateHelp
587- // OR execute Update-Help in an elevated admin mode before running ScriptAnalyzer
588- posh . AddCommand ( "Get-Help" ) . AddParameter ( "Name" , funcInfo . Name ) ;
589- Collection < PSObject > helpContent = posh . Invoke ( ) ;
587+ // OR execute Update-Help in an elevated admin mode before running ScriptAnalyzer
588+ Collection < PSObject > helpContent = null ;
589+ try
590+ {
591+ posh . AddCommand ( "Get-Help" ) . AddParameter ( "Name" , funcInfo . Name ) ;
592+ helpContent = posh . Invoke ( ) ;
593+ }
594+ catch ( Exception getHelpException )
595+ {
596+ this . outputWriter . WriteWarning ( getHelpException . Message . ToString ( ) ) ;
597+ }
590598
591599 // Retrieve "Description" field in the help content
592600 string desc = String . Empty ;
Original file line number Diff line number Diff line change @@ -46,8 +46,20 @@ Describe "Test importing correct customized rules" {
4646
4747 $customizedRulePath = Invoke-ScriptAnalyzer $directory \TestScript.ps1 - CustomizedRulePath $directory \samplerule\samplerule.psm1 | Where-Object {$_.Message -eq $message }
4848 $customizedRulePath.Count | Should Be 1
49- }
50-
49+
50+ # Force Get-Help not to prompt for interactive input to download help using Update-Help
51+ # By adding this registry key we force to turn off Get-Help interactivity logic during ScriptRule parsing
52+ $null , " Wow6432Node" | ForEach-Object {
53+ try
54+ {
55+ Set-ItemProperty - Name " DisablePromptToUpdateHelp" - Path " HKLM:\SOFTWARE\$ ( $_ ) \Microsoft\PowerShell" - Value 1 - Force
56+ }
57+ catch
58+ {
59+ # Ignore for cases when tests are running in non-elevated more or registry key does not exist or not accessible
60+ }
61+ }
62+ }
5163 }
5264
5365 Context " Test Get-ScriptAnalyzer with customized rules" {
Original file line number Diff line number Diff line change @@ -134,6 +134,19 @@ $runspace.Open();
134134# Let other test scripts know we are testing library usage now
135135$testingLibraryUsage = $true
136136
137+ # Force Get-Help not to prompt for interactive input to download help using Update-Help
138+ # By adding this registry key we force to turn off Get-Help interactivity logic during ScriptRule parsing
139+ $null , " Wow6432Node" | ForEach-Object {
140+ try
141+ {
142+ Set-ItemProperty - Name " DisablePromptToUpdateHelp" - Path " HKLM:\SOFTWARE\$ ( $_ ) \Microsoft\PowerShell" - Value 1 - Force
143+ }
144+ catch
145+ {
146+ # Ignore for cases when tests are running in non-elevated more or registry key does not exist or not accessible
147+ }
148+ }
149+
137150# Invoke existing test files that use Invoke-ScriptAnalyzer
138151. $directory \InvokeScriptAnalyzer.tests.ps1
139152. $directory \RuleSuppression.tests.ps1
You can’t perform that action at this time.
0 commit comments