SCCM Client VBS Deployment Script

Here’s a SCCM Client deployment script. You’ll need to change path references to your own, but it should work for x86 and x64 clients, and it should update clients older than R3. This was written by Robert Holbert, one of our junior admins, and myself. It’s got a lot of debug code in it still, and it’s pretty messy. Sorry.

'Install-SCCMClient.vbs
on error resume next
'Elevate for UAC
'references: http://www.winhelponline.com/articles/185/1/VBScripts-and-UAC-elevation.html
'If WScript.Arguments.length = 0 Then
'	Set objShell = CreateObject("Shell.Application")
'	objShell.ShellExecute "wscript.exe", Chr(34) & WScript.ScriptFullName & Chr(34) & " uac", "", "runas", 1
'Else
	'User variables
	Dim currentVer
	currentVer = "4.0.6487.2157"
	
	'Init common variables
	Dim wshShell
	Dim objFileSystem
	Set wshShell = wscript.CreateObject("wscript.Shell")
	Set objFileSystem = CreateObject("scripting.FileSystemObject")
	
	'Main Flow
	If CheckSCCM = False Then
		InstallSCCMAgent
	ElseIf CheckSCCMVersion < currentVer Then
		UpdateSCCMAgent
	'msgbox "Needs Updated"
	'Else
	'msgbox "Current Version"
	End If
'End If

'Functions
Function InstallSCCMAgent
	Dim strRunString
	strRunString = "\\dc1\NETLOGON\deployment\sccmclient\4.00.6487.2157\Client\ccmsetup.exe SMSSITECODE=CHE PATCH=\\dc1\NETLOGON\deployment\sccmclient\4.00.6487.2157\Client\sccm2007ac-sp2-kb977384-x86-enu.msp"
	'msgbox strRunString
	'wshShell.Exec(strExecString)
	wshShell.Run strRunString, 1, true
End Function

Function UpdateSCCMAgent
	Dim strRunString
	strRunString = "msiexec /p \\dc1\NETLOGON\deployment\sccmclient\4.00.6487.2157\Client\sccm2007ac-sp2-kb977384-x86-enu.msp /qn"
	'msgbox strRunString
	'wshShell.Exec(strExecString)
	wshShell.Run strRunString, 1, true
End Function

Function CheckSCCM
	Dim agentInstalled
	agentInstalled = True
	'msgbox "checking to see if agent is installed."
	If Not objFileSystem.FileExists("C:\Windows\System32\CCM\CcmExec.exe") Then
		'msgbox "did not find C:\Windows\System32\CCM"
		If Not objFileSystem.FileExists("C:\Windows\Syswow64\CCM\CcmExec.exe") Then
			agentInstalled = False
			'msgbox "did not find C:\Windows\Syswow64\CCM"
		End If
	End If
	If agentInstalled = True Then msgbox "found SCCM Client"
	CheckSCCM = agentInstalled
End Function

Function CheckSCCMVersion
	Dim strComputer, objWMIService, objItem, colItems
	strComputer = "."
	
	'WMI Connection
	Set objWMIService = GetObject("winmgmts:\\.\root\ccm")
	Set colItems = objWMIService.ExecQuery("Select * from CCM_InstalledComponent")

	maxVer = "0"

	For Each objItem in colItems
	thisVer = objItem.version
	If thisVer > maxVer Then
		maxVer = thisVer
	End If

	Next
		CheckSCCMVersion = maxVer
End Function
Advertisements

One thought on “SCCM Client VBS Deployment Script

  1. Pingback: Table of Contents | windowsmasher

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