Tag Archives | SCCM

Just discovered TSConfig.INI

I can now customize my winpe to run a VNC Server from a batch using TSConfig.INI and [CustomHook]. In theory, I can use “Create task sequence media” to create a thumb drive, that will reboot into winpe, and I can connect via WinVNC to continue the lite touch task sequence.

I really need to sit down and read the documentation. What else am I missing?

Waking up a SCCM collection from vbscript.

I wanted to wake up all the machines in a collection using a vbscript. I know that SCCM has this built in, but I could not get it working. To troubleshoot I figured I would write a script to get collection members, and then wake them via the command line with this tool: http://www.gammadyne.com/cmdline.htm#wol

GetCollectionMembers "XXX00018"

Sub GetCollectionMembers (COLLECTION_NAME)
  Set objLocation = CreateObject("WbemScripting.SWbemLocator")
  Set objService = objLocation.ConnectServer("SERVERNAME", "root\SMS\site_XXX")
  strQuery = "SELECT * FROM SMS_FullCollectionMembership WHERE CollectionID = '" & COLLECTION_NAME & "'"
  Set objSourceCollectionMembers = objService.ExecQuery(strQuery)
  For Each Resource In objSourceCollectionMembers
	WakeMachine objService,Resource.ResourceID
  Next
End Sub

Sub WakeMachine (objService,ResourceID)
  Set Machines = objService.ExecQuery("Select * From SMS_R_System where ResourceID =" & ResourceID)
  For Each Machine In Machines
	Set objShell = CreateObject("Wscript.Shell")
	strCurrentDir = Replace(WScript.ScriptFullName,WScript.ScriptName,"")
	strCommand = strCurrentDir & "\wol.exe " & Replace(Machine.MACAddresses(0),":","")
	Set objExecObject = objShell.Exec(strCommand)
  Next
End Sub

SCCM “trickle” install.

We wanted to deploy software to our environment via and assigned advertisement in SCCM, but we wanted to be able to install packages to a subset of a collection. If there is an issue the next day, the whole enterprise would not down. We already had a collection that identified machines that need the package, we just want to deploy to the first 15 one day, and another 15 the next day.

Since WQL does not allow a SQL “TOP” I did not think I would be able to do it via a complex query. So I wrote the following vbscript to find machines in one Collection and add them to another collection:

Sub CopyMachinesToCollection (SOURCE_COLLECTION,TARGET_COLLECTION,ResourcesAtATime)
	Set objLocation = CreateObject("WbemScripting.SWbemLocator")
	Set oService = objLocation.ConnectServer("server", "root\SMS\site_XXX")

	Set oSourceCollectionMembers = oService.ExecQuery("SELECT ResourceID, Name FROM SMS_FullCollectionMembership WHERE CollectionID = '" & SOURCE_COLLECTION & "'")
	Set oTargetCollection = oService.Get("SMS_Collection.CollectionID='" & TARGET_COLLECTION & "'")

	' Add ResourcesAtATime resources to
	counter=0
	For Each Resource In oSourceCollectionMembers
		if counter < ResourcesAtATime then
			'Wscript.Echo Resource.ResourceID  & "-" & Resource.Name
			Set DirectRule = oService.Get("SMS_CollectionRuleDirect").SpawnInstance_()
			DirectRule.ResourceClassName = "SMS_R_System"
			DirectRule.ResourceID = Resource.ResourceID
			DirectRule.RuleName = Resource.Name
			oTargetCollection.AddMembershipRule DirectRule, SMSContext
			oTargetCollection.RequestRefresh False
			end if
			counter=counter+1
	Next
End Sub

Sub DeleteTargetCollection (TARGET_COLLECTION)
	Set objLocation = CreateObject("WbemScripting.SWbemLocator")
	Set oService = objLocation.ConnectServer("svnyem01", "root\SMS\site_SVC")

	Set oTargetCollection = oService.Get("SMS_Collection.CollectionID='" & TARGET_COLLECTION & "'")

	' Delete all in oTargetCollection
	If Not IsNull(oTargetCollection.CollectionRules) Then
		For Each Rule In oTargetCollection.CollectionRules
			wscript.echo Rule.RuleName
			oTargetCollection.DeleteMembershipRule Rule
		Next
		oTargetCollection.RequestRefresh False
	End If
End Sub

Second sub removes all machines from the collection, and the first copies the first “x” from the soure to the destination

Using a sub-select to find machines that do not have the most recent version of a package.

Many people have blogged about this – how to find machines that don’t have the most recent version of a package installed.

First we write a query to show machines that don’t have the software installed (in this case firefox)
 select SMS_R_System.Name,SMS_R_System.LastLogonUserName
	from SMS_R_System
		inner join SMS_G_System_SYSTEM on SMS_G_System_SYSTEM.ResourceID = SMS_R_System.ResourceId
	where SMS_R_System.Client = 1
		and SMS_G_System_SYSTEM.SystemRole = "Workstation"
		and SMS_G_System_SYSTEM.Name not in (
			select SMS_R_System.Name
			from  SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId
			where SMS_R_System.Client = 1
			and SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName like "Mozilla Firefox%")
Next we write a query to show the machines that have the most recent software installed (this is used in the following query):
select SMS_R_System.Name, SMS_R_System.LastLogonUserName, SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName,
			SMS_G_System_ADD_REMOVE_PROGRAMS.Version
	from  SMS_R_System
		inner join SMS_G_System_ADD_REMOVE_PROGRAMS on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId
	where SMS_R_System.Client = 1
		and SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName like "Mozilla Firefox%"
		and SMS_G_System_ADD_REMOVE_PROGRAMS.Version = "3.6.3 (en-US)"
	order by SMS_R_System.Name

Finally we write a query to show machines that aren’t in the query above

	select SMS_R_System.Name, SMS_R_System.LastLogonUserName, SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName, SMS_G_System_ADD_REMOVE_PROGRAMS.Version
	from  SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId
	where SMS_R_System.Client = 1
		and SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName like "Mozilla Firefox%"
		and SMS_R_System.Name not in (
			select SMS_R_System.Name
			from  SMS_R_System inner join SMS_G_System_ADD_REMOVE_PROGRAMS on SMS_G_System_ADD_REMOVE_PROGRAMS.ResourceID = SMS_R_System.ResourceId
			where SMS_R_System.Client = 1
			and SMS_G_System_ADD_REMOVE_PROGRAMS.DisplayName like "Mozilla Firefox%"
			and SMS_G_System_ADD_REMOVE_PROGRAMS.Version = "3.6.3 (en-US)")
order by SMS_R_System.Name

Import the First and Third queries into a collection and we have a collection that shows machines that need the updated package (including machines that don’t have any version of the package installed.)

Install Windows 7 RSAT Silently and Activate All Features

  • wusa /quiet /norestart amd64fre_GRMRSATX_MSU.msu
  • ocsetup RemoteServerAdministrationTools;RemoteServerAdministrationTools-ServerManager;RemoteServerAdministrationTools-Roles;RemoteServerAdministrationTools-Roles-CertificateServices;RemoteServerAdministrationTools-Roles-CertificateServices-CA;RemoteServerAdministrationTools-Roles-CertificateServices-OnlineResponder;RemoteServerAdministrationTools-Roles-AD;RemoteServerAdministrationTools-Roles-AD-DS;RemoteServerAdministrationTools-Roles-AD-DS-SnapIns;RemoteServerAdministrationTools-Roles-AD-DS-AdministrativeCenter;RemoteServerAdministrationTools-Roles-AD-DS-NIS;RemoteServerAdministrationTools-Roles-AD-LDS;RemoteServerAdministrationTools-Roles-AD-Powershell;RemoteServerAdministrationTools-Roles-DHCP;RemoteServerAdministrationTools-Roles-DNS;RemoteServerAdministrationTools-Roles-FileServices;RemoteServerAdministrationTools-Roles-FileServices-Dfs;RemoteServerAdministrationTools-Roles-FileServices-Fsrm;RemoteServerAdministrationTools-Roles-FileServices-StorageMgmt;RemoteServerAdministrationTools-Roles-HyperV;RemoteServerAdministrationTools-Roles-RDS;RemoteServerAdministrationTools-Features;RemoteServerAdministrationTools-Features-BitLocker;RemoteServerAdministrationTools-Features-Clustering;RemoteServerAdministrationTools-Features-GP;RemoteServerAdministrationTools-Features-LoadBalancing;RemoteServerAdministrationTools-Features-SmtpServer;RemoteServerAdministrationTools-Features-StorageExplorer;RemoteServerAdministrationTools-Features-StorageManager;RemoteServerAdministrationTools-Features-Wsrm

Uninstall old Java Version via vbscript

Here is my current script from removing previous versions of java via VBScript

'  FILENAME: UninstallAllOldJava.vbs
'  AUTHOR: jbmurphy
'  SYNOPSIS: This script looks for older versions of Java and removes them
'  DESCRIPTION: Searches add remove programs for J2SE or Java and removes if not current version
'  NOTES: - Must edit strCurrentVersion to match the version you want to keep
'	- if called with a computer name will, run against remote machine
'	- logs to local path defined in strLogPath
'	- assumes admin priv
'  LINKS:
'  EXAMPLE: UninstallAllOldJava.vbs
'  EXAMPLE: UninstallAllOldJava.vbs \\workststion
'  INPUTS: \\workststion (optional)
'  RETURNVALUE: logs to value in strLogPath
'  ChangeLog:
'  	2009-10-27: jbmurphy-changes made

'On Error Resume Next
Option Explicit
DIM objFSO, strComputer, strCurrentVersion, objWMIService, colInstalledVersions
DIM objVersion, strLogPath, strLogName, strExecQuery

IF WScript.Arguments.Count > 0 then
    strComputer = replace(WScript.Arguments(0),"\\","")
ELSE
    strComputer = "."
END If

strLogPath = "%TEMP%"
strLogName = "Java_Uninstall.log"

strCurrentVersion = "Java(TM) 6 Update 15"
strExecQuery = "Select * from Win32_Product Where Name LIKE '%Java 2 Runtime Environment%' OR Name LIKE '%J2SE Runtime Environment%' OR Name LIKE '%Java(TM)%'"
KillProc

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledVersions = objWMIService.ExecQuery (strExecQuery)

LogIt String(120, "_")
LogIt String(120, "¯")
For Each objVersion in colInstalledVersions
    If objVersion.Name = strCurrentVersion then
       LogIt Now() & ": " &replace(strComputer,".","localhost") & ": Current version is installed: " & objVersion.Name & ":" & objVersion.IdentifyingNumber
    else
       LogIt Now() & ": " &replace(strComputer,".","localhost") & ": Uninstalling: " & objVersion.Name  & ":" & objVersion.IdentifyingNumber
       objVersion.Uninstall()
    end if
Next
LogIt String(120, "_")
LogIt String(120, "¯")
LogIt String(120, " ")

Sub LogIt (strLineToWrite)
    'wscript.echo strLineToWrite
    DIM ts
    If Not objFSO.FolderExists(strLogPath) Then MakeDir(strLogPath)
    Set ts = objFSO.OpenTextFile(strLogPath & strLogName, 8, True)
    ts.WriteLine strLineToWrite
    ts.close
End Sub

Function MakeDir (strPath)
	Dim strParentPath
	On Error Resume Next
	strParentPath = objFSO.GetParentFolderName(strPath)

  If Not objFSO.FolderExists(strParentPath) Then MakeDir strParentPath
	If Not objFSO.FolderExists(strPath) Then objFSO.CreateFolder strPath
	On Error Goto 0
  MakeDir = objFSO.FolderExists(strPath)
End Function

Sub KillProc()
   '# kills jusched.exe and jqs.exe if they are running.  These processes will cause the installer to fail.
   Dim wshShell
   Set wshShell = CreateObject("WScript.Shell")
   wshShell.Run "Taskkill /F /IM jusched.exe /T", 0, True
   wshShell.Run "Taskkill /F /IM jqs.exe /T", 0, True
End Sub