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 @@ -19,7 +19,7 @@ namespace Microsoft.PowerShell.Commands
/// Cmdlet for Get-Hotfix Proxy.
/// </summary>
[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
{
Expand Down Expand Up @@ -66,52 +66,61 @@ public sealed class GetHotFixCommand : PSCmdlet, IDisposable
private ManagementObjectSearcher _searchProcess;

private bool _inputContainsWildcard = false;
private readonly ConnectionOptions _connectionOptions = new ConnectionOptions { };

/// <summary>
/// Get the List of HotFixes installed on the Local Machine.
/// Sets connection options.
/// </summary>
protected override void BeginProcessing()
{
_connectionOptions.Authentication = AuthenticationLevel.Packet;
_connectionOptions.Impersonation = ImpersonationLevel.Impersonate;
_connectionOptions.Username = Credential?.UserName;
_connectionOptions.SecurePassword = Credential?.Password;
}

/// <summary>
/// Get the List of HotFixes installed on the Local Machine.
/// </summary>
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
{
Expand All @@ -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
}
}

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion test/powershell/engine/Help/assets/HelpURI/V2Cmdlets.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down