Take ComputerName via Pipeline in Get-HotFix (#10852)
* add process record for Get-hotfix * update new FWLink
This commit is contained in:
parent
cca5bceb0f
commit
5a76137d14
@ -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
|
||||
{
|
||||
@ -66,52 +66,61 @@ namespace Microsoft.PowerShell.Commands
|
||||
private ManagementObjectSearcher _searchProcess;
|
||||
|
||||
private bool _inputContainsWildcard = false;
|
||||
private readonly ConnectionOptions _connectionOptions = new ConnectionOptions { };
|
||||
|
||||
/// <summary>
|
||||
/// 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 BeginProcessing()
|
||||
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 @@ namespace Microsoft.PowerShell.Commands
|
||||
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 @@ namespace Microsoft.PowerShell.Commands
|
||||
|
||||
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)
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user