我的要求是在我的系统中安装所有的最新更新。"get-wmiobject“提供了系统中安装的所有更新的数据。我在这里写的代码是
方法1:
$y = get-wmiobject -class win32_quickfixengineering | sort-object -Property InstalledOn -Descending | select-object -Property * -First 1
$x = Get-Date $y.InstalledOn
Write-Host $x
get-wmiobject -class win32_quickfixengineering -Filter "InstalledOn='$x'" 方法2:
$y = get-wmiobject -class win32_quickfixengineering | sort-object -Property InstalledOn -Descending | select-object -Property * -First 1
$z = $y.InstalledOn
Write-Host $z
get-wmiobject -class win32_quickfixengineering -Filter "InstalledOn='$z'" 所有这些都给了我空的输出。所有这些都将用于筛选字符串,但不适用于日期筛选。这里怎么了?
然而,下面的代码正在工作:
$y = get-wmiobject -class win32_quickfixengineering | sort-object -Property InstalledOn -Descending | select-object -Property * -First 1
get-wmiobject -class win32_quickfixengineering | Where-Object {$_.InstalledOn -eq $y.InstalledOn}我想知道为什么过滤器不工作。
发布于 2020-04-23 08:53:56
我不知道为什么您试图使用的-Filter不起作用。我根本不能让它起作用。据推测,所使用的QueryLanguage有一些奇怪之处,但没有得到明确的记录。叹息..。
但是,如果您想要的只是QFE列表中最后一天应用的QFE项,下面的工作是.笑一笑
Get-HotFix代替CIM/WMi调用这并不是更快,但它似乎更有力量。
InstalledOn属性排序,
H 214H 115>组中选择第一组
获取.Group值,并将其分配给$NewestQFE_Group H 217H 118显示在屏幕上H 219F>密码..。
$NewestQFE_Group = (Get-HotFix |
Sort-Object -Descending -Property 'InstalledOn' |
Group-Object -Property 'InstalledOn')[0].Group
$NewestQFE_Group输出[是的,我还在win7上笑].
Source Description HotFixID InstalledBy InstalledOn
------ ----------- -------- ----------- -----------
MySysName Security Update KB4534310 NT AUTHORITY\SYSTEM 2020-01-15 12:00:00 AM
MySysName Security Update KB4536952 NT AUTHORITY\SYSTEM 2020-01-15 12:00:00 AM
MySysName Update KB4532945 NT AUTHORITY\SYSTEM 2020-01-15 12:00:00 AM发布于 2020-04-23 13:52:47
Installedon是一个scriptproperty,它将原始字符串(如'8/2/2019‘)转换为datetime对象。原来的字符串对排序不好。
$a = get-wmiobject win32_quickfixengineering | select -last 1
$a | gm installedon | fl *
TypeName : System.Management.ManagementObject#root\cimv2\Win32_QuickFixEngineering
Name : InstalledOn
MemberType : ScriptProperty
Definition : System.Object InstalledOn {get=if ([environment]::osversion.version.build -ge 7000)
{
# WMI team fixed the formatting issue related to InstalledOn
# property in Windows7 (to return string)..so returning the WMI's
# version directly
[DateTime]::Parse($this.psBase.properties["InstalledOn"].Value,
[System.Globalization.DateTimeFormatInfo]::new())
}
else
{
$orig = $this.psBase.properties["InstalledOn"].Value
$date = [datetime]::FromFileTimeUTC($("0x" + $orig))
if ($date -lt "1/1/1980")
{
if ($orig -match "([0-9]{4})([01][0-9])([012][0-9])")
{
new-object datetime @([int]$matches[1], [int]$matches[2], [int]$matches[3])
}
}
else
{
$date
}
};}
$a.psbase.properties['installedon'].value
8/2/2019
get-wmiobject win32_quickfixengineering -filter "installedon='8/2/2019'"
Source Description HotFixID InstalledBy InstalledOn
------ ----------- -------- ----------- -----------
DESKTOP-JQ... Security Update KB4493470 NT AUTHORITY\SYSTEM 8/2/2019 12:00:00 AMhttps://stackoverflow.com/questions/61380280
复制相似问题