Skip to content

Commit 071e1c6

Browse files
committed
Wrap import of DSC module with ProgressPreference = SilentlyContinue
And set it back afterwards. Since it has `ErrorAction = Ignore` it should always get set back correctly. This prevents the progress pane from getting stuck in certain circumstances.
1 parent 11c3034 commit 071e1c6

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/PowerShellEditorServices/Services/PowerShell/Debugging/DscBreakpointCapability.cs

+5-2
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,13 @@ public static async Task<DscBreakpointCapability> GetDscCapabilityAsync(
9292
if (!isDscInstalled.HasValue)
9393
{
9494
PSCommand psCommand = new PSCommand()
95+
.AddScript("$prevProgressPreference = $ProgressPreference")
96+
.AddScript("$ProgressPreference = 'SilentlyContinue'")
9597
.AddCommand(@"Microsoft.PowerShell.Core\Import-Module")
96-
.AddParameter("-Name", "PSDesiredStateConfiguration")
98+
.AddParameter("Name", "PSDesiredStateConfiguration")
9799
.AddParameter("PassThru")
98-
.AddParameter("ErrorAction", ActionPreference.Ignore);
100+
.AddParameter("ErrorAction", ActionPreference.Ignore)
101+
.AddScript("$ProgressPreference = $prevProgressPreference");
99102

100103
IReadOnlyList<PSModuleInfo> dscModule =
101104
await psesHost.ExecutePSCommandAsync<PSModuleInfo>(

src/PowerShellEditorServices/Services/PowerShell/Utility/PowerShellExtensions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public static void SetCorrectExecutionPolicy(this PowerShell pwsh, ILogger logge
140140
// Calling the cmdlet is the simplest way to do that
141141
IReadOnlyList<PSObject> policies = pwsh
142142
.AddCommand(@"Microsoft.PowerShell.Security\Get-ExecutionPolicy")
143-
.AddParameter("-List")
143+
.AddParameter("List")
144144
.InvokeAndClear<PSObject>();
145145

146146
// The policies come out in the following order:
@@ -223,7 +223,7 @@ public static void LoadProfiles(this PowerShell pwsh, ProfilePathInfo profilePat
223223
public static void ImportModule(this PowerShell pwsh, string moduleNameOrPath)
224224
{
225225
pwsh.AddCommand(@"Microsoft.PowerShell.Core\Import-Module")
226-
.AddParameter("-Name", moduleNameOrPath)
226+
.AddParameter("Name", moduleNameOrPath)
227227
.InvokeAndClear();
228228
}
229229

0 commit comments

Comments
 (0)