-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Add back Get-HotFix cmdlet
#10740
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add back Get-HotFix cmdlet
#10740
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
| { | ||
|
|
@@ -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?) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
|
@@ -244,3 +227,5 @@ public void Dispose(bool disposing) | |
| } | ||
| #endregion | ||
| } | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,5 +66,6 @@ CmdletsToExport=@("Add-Content", | |
| "Rename-Computer", | ||
| "Get-ComputerInfo", | ||
| "Get-TimeZone", | ||
| "Set-TimeZone") | ||
| "Set-TimeZone", | ||
| "Get-HotFix") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
SteveL-MSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| $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 | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.