@@ -554,13 +554,7 @@ private List<ExternalRule> GetExternalRule(string[] moduleNames)
554554 {
555555 posh . AddCommand ( "Get-Module" ) . AddParameter ( "Name" , moduleName ) . AddParameter ( "ListAvailable" ) ;
556556 shortModuleName = posh . Invoke < PSModuleInfo > ( ) . First ( ) . Name ;
557-
558- // Invokes Update-Help for this module
559- // Required since when invoking Get-Help later on, the cmdlet prompts for Update-Help interactively
560- // By invoking Update-Help first, Get-Help will not prompt for downloading help later
561- posh . AddCommand ( "Update-Help" ) . AddParameter ( "Module" , shortModuleName ) . AddParameter ( "Force" ) ;
562- posh . Invoke ( ) ;
563-
557+
564558 // Invokes Get-Command and Get-Help for each functions in the module.
565559 posh . Commands . Clear ( ) ;
566560 posh . AddCommand ( "Get-Command" ) . AddParameter ( "Module" , shortModuleName ) ;
@@ -586,8 +580,21 @@ private List<ExternalRule> GetExternalRule(string[] moduleNames)
586580 //Only add functions that are defined as rules.
587581 if ( param != null )
588582 {
589- posh . AddCommand ( "Get-Help" ) . AddParameter ( "Name" , funcInfo . Name ) ;
590- Collection < PSObject > helpContent = posh . Invoke ( ) ;
583+ // On a new image, when Get-Help is run the first time, PowerShell offers to download updated help content
584+ // using Update-Help. This results in an interactive prompt - which we cannot handle
585+ // Workaround to prevent Update-Help from running is to set the following reg key
586+ // HKLM:\Software\Microsoft\PowerShell\DisablePromptToUpdateHelp
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+ }
591598
592599 // Retrieve "Description" field in the help content
593600 string desc = String . Empty ;
0 commit comments