How to move clients in WSUS from “Unassigned Computers” group to “Clients” group

I had one need: move all the computers that contact WSUS server from the default group “Unassigned Computers” to a group called “Clients” (I don’t want to use Group Policy assignment).
Here a script that look into “Unassigned Computers” group and if there are some computers with name that do not start with “SV-” (for me it’s a server), they are moved into a group called “Clients”

' Created da quel bel figone di Luca Bazzuka

Imports Microsoft.UpdateServices.Administration 

Module AddComputerTarget 

     Sub Main() 
         Dim server As IUpdateServer 
         Dim subscription As ISubscription 
	 Dim instance As IComputerTargetGroup
	 Dim target As IComputerTarget
	 Dim groups As ComputerTargetGroupCollection
	 Dim group As IComputerTargetGroup
	 Dim allcomputergroup As Guid
	 Dim unassignedcomputer As Guid
	 Dim rootgroup As IComputerTargetGroup
	 Dim unassignedcomputergroup As IComputerTargetGroup
	 Dim listatarget As ComputerTargetCollection
	 Dim _statogruppo As Boolean

         'connect to the local server 
         server = AdminProxy.GetUpdateServer 
         subscription = server.GetSubscription() 


	 unassignedcomputer = ComputerTargetGroupId.unassignedcomputers
	 unassignedcomputergroup = server.GetComputerTargetGroup(unassignedcomputer)	 


	 allcomputergroup = ComputerTargetGroupId.AllComputers
	 rootgroup = server.GetComputerTargetGroup(allcomputergroup)

	 _statogruppo = "False"
	 instance = unassignedcomputergroup
	 groups = rootgroup.GetChildTargetGroups
	 For Each group in groups
		If group.Name = "Clients" Then
			instance = server.GetComputerTargetGroup(group.Id)
			Console.WriteLine("Gruppo 'Clients' esiste...")
			_statogruppo = "True"
		End If
	 Next

	 If _statogruppo = "False" Then
		Console.WriteLine("Gruppo 'Clients' non esiste...BOTTANAZZA!!!")
		Exit Sub
	 End If
	 
	 listatarget = 	unassignedcomputergroup.GetComputerTargets
	 For Each target in listatarget
		If Left(target.FullDomainName, 3) = "sv-" and Left(target.OSDescription, 19) = "Windows Server 2003" Then
			' Non fare un ciuffolo
		Else
		 	instance.AddComputerTarget(target)
			Console.WriteLine("Spostato PC : " & target.FullDomainName)
		End If
	 Next
     End Sub 


End Module 

Now I compile the script with the command above :

%WINDIR%\Microsoft.NET\Framework\v2.0.50727\vbc.exe MoveToClientsGroup.vbs /r:"%PROGRAMFILES%\Update Services\service\bin\Microsoft.UpdateServices.Administration.dll" /out:MoveToClientsGroup.exe

 …and schedule to run this .exe every 30 minutes on WSUS server

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s