Add back Get-HotFix cmdlet (#10740)

This commit is contained in:
Steve Lee authored and Ilya committed 2019-10-11 22:51:43 +05:00
1 parent 54fd7d805d
commit 1fa73e360f
5 files changed
+76 -32

No files matched your search

@@ -22,7 +22,6 @@
<Compile Remove="commands\management\GetClipboardCommand.cs" />
<Compile Remove="commands\management\GetTransactionCommand.cs" />
<Compile Remove="commands\management\GetWMIObjectCommand.cs" />
<Compile Remove="commands\management\Hotfix.cs" />
<Compile Remove="commands\management\InvokeWMIMethodCommand.cs" />
<Compile Remove="commands\management\RegisterWMIEventCommand.cs" />
<Compile Remove="commands\management\RemoveWMIObjectCommand.cs" />
@@ -37,7 +36,6 @@
<Compile Remove="gen\EventlogResources.cs" />
<Compile Remove="gen\TransactionResources.cs" />
<Compile Remove="gen\WebServiceResources.cs" />
<Compile Remove="gen\HotFixResources.cs" />
<Compile Remove="gen\ControlPanelResources.cs" />
<Compile Remove="gen\WmiResources.cs" />
<Compile Remove="gen\ManagementMshSnapInResources.cs" />
@@ -47,7 +45,6 @@
<EmbeddedResource Remove="resources\EventlogResources.resx" />
<EmbeddedResource Remove="resources\TransactionResources.resx" />
<EmbeddedResource Remove="resources\WebServiceResources.resx" />
<EmbeddedResource Remove="resources\HotFixResources.resx" />
<EmbeddedResource Remove="resources\ControlPanelResources.resx" />
<EmbeddedResource Remove="resources\WmiResources.resx" />
<EmbeddedResource Remove="resources\ManagementMshSnapInResources.resx" />
@@ -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 @@ namespace Microsoft.PowerShell.Commands
{
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 @@ namespace Microsoft.PowerShell.Commands
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 @@ namespace Microsoft.PowerShell.Commands
}
#endregion
}
#endif
@@ -66,5 +66,6 @@ CmdletsToExport=@("Add-Content",
"Rename-Computer",
"Get-ComputerInfo",
"Get-TimeZone",
"Set-TimeZone")
"Set-TimeZone",
"Get-HotFix")
}
@@ -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
}
}
@@ -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"