А АSunday 3 June 2018

Administration WSUS with Powershell.

Hi guys.

Recently I have to make some new groups from AD in WSUS server. I wouldn't to type all names with my keyboard. Therefore I can do some mistake and it so boring. So I though that WSUS Powershell scripts are in this world.

I found super PoshWSUS package (PoshWSUS v2.3.2, Last Updated: 12 Apr 2018) from Boe Prox for performing my task. I think there is Get-PSWSUSGroup, so Set-PSWSUSGroup function have to be there too. Ok, so I imported module to my Powershell profile. Then I got the names of 96 functions! I found there Get-PSWSUSGroup and New-PSWSUSGroup functions.

Ok, let's go.
At fisrt I make connection to my WSUS server.
>Connect-PSWSUSServer
Name                 Version              PortNumber           ServerProtocolVersion
----                 -------              ----------           ---------------------
192.168.1.28         6.3.9600.18838       8530                 1.8

Then I can get the info of my existing groups in WSUS:
>Get-PSWSUSGroup

Then I can get the info of my PARENTGROUP group:
>Get-PSWSUSGroup | ?{$_.Name -like "PARENTGROUP"} | fl

ok, and I thought that I can create the new CHILDGROUP group easy as:
>New-PSWSUSGroup -Name "CHILDGROUP" -ParentGroup "PARENTGROUP"

Ooops, I got error of type conversion for ParentGroup parameter - New-PSWSUSGroup: Can not process the argument conversion for the "ParentGroup" parameter. Can not convert the value of "pilotHosts" type "System.String" to type Microsoft.UpdateServices.Internal.BaseApi.ComputerTargetGroup ".



Manual of calling this function didn't help me. I found solution after reading TechNet blog. So if I would like to call this fucntion without any preliminary conversion I have to use Get-PSWSUSGroup for retrieve info about PARENTGROUP.

So it must be as:
>$grp = Get-PSWSUSGroup | ?{$_.Name -like "PARENTGROUP"}
>New-PSWSUSGroup -Name "CHILDGROUP" -ParentGroup $grp

Well done.

Here I have to close my session to WSUS:
>Disconnect-PSWSUSServer

After that I found some interesting articles concerning WSUS and Powershell in TechNet blog. And I wanted to check another path for the same task.  I have to use "WSUS Adminstrative Console". If I have Windows 10 Pro I can install RSAT where "WSUS Adminstrative Console" was included. I can use the Microsoft.UpdateServices.Administration assembly.

Here is the command that I use to load that assembly:
>[reflection.assembly]::LoadWithPartialName("Microsoft.UpdateServices.Administration") | Out-Null

Connect to WSUS server:
>$wsus = [Microsoft.UpdateServices.Administration.AdminProxy]::getUpdateServer('MyUPDATE', $False, 8530)
>$wsus

Add new subgroup:
>$group = $wsus.GetComputerTargetGroups() | Where {$_.Name –eq "PARENTGROUP")
>$wsus.CreateComputerTargetGroup("CHILDGROUP", $group)

Or add Client to group:
>$Client = $wsus.SearchComputerTargets("EU0")
>$group = $wsus.GetComputerTargetGroups() | Where {$_.Name –eq "TESTGROUP"}
>$group.AddComputerTarget($Client[0])

Well done again.

What's the best method for me? I don't know. I know that PoshWSUS don't require Administrative privilege for own operations. That's all.

Good luck.

No comments:

Post a Comment

А что вы думаете по этому поводу?

Версия на печать

Популярное