加入收藏 | 设为首页 | 会员中心 | 我要投稿 衡阳站长网 (https://www.0734zz.cn/)- 数据集成、设备管理、备份、数据加密、智能搜索!
当前位置: 首页 > 服务器 > 搭建环境 > Windows > 正文

windows – 通过PowerShell自动化WSUS

发布时间:2021-01-11 23:15:37 所属栏目:Windows 来源:网络整理
导读:我编写了一个脚本,旨在快速管理 WSUS进程,我有一些我硬编码的东西,但宁愿使用PowerShell.特别是,Approve-WsusUpdate的“目标”组. 目前我正在做这样的事情: #Select Target Group for Update Approval:$TargetComputerGroups = "All Computers","Unassigned

我编写了一个脚本,旨在快速管理 WSUS进程,我有一些我硬编码的东西,但宁愿使用PowerShell.特别是,Approve-WsusUpdate的“目标”组.

目前我正在做这样的事情:

#Select Target Group for Update Approval:

$TargetComputerGroups = "All Computers","Unassigned Computers","Clients","Servers","Test","View Templates"

$UserPrompt = @"

Please select a Computer Group from the below options:

1) All Computers (Selects all of the below)
2) Unassigned Computers
3) Clients
4) Servers
5) Test
6) View Templates

Enter selection
"@

###Record user selection to varirable
$TargetComputerGroupTemp = Read-Host -Prompt $UserPrompt

###Convert their choice to the correct 0-index array value.
$TargetComputerIndex = $TargetComputerGroupTemp -1

$ComputerTarget = $TargetComputerGroups[$TargetComputerIndex]

是否有’get-targets’命令可以创建一系列可用的目标组?这样我就可以删除$TargetComputerGroups的手动声明.

另外,我想让$UserPrompt成为更好的代码集(再次避免手动声明).我觉得做’$i for $i for $TargetComputerGroups’写主机’按1给我’

话虽如此,我对此非常陌生,所以我不知道最好的方法(理想情况下将他们的选择映射到该语句中的正确组!).

您可以使用PowerShell执行此操作,但您还需要在计算机上安装WSUS管理控制台.

然后,您可以执行以下操作.

[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")

$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer(“wsus_server”,$False)

$wsus

然后,您可以获得目标组列表

$wsus.GetComputerTargetGroups()

或者选择一个组

$targetgroup = $wsus.GetComputerTargetGroups() | ? {$_.Name -eq "some target name"}

在Use PowerShell to Perform Basic Administrative Tasks on WSUS中有更多信息,但上述信息将为您提供有关组的信息.

(编辑:衡阳站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读