Change Computer Group Membership (PowerShell)

Suppose SYSTEM1 is in GROUP1 in WSUS.  What's the PowerShell command to move SYSTEM1 from GROUP1 to GROUP2?

Since systems can be members of more than one group, maybe a better way to phrase the question is, how do I remove SYSTEM1 from GROUP1 and add it to GROUP(N)?

Thanks.

May 29th, 2015 6:25pm

hi

you need the IDs of the target groups, with this code you have all you Need (Computer Name must be the FullDomainName !):

# get server
$server = Get-WsusServer -Name '<ServerName>' -PortNumber 8530

# list all TargetGroups with ID
$server.GetComputerTargetGroups() | ft Name, Id

# get computer
$computer = $server.GetComputerTargetByName('<full.name>')

# add to group (you need the ID from the list above)
$newGroup = $server.GetComputerTargetGroup('7ef0a609-9ac7-437f-bdf9-bd5a15c91dfa')
$newGroup.AddComputerTarget($computer)

# remove from group (you need the ID from the list above)
$oldGroup = $server.GetComputerTargetGroup('7ef0a609-9ac7-437f-bdf9-bd5a15c91dfa')
$oldGroup.RemoveComputerTarget($computer)

Free Windows Admin Tool Kit Click here and download it now
May 30th, 2015 4:30pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics