我已经写了一个脚本,目的是快速pipe理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”命令可以创build一组可用的目标组? 这样我可以删除$TargetComputerGroups的手动声明。
另外,我想使$UserPrompt成为一组更好的代码(再次避免手动声明)。 我想'$i for $i in $TargetComputerGroups' write-host 'Press 1 for i'执行'$i for $i in $TargetComputerGroups' write-host 'Press 1 for i'
这就是说,我对这个很陌生,所以我不知道这样做的最好方法(理想情况是将他们的select映射到正确的组中)。
您可以使用PowerShell来完成,但是您也需要在计算机上安装WSUSpipe理控制台。
然后您可以执行以下操作。
[void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer(“wsus_server”,$False) $wsus
然后你可以得到一个目标组的列表
$wsus.GetComputerTargetGroups()
或者select一个组
$targetgroup = $wsus.GetComputerTargetGroups() | ? {$_.Name -eq "some target name"}
使用PowerShell在WSUS上执行基本pipe理任务中有更多信息,但上述信息将为您提供关于组的信息。
正如Drifter104所说,目前还没有一个PowerShell模块可用于pipe理WSUS,尽pipe其中一个将包含在下一个Windows Server版本( https://technet.microsoft.com/en-us/library/hh826166.aspx )中。 同时,您需要导入用于pipe理WSUS的.NET程序集并使用它; PowerShell最大的特点之一就是,即使它不包含用于执行给定任务的本地cmdlet,您也可以从中访问完整的.NET环境,并且实际上您可以做任何您能够从.NET应用程序。
关于脚本部分:一旦您获得了数组中的WSUS组的名称,就可以非常方便地构build向用户显示的列表。 只需循环访问数组,并使用索引来select数字:
Write-Host Please select a Computer Group from the below options: $i = 1 foreach($g in $TargetComputerGroups) { Write-Host Press $i for $g $i++ } $sel = Read-Host -Prompt "Enter selection: "