From 677166e175752c9fb7406a47cb5d4fe2ab97f659 Mon Sep 17 00:00:00 2001 From: "Gustafsson, Staffan" Date: Wed, 27 Mar 2019 13:15:26 +0100 Subject: [PATCH 1/2] Fixing progress for Get-ComputerInfo --- .../commands/management/GetComputerInfoCommand.cs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs index 6914b491edd..7a5c782b247 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs @@ -85,7 +85,6 @@ private class MiscInfoGroup #region Instance Data private string _machineName = localMachineName; // we might need to have cmdlet work on another machine - private ProgressRecord _progress = null; /// /// Collection of property names from the Property parameter, @@ -225,17 +224,14 @@ protected override void ProcessRecord() /// private void UpdateProgress(string status) { - if (_progress != null) + status = status ?? ComputerResources.ProgressStatusCompleted; + var progress = new ProgressRecord(0, activity, status); + if (status == null) { - _progress.RecordType = ProgressRecordType.Completed; - WriteProgress(_progress); + progress.RecordType = ProgressRecordType.Completed; } - if (status != null) - { - _progress = new ProgressRecord(0, activity, status); - WriteProgress(_progress); - } + WriteProgress(progress); } /// From db50e54f7732f1e122e4dc421470ffbadc87ce69 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Mon, 1 Apr 2019 10:43:46 -0700 Subject: [PATCH 2/2] Fix the null check as status can never be null --- .../commands/management/GetComputerInfoCommand.cs | 8 ++------ .../Get-ComputerInfo.Tests.ps1 | 12 ++++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs index 7a5c782b247..d43641997f8 100644 --- a/src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/GetComputerInfoCommand.cs @@ -224,12 +224,8 @@ protected override void ProcessRecord() /// private void UpdateProgress(string status) { - status = status ?? ComputerResources.ProgressStatusCompleted; - var progress = new ProgressRecord(0, activity, status); - if (status == null) - { - progress.RecordType = ProgressRecordType.Completed; - } + ProgressRecord progress = new ProgressRecord(0, activity, status ?? ComputerResources.ProgressStatusCompleted); + progress.RecordType = status == null ? ProgressRecordType.Completed : ProgressRecordType.Processing; WriteProgress(progress); } diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ComputerInfo.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ComputerInfo.Tests.ps1 index b9b486b2d7c..ab6f97c5688 100644 --- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ComputerInfo.Tests.ps1 +++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-ComputerInfo.Tests.ps1 @@ -1010,6 +1010,18 @@ try { $computerInfo = Get-ComputerInfo $computerInfo | Should -BeOfType 'Microsoft.PowerShell.Commands.ComputerInfo' } + + It "Verify progress records in Get-ComputerInfo" { + try { + $j = Start-Job { Get-ComputerInfo } + $j | Wait-Job + $j.ChildJobs[0].Progress | Should -HaveCount 9 + $j.ChildJobs[0].Progress[-1].RecordType | Should -Be ([System.Management.Automation.ProgressRecordType]::Completed) + } + finally { + $j | Remove-Job + } + } } Describe "Tests for Get-ComputerInfo" -tags "Feature", "RequireAdminOnWindows" {