powershell - 如果可能,寻求有关完成此 Wsus 脚本的帮助
问题描述
为澄清而编辑:目标在我想要完成的内容中进行了概述。现在我不知道我是否朝着正确的方向前进。所以简而言之,
- 我这样做对吗?(示例是这个单个脚本可能还是我需要多个脚本?在 powershell 中是否有更好的过程来执行此操作?)
- 我如何用我在这里的东西来实现我的目标?它只做我正在寻找的一部分。列出更新应该发送到的计算机的部分以及我正在努力解决的所述计算机上的更新状态。
- 我不指望人们写这个,但帮助我弄清楚。我无法想象我是第一个满足这些需求的人,但只是没有找到类似的脚本来寻求帮助。
背景故事:在过去的几周里,我一直在自学 Powershell 以实现 wsus 报告目标。我到处搜索,试图找到一个可以修改以满足我需要的脚本,但我觉得我有限的技能让这变得困难。目标:预先批准 我正在尝试生成需要批准的更新列表。(这可行)但是对于每个更新,我想列出应该获取此更新的服务器以及更新状态。示例:server1/server2/server3 需要更新 KB12345 并且安装状态等于 X。我只是对处理此问题的最佳方法感到困惑。我可以导出到不同的文件格式。TXT 用于列出“需要批准多少更新”的第一部分,Excel 用于计算机状态部分。我开始玩计算机示波器,但我无法过滤它,所以我可以得到工作站和服务器。它把所有东西都列出来了。目标:验证已安装状态我想在我们的维护窗口期间/之后对此进行第二次检查,以便我们可以确认所有安装正确,并且该报告记录在我们的更改请求中以供审计需求。我尝试过的事情:检查每台计算机以查看是否使用不同的脚本安装了更新需要很长时间,并且取决于可用的工作站。服务器没什么大不了的,因为它们总是在运行。如果 wsus 没有及时更新,我们可以在本地与服务器进行比较,但我需要能够运行它,以便我可以报告本月的工作站。(我只关心每月应用的更新。
我想把它分成两个脚本。一个执行批准列表,另一个在与文本文件中的 KB# 列表进行比较后运行。
我觉得这有点矫枉过正,但我们今年的 SOX 审计如何出现任何问题或担忧都被疯狂地审查了。#注意我脚本中的“清理”是 ISEprofile 的本地函数,每次运行都会清除所有内容。这在投入生产时被删除。
Cleanup
[void][reflection.assembly]::LoadWithPartialName(“Microsoft.UpdateServices.Administration”)
#Connect to the WSUS Server and create the wsus object
$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer(‘wsus’,$False,"8530")
#Variables
#Wsus Variables
$Arrivaldate = ”01/12/2021"
#ApprovedStatus could be the following:Any, declined, hasstaleupdateapprovals, latestrevisionapproved, notapproved
$ApprovedStatus = "notapproved"
$InstallationStatus = "NotInstalled"
#Logging Variables
$Logpath = "D:\scripts\ps1\Testing\Logs\Monthlyupdatelist.txt"
#Create a computer scope object
$computerscope = New-Object Microsoft.UpdateServices.Administration.ComputerTargetScope
#Create UpdateScope
$updatescope = New-Object Microsoft.UpdateServices.Administration.UpdateScope
#Find all clients using the computer target scope
#$wsus.GetComputerTargets($computerscope)
#$Wsus.GetComputerStatus($computerscope,[ Microsoft.UpdateServices.Administration.UpdateSources]::All)
#Find updates based on scope below. Run $updatescope alone to see all the items you can filter by.
$updatescope.ApprovedStates = [Microsoft.UpdateServices.Administration.ApprovedStates]::$ApprovedStatus
$updatescope.IncludedInstallationStates = [Microsoft.UpdateServices.Administration.UpdateInstallationStates]::$InstallationStatus
$updatescope.FromArrivalDate = [datetime]$Arrivaldate
Start-Transcript -Path $Logpath
#This lists how many updates are set in "all updates"
Write-Host "Number of Updates this month to approve:"$wsus.GetUpdateCount($updatescope)
$wsus.GetUpdateStatus($updatescope,$False)
#List out the updates for the month
$Updatelist = $wsus.GetUpdates($updatescope)
$Updatelist | Select Title, UpdateClassificationTitle, KnowledgebaseArticles, ProductTitles, ArrivalDate, IsApproved, IsDeclined
Stop-Transcript
解决方案
推荐阅读
- python - 让用户输入一个整数,或在 python 中按“q”退出
- angular - 以角度 8 将变量附加到字符串
- python - python - 如何使用python中的变量进行Sql更新?
- c++ - 我使用了 sprintf(),为什么 VC++ 抱怨 _swprintf()?
- javascript - 重新定位梅西问框
- c++ - 如何在 C++ 中将 do while 循环转换为 while 循环?
- android - 我的 Admob 广告未在我的应用中显示,出现错误代码 3“无广告配置”如何解决,我的测试广告也正常工作
- javascript - 在 vue 可拖动的每次更改后获取数组 ID
- html - 为什么“价格和时间”表头没有完全覆盖该部门
- java - 序列化和反序列化属性不一致