Skip to content

Commit fbb2c52

Browse files
committed
(maint) Do not error when Execution Policy cannot be determined
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.
1 parent 19ee965 commit fbb2c52

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/bolt/shell/powershell/snippets.rb

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,21 +55,25 @@ def run_script(arguments, script_path)
5555
}
5656
#{build_arg_list}
5757
58-
switch -regex ( Get-ExecutionPolicy )
58+
try
5959
{
60-
'^AllSigned'
60+
switch -regex ( Get-ExecutionPolicy )
6161
{
62-
if ((Get-AuthenticodeSignature -File "#{script_path}").Status -ne 'Valid') {
63-
$Host.UI.WriteErrorLine("Error: Target host Powershell ExecutionPolicy is set to ${_} and script '#{script_path}' does not contain a valid signature.")
62+
'^AllSigned'
63+
{
64+
if ((Get-AuthenticodeSignature -File "#{script_path}").Status -ne 'Valid') {
65+
$Host.UI.WriteErrorLine("Error: Target host Powershell ExecutionPolicy is set to ${_} and script '#{script_path}' does not contain a valid signature.")
66+
exit 1;
67+
}
68+
}
69+
'^Restricted'
70+
{
71+
$Host.UI.WriteErrorLine("Error: Target host Powershell ExecutionPolicy is set to ${_} which denies running any scripts on the target.")
6472
exit 1;
6573
}
6674
}
67-
'^Restricted'
68-
{
69-
$Host.UI.WriteErrorLine("Error: Target host Powershell ExecutionPolicy is set to ${_} which denies running any scripts on the target.")
70-
exit 1;
71-
}
7275
}
76+
catch {}
7377
7478
if([string]::IsNullOrEmpty($invokeArgs.ScriptBlock)){
7579
$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");

0 commit comments

Comments
 (0)