Tuesday 1 October 2013

PreCaching Task Sequence on Client Machine - Part 2

Hi,

If you have read through http://poorlycoded.blogspot.com.au/2013/03/precaching-task-sequence-on-client.html and decided you want to know more, well let me try and assist :)

The below script will read from a list of packages and override the content variables for those packages:
sPackageIDs = "ABC12345,ABC98765,ABC00000,ABC111111"
Set objEnv = CreateObject("Microsoft.SMS.TSEnvironment")
Set objFSO=CreateObject("Scripting.FileSystemObject")
Set objShell=CreateObject("Wscript.Shell")
Set objDrives=objFSO.Drives

cacheFolder = "\PathToCache"

path = objFSO.GetParentFolderName(WScript.ScriptFullName)


For Each objDrive In objDrives
 If objDrive.DriveType=2 And objDrive.DriveLetter<>"X" Then
  If objFSO.FolderExists(objDrive.DriveLetter & ":\Windows") Then 
   Drive=objDrive.DriveLetter & ":"
  End If 
 End If
Next 

strCache = Drive & cacheFolder
tsEnv2Path = objFSO.Buildpath(path,"tsenv2.exe")


pkgSplit = Split(sPackageIDS,",")

for each pkg in pkgSplit
strPKGVar = "_SMSTS" & pkg
    For Each variable In objEnv.GetVariables 
        if variable = strPKGVar then
            if objFSO.FolderExists(objFSO.BuildPath(strCache,pkg)) then
                objShell.Run(tsEnv2Path & " set " & variable & "=s" & strCache & "\" & pkg & "\",1,true)
        end if
    next

Next 

You can then put this into your task sequence and have those packages overriden by the local, cached         package.Obviously be careful you don't have a format step, otherwise this will all be in vain, and if you cache folder is in a non standard location, perhaps ensure its added to the Safe Folder variable by adding this line, or setting the OSDStateStore variable in your TS.

objEnv("OSDStateStorePath")=strCache


Hope this helps! PS i've knocked together the above script without testing in my lab - so obviously test this   first :)

No comments:

Post a Comment