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
23
23
using System . Management . Automation . Runspaces ;
24
24
using Microsoft . PowerShell . EditorServices . Session . Capabilities ;
25
25
using System . IO ;
26
+ using System . Security ;
26
27
27
28
/// <summary>
28
29
/// Manages the lifetime and usage of a PowerShell session.
@@ -1302,10 +1303,18 @@ private void SetExecutionPolicy(ExecutionPolicy desiredExecutionPolicy)
1302
1303
. AddParameter ( "Scope" , ExecutionPolicyScope . Process )
1303
1304
. AddParameter ( "Force" ) ;
1304
1305
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
+ }
1307
1316
1308
- // TODO: Ensure there were no errors?
1317
+ this . powerShell . Commands . Clear ( ) ;
1309
1318
}
1310
1319
else
1311
1320
{
You can’t perform that action at this time.
0 commit comments