From 9634fddb3ec8116be055d1243cee1ce64ef4e6f8 Mon Sep 17 00:00:00 2001 From: donoghuc Date: Wed, 3 Apr 2024 09:06:25 -0700 Subject: [PATCH] test theory --- lib/bolt/shell/powershell/snippets.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/bolt/shell/powershell/snippets.rb b/lib/bolt/shell/powershell/snippets.rb index 6cd35e9fe2..7f7cf6d6ab 100644 --- a/lib/bolt/shell/powershell/snippets.rb +++ b/lib/bolt/shell/powershell/snippets.rb @@ -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");