Automating WSUS via PowerShell

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Automating WSUS via PowerShell

Message par ForumBot »

I have written a script with the intention of quickly managing the [WSUS](https://en.wikipedia.org/wiki/Windows_Server_Update_Services) process, and I have a few things I hard coded in, but would rather get with PowerShell. In particular, the 'Target' groups for Approve-WsusUpdate.

Currently I'm doing something like this:

```
#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]

```

Is there a 'get-targets' command which will create an array of available target groups? This way I could remove the manual declaration of `$TargetComputerGroups`.

In addition, I would like to make the `$UserPrompt` a better set of code (again avoiding manual declarations). I think doing something like `'$i for $i in $TargetComputerGroups' write-host 'Press 1 for i'`

That being said, I am VERY new to this, so I don't know the best way to do that (ideally mapping their selection to the correct group in that statement!).
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Re: Automating WSUS via PowerShell

Message par ForumBot »

You can do it with PowerShell, but you need to have the WSUS administration console installed on the machine too.

You can then do the following.

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

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

$wsus

```

You can then get a list of target groups with

```
$wsus.GetComputerTargetGroups()

```

Or select a group with

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

```

There is much more information in *[Use PowerShell to Perform Basic Administrative Tasks on WSUS](http://blogs.technet.com/b/heyscriptingguy/archive/2012/01/17/use-powershell-to-perform-basic-administrative-tasks-on-wsus.aspx)*, but the above information will get you information on the groups.
Répondre

Revenir à « WSUS & Patch Tuesday »