diff --git a/src/Microsoft.PowerShell.Commands.Management/Microsoft.PowerShell.Commands.Management.csproj b/src/Microsoft.PowerShell.Commands.Management/Microsoft.PowerShell.Commands.Management.csproj
index af023882fb5..ee25f9cb5d8 100644
--- a/src/Microsoft.PowerShell.Commands.Management/Microsoft.PowerShell.Commands.Management.csproj
+++ b/src/Microsoft.PowerShell.Commands.Management/Microsoft.PowerShell.Commands.Management.csproj
@@ -22,7 +22,6 @@
-
@@ -37,7 +36,6 @@
-
@@ -47,7 +45,6 @@
-
diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Hotfix.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Hotfix.cs
index d0f892d3cfe..0c72d9ca646 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Hotfix.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Hotfix.cs
@@ -1,30 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
+#if !UNIX
+
using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Collections.Specialized;
-using System.ComponentModel; // Win32Exception
using System.Diagnostics.CodeAnalysis;
-using System.Diagnostics; // Process class
-using System.Globalization;
-using System.IO;
using System.Management;
using System.Management.Automation;
using System.Management.Automation.Internal;
-using System.Net;
-using System.Runtime.Serialization;
-using System.Security;
-using System.Security.AccessControl;
-using System.Security.Permissions;
using System.Security.Principal;
using System.Text;
-using System.Text.RegularExpressions;
-using System.Threading;
-
-using Dbg = System.Management.Automation;
namespace Microsoft.PowerShell.Commands
{
@@ -90,7 +75,14 @@ protected override void BeginProcessing()
{
bool foundRecord = false;
StringBuilder QueryString = new StringBuilder();
- ConnectionOptions conOptions = ComputerWMIHelper.GetConnectionOptions(AuthenticationLevel.Packet, ImpersonationLevel.Impersonate, this.Credential);
+ ConnectionOptions conOptions = new ConnectionOptions
+ {
+ Authentication = AuthenticationLevel.Packet,
+ Impersonation = ImpersonationLevel.Impersonate,
+ Username = Credential?.UserName,
+ SecurePassword = Credential?.Password
+ };
+
ManagementScope scope = new ManagementScope(ComputerWMIHelper.GetScopeString(computer, ComputerWMIHelper.WMI_Path_CIM), conOptions);
scope.Connect();
if (Id != null)
@@ -142,15 +134,6 @@ protected override void BeginProcessing()
catch (SystemException) // thrown by SecurityIdentifier.constr
{
}
- // catch (ArgumentException) // thrown (indirectly) by SecurityIdentifier.constr (on XP only?)
- // { catch not needed - this is already caught as SystemException
- // }
- // catch (PlatformNotSupportedException) // thrown (indirectly) by SecurityIdentifier.Translate (on Win95 only?)
- // { catch not needed - this is already caught as SystemException
- // }
- // catch (UnauthorizedAccessException) // thrown (indirectly) by SecurityIdentifier.Translate
- // { catch not needed - this is already caught as SystemException
- // }
}
WriteObject(obj);
@@ -244,3 +227,5 @@ public void Dispose(bool disposing)
}
#endregion
}
+
+#endif
diff --git a/src/Modules/Windows/Microsoft.PowerShell.Management/Microsoft.PowerShell.Management.psd1 b/src/Modules/Windows/Microsoft.PowerShell.Management/Microsoft.PowerShell.Management.psd1
index caea6003a72..e9c7a0a7f0a 100644
--- a/src/Modules/Windows/Microsoft.PowerShell.Management/Microsoft.PowerShell.Management.psd1
+++ b/src/Modules/Windows/Microsoft.PowerShell.Management/Microsoft.PowerShell.Management.psd1
@@ -66,5 +66,6 @@ CmdletsToExport=@("Add-Content",
"Rename-Computer",
"Get-ComputerInfo",
"Get-TimeZone",
- "Set-TimeZone")
+ "Set-TimeZone",
+ "Get-HotFix")
}
diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-HotFix.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-HotFix.Tests.ps1
new file mode 100644
index 00000000000..8169ebc50ca
--- /dev/null
+++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-HotFix.Tests.ps1
@@ -0,0 +1,61 @@
+# Copyright (c) Microsoft Corporation. All rights reserved.
+# Licensed under the MIT License.
+
+Describe "Get-HotFix Tests" -Tag CI {
+ BeforeAll {
+ $originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
+
+ $skip = $false
+ if (!$IsWindows) {
+ $skip = $true
+ }
+ else {
+ # skip the tests if there are no hotfixes returned
+ $qfe = Get-CimInstance Win32_QuickFixEngineering
+ if ($qfe.Count -eq 0) {
+ $skip = $true
+ }
+ }
+
+ $PSDefaultParameterValues["it:skip"] = $skip
+ }
+
+ AfterAll {
+ $global:PSDefaultParameterValues = $originalDefaultParameterValues
+ }
+
+ It "Get-HotFix will enumerate all QFEs" {
+ $hotfix = Get-HotFix
+ $hotfix.Count | Should -Be $qfe.Count
+ }
+
+ It "Get-HotFix can filter on -Id" {
+ $testQfe = $qfe[0]
+
+ $hotfix = Get-HotFix -Id $testQfe.HotFixID
+ $hotfix.HotFixID | Should -BeExactly $testQfe.HotFixID
+ $hotfix.Description | Should -BeExactly $testQfe.Description
+ }
+
+ It "Get-HotFix can filter on -Description" {
+ $testQfes = $qfe | Where-Object { $_.Description -eq 'Update' }
+ if ($testQfes.Count -gt 0) {
+ $hotfixes = Get-HotFix -Description 'Update'
+ }
+ elseif ($qfe.Count -gt 0) {
+ $description = $qfe[0].Description
+ $testQfes = $qfe | Where-Object { $_.Description -eq $description }
+ $hotfixes = Get-HotFix -Desscription $description
+ }
+
+ # if no applicable qfes are found on test system, this test will still
+ # pass as both will have count 0
+
+ $hotfixes.Count | Should -Be $testQfes.Count
+ }
+
+ It "Get-HotFix can use -ComputerName" {
+ $hotfixes = Get-HotFix -ComputerName localhost
+ $hotfixes.Count | Should -Be $qfe.Count
+ }
+}
diff --git a/test/powershell/engine/Basic/DefaultCommands.Tests.ps1 b/test/powershell/engine/Basic/DefaultCommands.Tests.ps1
index f08f9dc54db..b2c69a648fd 100644
--- a/test/powershell/engine/Basic/DefaultCommands.Tests.ps1
+++ b/test/powershell/engine/Basic/DefaultCommands.Tests.ps1
@@ -279,7 +279,7 @@ Describe "Verify approved aliases list" -Tags "CI" {
"Cmdlet", "Get-Help", "", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", "None"
"Cmdlet", "Get-History", "", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", "None"
"Cmdlet", "Get-Host", "", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", "None"
-"Cmdlet", "Get-HotFix", "", $($FullCLR ), "", "", ""
+"Cmdlet", "Get-HotFix", "", $($FullCLR -or $CoreWindows ), "", "", "None"
"Cmdlet", "Get-Item", "", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", "None"
"Cmdlet", "Get-ItemProperty", "", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", "None"
"Cmdlet", "Get-ItemPropertyValue", "", $($FullCLR -or $CoreWindows -or $CoreUnix), "", "", "None"