首页 > 系统相关 >powershell-管理windows update自动补丁更新

powershell-管理windows update自动补丁更新

时间:2023-02-19 17:32:10浏览次数:42  
标签:windows update Write Host Security 安装 powershell Principal

#需要使用powershell5.0以上版本
Install-Module PSWindowsUpdate
# 检查管理员权限
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
Write-Host "请以管理员身份运行此脚本。" -ForegroundColor Red
Exit 1
}

# 搜索并安装安全更新
Write-Host "搜索并安装安全更新..."
$updates = Get-WindowsUpdate -Category SecurityUpdates
foreach ($update in $updates) {
$title = $update.Title
Write-Host "安装更新: $title"
Install-WindowsUpdate -KBArticleID $update.KnowledgebaseArticleID
}

# 结束脚本
Write-Host "安装完成。"
Exit 0
#脚本2、扫描下载的补丁文件进行安装
for /f "delims=" %%a in ('dir /b /a-d "C:\Windows\SoftwareDistribution\Download\*.cab"') do start /wait wusa.exe "C:\Windows\SoftwareDistribution\Download\%%a" /quiet /norestart

标签:windows,update,Write,Host,Security,安装,powershell,Principal
From: https://blog.51cto.com/gavenlee/6066775

相关文章

  • Wintel联盟:Windows+Intel  PC时代的“双霸主神话”
     正所谓,时势造英雄。 1981年8月12日,IBM公司正式推出全球第一台个人电脑IBM5150。当时,IBM为了加速研发进度一改公司传统,IBM5150采用通用标准部件,开放除BIOS以外的......
  • Windows系统发展简史
    1983年11月10日,为向IBM公司研发的计算机提供图形用户界面和多任务环境的操作系统,微软公司在纽约广场酒店宣布开发MicrosoftWindows;同月,微软公司CEO比尔·盖茨向IBM展示了......
  • Elasticsearch:Windows 7.17.7 安装
    1.下载ElasticSearchElasticSearch下载地址https://www.elastic.co/cn/downloads/past-releases#elasticsearch根据需要,选择对应的版本下载:2.安装ElasticSearch在......
  • Elasticsearch:Windows 7.17.7 安装(2)
    ElasticSearch下载后可以将其注册为Windows服务,具体可以参考官方说明:https://www.elastic.co/guide/en/elasticsearch/reference/8.6/zip-windows.html#install-windows1......
  • 5.windows安装linux系统
    本章意图将windows系统安装为Linux系统 1.安装的准备:U盘(不小于20G)windows电脑安装软件连接链接:https://pan.baidu.com/s/1QHYv3tif2cX3V6dDQ9nV4w提取码:o1......
  • 虚拟机CentOS 与windows文件共享
    设置windows共享的目录,我设置的为E盘的linuxdir进入Centos执行:yuminstall-ygccgcc-develgcc-c++gcc-c+±develmakekernelkernel-devel重启虚拟机:(重要)错误提示:未......
  • 如何远程SSH到Windows内部的虚拟机?
    1.背景我学校有一台Windows电脑([email protected]),里面安装了一个Ubuntu虚拟机(用户名为y),虚拟机里连着VPN。并且虚拟机的22端口映射到了主机的22端口。通过这个VPN我可以访问另......
  • 删删删!快速将旧版 .NET Framework 的 WPF / Windows Forms 项目格式(csproj) 迁移成新
    原文:http://blog.walterlv.com/post/introduce-new-style-csproj-into-net-framework.html现在再使用VisualStudio创建新的WPF项目时,将默认引诱你使用.NET6(或者5......
  • Mac 上Maven的安装 与配置(Windows也适用)
    Mac上Maven的安装与配置(Windows也适用)1.下载Maven1.HomeBrew安装brewsearchmaven#搜索brewinstallmaven#默认下载最新版本#下载指定版本brewinstal......
  • windows任务栏设置
    每个显示器任务栏显示自己的窗口启用后,你会看到在使用多个显示器时,显示我的任务栏应用程序下的额外选项。这三个选项是:所有任务栏主任务栏和窗口打开的任务窗口打开时......