diff --git a/src/Microsoft.PowerShell.Commands.Management/commands/management/Hotfix.cs b/src/Microsoft.PowerShell.Commands.Management/commands/management/Hotfix.cs
index 0c72d9ca646..85257270a77 100644
--- a/src/Microsoft.PowerShell.Commands.Management/commands/management/Hotfix.cs
+++ b/src/Microsoft.PowerShell.Commands.Management/commands/management/Hotfix.cs
@@ -19,7 +19,7 @@ namespace Microsoft.PowerShell.Commands
/// Cmdlet for Get-Hotfix Proxy.
///
[Cmdlet(VerbsCommon.Get, "HotFix", DefaultParameterSetName = "Default",
- HelpUri = "https://go.microsoft.com/fwlink/?LinkID=135217", RemotingCapability = RemotingCapability.SupportedByCommand)]
+ HelpUri = "https://go.microsoft.com/fwlink/?linkid=2109716", RemotingCapability = RemotingCapability.SupportedByCommand)]
[OutputType(@"System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering")]
public sealed class GetHotFixCommand : PSCmdlet, IDisposable
{
@@ -66,52 +66,61 @@ public sealed class GetHotFixCommand : PSCmdlet, IDisposable
private ManagementObjectSearcher _searchProcess;
private bool _inputContainsWildcard = false;
+ private readonly ConnectionOptions _connectionOptions = new ConnectionOptions { };
+
///
- /// Get the List of HotFixes installed on the Local Machine.
+ /// Sets connection options.
///
protected override void BeginProcessing()
+ {
+ _connectionOptions.Authentication = AuthenticationLevel.Packet;
+ _connectionOptions.Impersonation = ImpersonationLevel.Impersonate;
+ _connectionOptions.Username = Credential?.UserName;
+ _connectionOptions.SecurePassword = Credential?.Password;
+ }
+
+ ///
+ /// Get the List of HotFixes installed on the Local Machine.
+ ///
+ protected override void ProcessRecord()
{
foreach (string computer in ComputerName)
{
bool foundRecord = false;
- StringBuilder QueryString = new StringBuilder();
- 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);
+ StringBuilder queryString = new StringBuilder();
+ ManagementScope scope = new ManagementScope(ComputerWMIHelper.GetScopeString(computer, ComputerWMIHelper.WMI_Path_CIM), _connectionOptions);
scope.Connect();
if (Id != null)
{
- QueryString.Append("Select * from Win32_QuickFixEngineering where (");
+ queryString.Append("Select * from Win32_QuickFixEngineering where (");
for (int i = 0; i <= Id.Length - 1; i++)
{
- QueryString.Append("HotFixID= '");
- QueryString.Append(Id[i].ToString().Replace("'", "\\'"));
- QueryString.Append("'");
+ queryString.Append("HotFixID= '");
+ queryString.Append(Id[i].Replace("'", "\\'"));
+ queryString.Append("'");
if (i < Id.Length - 1)
- QueryString.Append(" Or ");
+ {
+ queryString.Append(" Or ");
+ }
}
- QueryString.Append(")");
+ queryString.Append(")");
}
else
{
- QueryString.Append("Select * from Win32_QuickFixEngineering");
+ queryString.Append("Select * from Win32_QuickFixEngineering");
foundRecord = true;
}
- _searchProcess = new ManagementObjectSearcher(scope, new ObjectQuery(QueryString.ToString()));
+ _searchProcess = new ManagementObjectSearcher(scope, new ObjectQuery(queryString.ToString()));
foreach (ManagementObject obj in _searchProcess.Get())
{
if (Description != null)
{
if (!FilterMatch(obj))
+ {
continue;
+ }
}
else
{
@@ -126,13 +135,15 @@ protected override void BeginProcessing()
try
{
SecurityIdentifier secObj = new SecurityIdentifier(installed);
- obj["InstalledBy"] = secObj.Translate(typeof(NTAccount)); ;
+ obj["InstalledBy"] = secObj.Translate(typeof(NTAccount));
}
- catch (IdentityNotMappedException) // thrown by SecurityIdentifier.Translate
+ catch (IdentityNotMappedException)
{
+ // thrown by SecurityIdentifier.Translate
}
- catch (SystemException) // thrown by SecurityIdentifier.constr
+ catch (SystemException)
{
+ // thrown by SecurityIdentifier.constr
}
}
@@ -142,8 +153,8 @@ protected override void BeginProcessing()
if (!foundRecord && !_inputContainsWildcard)
{
- Exception Ex = new ArgumentException(StringUtil.Format(HotFixResources.NoEntriesFound, computer));
- WriteError(new ErrorRecord(Ex, "GetHotFixNoEntriesFound", ErrorCategory.ObjectNotFound, null));
+ Exception ex = new ArgumentException(StringUtil.Format(HotFixResources.NoEntriesFound, computer));
+ WriteError(new ErrorRecord(ex, "GetHotFixNoEntriesFound", ErrorCategory.ObjectNotFound, null));
}
if (_searchProcess != null)
diff --git a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-HotFix.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-HotFix.Tests.ps1
index 8169ebc50ca..715893da360 100644
--- a/test/powershell/Modules/Microsoft.PowerShell.Management/Get-HotFix.Tests.ps1
+++ b/test/powershell/Modules/Microsoft.PowerShell.Management/Get-HotFix.Tests.ps1
@@ -58,4 +58,9 @@ Describe "Get-HotFix Tests" -Tag CI {
$hotfixes = Get-HotFix -ComputerName localhost
$hotfixes.Count | Should -Be $qfe.Count
}
+
+ It "Get-Hotfix can accept ComputerName via pipeline" {
+ { [PSCustomObject]@{ComputerName = 'UnavailableComputer'} | Get-HotFix } |Should -Throw -ErrorID 'Microsoft.PowerShell.Commands.GetHotFixCommand'
+ [PSCustomObject]@{ComputerName = 'localhost'} | Get-HotFix | Should -Not -BeNullOrEmpty
+ }
}
diff --git a/test/powershell/engine/Help/assets/HelpURI/V2Cmdlets.csv b/test/powershell/engine/Help/assets/HelpURI/V2Cmdlets.csv
index d663fb8fcd5..39a7909408c 100644
--- a/test/powershell/engine/Help/assets/HelpURI/V2Cmdlets.csv
+++ b/test/powershell/engine/Help/assets/HelpURI/V2Cmdlets.csv
@@ -69,7 +69,7 @@ Get-FormatData,https://go.microsoft.com/fwlink/?LinkID=144303
Get-Help,https://go.microsoft.com/fwlink/?LinkID=113316
Get-History,https://go.microsoft.com/fwlink/?LinkID=113317
Get-Host,https://go.microsoft.com/fwlink/?LinkID=113318
-Get-Hotfix,https://go.microsoft.com/fwlink/?LinkID=135217
+Get-Hotfix,https://go.microsoft.com/fwlink/?linkid=2109716
Get-Item,https://go.microsoft.com/fwlink/?LinkID=113319
Get-ItemProperty,https://go.microsoft.com/fwlink/?LinkID=113320
Get-Job,https://go.microsoft.com/fwlink/?LinkID=113328