Skip to content

Commit

Permalink
(maint) Do not error when Execution Policy cannot be determined
Browse files Browse the repository at this point in the history
We attempt to compute Execution Policy in order to provide a nice error message for some cases. We are seeing failures in some cases to compute this value. In the case the execution policy cannot be determined we still want to be able to attempt to run the action. This commit handles errors when execution policy cannot be determined.
  • Loading branch information
donoghuc committed Apr 3, 2024
1 parent 19ee965 commit fbb2c52
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/bolt/shell/powershell/snippets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,25 @@ def run_script(arguments, script_path)
}
#{build_arg_list}
switch -regex ( Get-ExecutionPolicy )
try
{
'^AllSigned'
switch -regex ( Get-ExecutionPolicy )
{
if ((Get-AuthenticodeSignature -File "#{script_path}").Status -ne 'Valid') {
$Host.UI.WriteErrorLine("Error: Target host Powershell ExecutionPolicy is set to ${_} and script '#{script_path}' does not contain a valid signature.")
'^AllSigned'
{
if ((Get-AuthenticodeSignature -File "#{script_path}").Status -ne 'Valid') {
$Host.UI.WriteErrorLine("Error: Target host Powershell ExecutionPolicy is set to ${_} and script '#{script_path}' does not contain a valid signature.")
exit 1;
}
}
'^Restricted'
{
$Host.UI.WriteErrorLine("Error: Target host Powershell ExecutionPolicy is set to ${_} which denies running any scripts on the target.")
exit 1;
}
}
'^Restricted'
{
$Host.UI.WriteErrorLine("Error: Target host Powershell ExecutionPolicy is set to ${_} which denies running any scripts on the target.")
exit 1;
}
}
catch {}
if([string]::IsNullOrEmpty($invokeArgs.ScriptBlock)){
$Host.UI.WriteErrorLine("Error: Failed to obtain scriptblock from '#{script_path}'. Running scripts might be disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170");
Expand Down

0 comments on commit fbb2c52

Please sign in to comment.