Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand All @@ -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" />
Expand All @@ -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" />
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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?)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow, was powershell v1 supported on win95 (I though PS came out only around the XP times)? Or is this still from Monad days?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if v1 actually supported 95, although I suspect not. This error seems like a developer trying to cover their bases for exceptions.

// { 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);
Expand Down Expand Up @@ -244,3 +227,5 @@ public void Dispose(bool disposing)
}
#endregion
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,6 @@ CmdletsToExport=@("Add-Content",
"Rename-Computer",
"Get-ComputerInfo",
"Get-TimeZone",
"Set-TimeZone")
"Set-TimeZone",
"Get-HotFix")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: For a cleaner history, it would've been be nice if parentheses/commas were placed in such a way that the last line does not require any change for the next addition (i.e. have the closing parenthesis in this case on the next line).

}
Original file line number Diff line number Diff line change
@@ -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
}
}
2 changes: 1 addition & 1 deletion test/powershell/engine/Basic/DefaultCommands.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down