Right Click Tools - Client Actions
Main Menu
>
Tools
>
Right Click Tools
Client Actions
Right click on a computer or a collection and force the computer(s) to Clear Cache, Run Polcy, or Inventory.
Download
Code
------------Clientactions.vbs-------------------------- 'Created By Matthew Hudson on error resume next Set objArgs = WScript.Arguments if (objArgs.count > 1) then MyPos = InStr(objArgs(0), ":") ToolType= wscript.arguments.item(0) 'C-collection I-individual SMSID= wscript.arguments.item(1) SMSAction= wscript.arguments.item(2) 'Clearcache, Inventory, Policy end if Const SW_NORMAL = 1 Set Shell = CreateObject("Wscript.Shell") Set oFSO = CreateObject("Scripting.FileSystemObject") Set SWbemLocator=CreateObject("WbemScripting.SWbemLocator") set SWbemServices = SWbemLocator.ConnectServer("SMs-server.foo.com","root\SMS\site_XXX") ''''''''' Collection based Tools ''''''''''''''''''''''''' 'if we are looking at multiple computers: if ToolType="C" then strQuery = "select * from SMS_CM_RES_COLL_" & SMSCollectionID Set Computers= SWbemServices.ExecQuery(strQuery) for each Computer in Computers theAction Computer.Name,SMSAction Next end if ''''''''' Individual Tools ''''''''''''''''''''''''' 'if a single computer was selected and clear cache was selected if ToolType="I" then strQuery = "select Name from SMS_R_SYSTEM where ResourceID='"+ SMSID +"'" set CompNAmes= SWbemServices.ExecQuery(strQuery) for each strComputer in CompNAmes theAction strComputer.Name,SMSAction next End if ' ********************* Actions ********************* sub theAction(strComputer,SMSAction) strCommand = "cscript c:\" & SMSAction & ".vbs" Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" _ & strComputer & "\root\cimv2") '50 Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFileCopy = objFSO.GetFile("C:\Program Files\MCNS\ClientActions\" & SMSAction & ".vbs") objFileCopy.Copy ("\\" & strcomputer & "\c$\" & SMSAction & ".vbs") Set objStartup = objWMIService.Get("Win32_ProcessStartup") Set objConfig = objStartup.SpawnInstance_ objConfig.ShowWindow = SW_NORMAL Set objProcess = objWMIService.Get("Win32_Process") intReturn = objProcess.Create (strCommand, Null, objConfig, intProcessID) 'If intReturn <> 0 Then ' Wscript.Echo "Process could not be created." & _ ' vbNewLine & "Command line: " & strCommand & _ ' vbNewLine & "Return value: " & intReturn 'Else ' Wscript.Echo "Process created." & _ ' vbNewLine & "Command line: " & strCommand & _ ' vbNewLine & "Process ID: " & intProcessID 'End If wscript.sleep (2000) 'wscript.echo strcommand objFSO.DeleteFile ("\\" & strcomputer & "\c$\" & SMSAction & ".vbs") End sub ' ********************************************************* -------------Inventory.vbs------------------------- On Error Resume Next Dim oCPAppletMgr Set oCPAppletMgr = CreateObject("CPApplet.CPAppletMgr") Dim oClientActions Set oClientActions = oCPAppletMgr.GetClientActions() Dim oClientAction For Each oClientAction In oClientActions If oClientAction.Name = "Software Inventory Collection Cycle" Then oClientAction.PerformAction End If If oClientAction.Name = "Hardware Inventory Collection Cycle" Then oClientAction.PerformAction End If Next -----------Clearcache.vbs--------------------------- on error resume next dim oUIResManager dim oCache dim oCacheElement dim oCacheElements set oUIResManager = createobject("UIResource.UIResourceMgr") if oUIResManager is nothing then wscript.echo "OK" wscript.quit end if set oCache=oUIResManager.GetCacheInfo() if oCache is nothing then set oUIResManager=nothing wscript.quit end if set oCacheElements=oCache.GetCacheElements for each oCacheElement in oCacheElements oCache.DeleteCacheElement(oCacheElement.CacheElementID) next set oCacheElements=nothing set oUIResManager=nothing set oCache=nothing wscript.quit ---------Policy.vbs----------------------------- On Error Resume Next Dim oCPAppletMgr Set oCPAppletMgr = CreateObject("CPApplet.CPAppletMgr") Dim oClientActions Set oClientActions = oCPAppletMgr.GetClientActions() Dim oClientAction For Each oClientAction In oClientActions If oClientAction.Name = "Machine Policy Retrieval and Evaluation Cycle" Then oClientAction.PerformAction End If Next ----------------------------------- ----------MCNS-col.xml----------------------------
C:\Program Files\MCNS\clientactions\clientactions.vbs
C ##SUB:CollectionID## Inventory
C:\Program Files\MCNS\clientactions\clientactions.vbs
C ##SUB:CollectionID## Policy
C:\Program Files\MCNS\clientactions\clientactions.vbs
C ##SUB:CollectionID## Clearcache
-----------MCNS.XML---------------------------
C:\Program Files\MCNS\clientactions\clientactions.vbs
I ##SUB:ResourceID## Inventory
C:\Program Files\MCNS\clientactions\clientactions.vbs
I ##SUB:ResourceID## Policy
C:\Program Files\MCNS\clientactions\clientactions.vbs
I ##SUB:ResourceID## Clearcache
--------------------------------------
Documentation
You will need to create a Action folder and an XML file. You may also edit a pre-existing XML file clientactions.vbs [I|C] [resourceID|CollectionID] [Actionfile to run] I - individual computer, must be used with Resource ID C - Collection of computers, must be used with Collection ID Action file to run - This is the vbs file that will be executed on the client machine. 'cscript clientactions.vbs I 96 Clearcache x:\Program Files\Microsoft Configuration Manager\AdminUI\XmlStorage\Extensions\Actions\7ba8bf44-2344-4035-bdb4-16630291dcf6 This will have the mcns.xml file x:\Program Files\Microsoft Configuration Manager\AdminUI\XmlStorage\Extensions\Actions\dbb315c3-1d8b-4e6a-a7b1-db8246890f59 x:\Program Files\Microsoft Configuration Manager\AdminUI\XmlStorage\Extensions\Actions\fa922e1a-6add-477f-b70e-9a164f3b11a2 This will have the MCNS-col.Xml SMS-server.foo.com - Your SMS Server name site_XXX" - Replace XXX with the server site code. This have been tested on the site server not no a remote console If you see a black box and then disappears then you need to reset your wscript settings: Set the default method for vbscript to wscript. Run the following line on a command prompt window: wscript /H:WScript --Created by: Matthew Hudson