windows – 通过PowerShell自动化WSUS

我编写了一个脚本,旨在快速管理 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中有更多信息,但上述信息将为您提供有关组的信息.

相关文章

文章浏览阅读2.2k次,点赞6次,收藏20次。在我们平时办公工作...
文章浏览阅读1k次。解决 Windows make command not found 和...
文章浏览阅读3.2k次,点赞2次,收藏6次。2、鼠标依次点击“计...
文章浏览阅读1.3w次。蓝光版属于高清版的一种。BD英文全名是...
文章浏览阅读974次,点赞7次,收藏8次。提供了更强大的功能,...
文章浏览阅读1.4w次,点赞5次,收藏22次。如果使用iterator的...