File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
src/PowerShellEditorServices/Session Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ namespace Microsoft.PowerShell.EditorServices
2323 using System . Management . Automation . Runspaces ;
2424 using Microsoft . PowerShell . EditorServices . Session . Capabilities ;
2525 using System . IO ;
26+ using System . Security ;
2627
2728 /// <summary>
2829 /// Manages the lifetime and usage of a PowerShell session.
@@ -1302,10 +1303,18 @@ private void SetExecutionPolicy(ExecutionPolicy desiredExecutionPolicy)
13021303 . AddParameter ( "Scope" , ExecutionPolicyScope . Process )
13031304 . AddParameter ( "Force" ) ;
13041305
1305- this . powerShell . Invoke ( ) ;
1306- this . powerShell . Commands . Clear ( ) ;
1306+ try
1307+ {
1308+ this . powerShell . Invoke ( ) ;
1309+ }
1310+ catch ( CmdletInvocationException e )
1311+ {
1312+ Logger . WriteException (
1313+ $ "An error occurred while calling Set-ExecutionPolicy, the desired policy of { desiredExecutionPolicy } may not be set.",
1314+ e ) ;
1315+ }
13071316
1308- // TODO: Ensure there were no errors?
1317+ this . powerShell . Commands . Clear ( ) ;
13091318 }
13101319 else
13111320 {
You can’t perform that action at this time.
0 commit comments