windows – 通过PowerShell自动化WSUS

前端之家收集整理的这篇文章主要介绍了windows – 通过PowerShell自动化WSUS前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我编写了一个脚本,旨在快速管理 WSUS进程,我有一些我硬编码的东西,但宁愿使用PowerShell.特别是,Approve-WsusUpdate的“目标”组.

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

  1. #Select Target Group for Update Approval:
  2.  
  3. $TargetComputerGroups = "All Computers","Unassigned Computers","Clients","Servers","Test","View Templates"
  4.  
  5. $UserPrompt = @"
  6.  
  7. Please select a Computer Group from the below options:
  8.  
  9. 1) All Computers (Selects all of the below)
  10. 2) Unassigned Computers
  11. 3) Clients
  12. 4) Servers
  13. 5) Test
  14. 6) View Templates
  15.  
  16. Enter selection
  17. "@
  18.  
  19. ###Record user selection to varirable
  20. $TargetComputerGroupTemp = Read-Host -Prompt $UserPrompt
  21.  
  22. ###Convert their choice to the correct 0-index array value.
  23. $TargetComputerIndex = $TargetComputerGroupTemp -1
  24.  
  25. $ComputerTarget = $TargetComputerGroups[$TargetComputerIndex]

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

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

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

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

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

  1. [void][reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration")
  2.  
  3. $wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer(“wsus_server”,$False)
  4.  
  5. $wsus

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

  1. $wsus.GetComputerTargetGroups()

或者选择一个组

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

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

猜你在找的Windows相关文章