powershell - 如何在powershell中只显示前三行输出
问题描述
我正在尝试创建一个脚本,该脚本将检查对 Windows 机器进行最新更新的时间。然后,如果最近的更新超过 90 天,请向 itadmin 电子邮件发送电子邮件通知并运行更新(我还没有添加电子邮件部分,但这只是一个复制意大利面)。我遇到的问题是我只想在 get-WUHistory 中显示三个最近的更新,并让可变的更新时间赶上这些。关于如何做到这一点的任何想法?提前感谢您的帮助。
另外我应该补充一点,我对 Powershell 的经验很少,大约两周前我才开始使用它,所以这可能是一个愚蠢的问题。
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Install-Module PSWindowsUpdate -Force
Import-Module PSWindowsUpdate -Force
$Version = (Get-Item "HKLM:SOFTWARE\Microsoft\Windows NT\CurrentVersion").GetValue('ReleaseID')
$Date = (Get-Date).AddDays(-90)
$UpdateTime = Get-WUHistory | Format-List -Property Date
Write-Output $Version
If($UpdateTime -lt $Date){
########################
}
If($version -lt 1909){
Write-Host("This computer is not up to date") -ForegroundColor Red
Get-WindowsUpdate -MicrosoftUpdate -Download
}
else {
Write-Host("This computer is up to date" ) -foregroundcolor green
Write-Host("Checking for patches") -ForegroundColor Green
Get-WindowsUpdate -MicrosoftUpdate -category "Security Updates" -Severity Critical,Important,Moderate
}
#Restart-Computer -force
解决方案
推荐阅读
- oracle - 插入到报告中的图像具有灰色背景
- c - 交换链表中的某些元素
- javascript - 从 html 表中追加数据而不是另存为新文件
- python - 如何修复 tkinter 中的“'int' object is not iterable”错误
- ios - CLI 命令未上传 dSYM
- php - 如何用 php 打印这些 json 值
- javascript - Jest 中的 resetAllMocks、resetModules、resetModuleRegistry、restoreAllMocks 之间的区别
- python - 我正在尝试获取我打印的内容并将其添加到列表中以作为员工工资单打印出来
- html - 将谷歌表格中的一周时间表整合到 webnode 网站中
- python - 在散景图的轴上突出显示许多范围?