SCCM Custom Attributes to use during OS install

Posted on 2016-08-15
Last Modified: 2016-09-13
In order to understand what I am trying to do, I suggest that you check out this link.

Basically, I am looking to have SCCM, during OSD deployment, copy a spreadsheet file that is located on our network to another location on our network but rename with a variable that the user will type before the OSD task starts.

So for those of you that PXE boot to drop an OS on the machine, you may have seen a variable for OSDComputername. This variable will allow us to put in the host name of the machine and after the OS is installed, it will update the host name on the machine so you don't have to do it later. I have been able to successfully do this with the AD Location and Description via the above link as well as have it drop the machine in a specific OU based on certain wording that I used to do this.

Now I need to add another variable that does the following. The user will enter in a series of numbers under a attribute I created called TICKETNUMBER. so lets say the ticket number is 123456. I enter this into the field I created right below OSDComputername. It starts the process of copying the OS to the machine, installs the drivers and all the typical things that OSD deployment does. Then it changes the host name (via OSDComputername) and when it gets to my created TS..which is just a VB script that says to copy the file that is in one network location and save it to another using the numbers I put in earlier. So it would change the name to 123456.xlsx and put it in a folder I specified (not on the local machine).

What I need to figure out is how to pull that data and have the VBS do this.. I also need to figure out how to add it in SCCM correctly.

I thought this would be simple. I added the attribute so that I can enter in these numbers prior to OSD deployment but I don't know how to get it to all come together... Anyone have any ideas on how to make this work? I am willing to give more info as needed.
Question by:prologic08
  • 5
  • 5
LVL 17

Expert Comment

by:Mike T
ID: 41758522

It is fairly straight-forward but I need to ask a few questions as well.
First, are you familiar with MDT and the many variables it adds to OSD?
Have you installed and integrated MDT?

TS Variables

There are 3 types of variables you can use with ConfigMgr: in-built read-only, in-built dynamic and custom. If you are familiar with MDT there's a good description of them in the Help file.

e.g. OSDComputername is a dynamic variable. You can change the value but not the name.

You can create custom variables at two levels: collection or machine.
You can set the variables in 3 places: customsettings.ini, the TS or a script called from the TS.

For simplicity I would install and integrate MDT 2013 Update 2. The reason is that it gives you a key variable %deployroot%. This is read-only and points to the scripts folder of MDT, but the great thing is you can add a *new* folder below and then the pathing becomes easy:

Set the custom variable TICKETNUMBER on your OSD collection. If you're using unknown computers that's a good place to set it.
You also have two options: you can NOT set the value and when you PXE boot it will prompt, albeit with an ugly GUI. If you set it, you won't be prompted. You can however change it later any way you like: script, HTA script, TS.

Finally, you copy script will need to read the value of TICKETNUMBER. To do that, you just need to bind to the ConfigMgr environment. This is only active during OSD so a bit tricky to test. People typically use this to create build tattoos in the registry so that's an example of code you can use. The key line is:

Set objEnv = CreateObject(“Microsoft.SMS.TSEnvironment”)

Open in new window

After that you can read and write TS variables at will.

See Peter's script for a tattoo example, but your ticket copy will very similar.

Finally, you can also use TS logic that branches depending on the TICKETNUMBER value without passing arguments to the script! Create a TS step Group, then click options and click Add "If any". Then click Add again and choose variable. Now type TICKETNUMBER as the name and a value.
Add a step inside the group to copy the file (without needing any argument to be passed). Rinse and repeat.

Group:   Sales    TICKETNUMBER = SALES
           copy 123.xls  to Sales
Group:    Marketing   TICKETNUMBER = Marketing
           copy 123.xls to Marketing


Author Comment

ID: 41762467
Unfortunately, we do not yet use MDT here. On the other hand, I tried to understand your response as best as I can. I have had some bit of success with everything except for the main objective.

So I have modified my script to copy a file from one network location to another network location but changing the name of the file to a name that I can put in prior to OS deployment. I added the collection variable: TICKETNUMBER and set it to All Unknown Computers. This is the variable that I want it to change the name to. So if I put 123456 as the value, when the TS runs, it will copy file WHATEVER.XLS to another folder and rename it 123456.XLS. I have all of the logic that I believe I need.

dim filesys, objEnv
set filesys=CreateObject("Scripting.FileSystemObject")
set objEnv=CreateObject("Microsoft.SMS.TSEnvironment") 
strTicketNumber = objEnv("TICKETNUMBER")
If filesys.FileExists("\\contoso\share\WHATEVER.xlsm") Then
filesys.CopyFile "\\contoso\share\WHATEVER.xlsm", "\\contoso\share\new folder\" & strTicketNumber & ".xlsm"
End If

Open in new window

I created a package for the VBS and added it as the last step of the OS deployment. Everything works as it should except for the obvious step that I wanted. It will copy the file over but it does not pass the value over so instead of getting "123456.XLS", I just get ".XLS" (no name).

I wasn't sure if I needed to create a device collection but I am pretty sure I don't. I also have a feeling that I am not using the right code to pass the value. Does this make sense?
LVL 17

Expert Comment

by:Mike T
ID: 41762759

It does make sense, yes.

MDT just helps (a lot) but to do what you want you don't need it.
What I describing is detailed here, albeit for choosing a machine name:


The logic is the same. I think you've done that, but the link is good to check against.

If you're getting .XLS then the variable's value is null. If you don't give a value up front, and it does NOT prompt then it will indeed be null. If you see the ugly two line GUI popup, then that's correct.

To check the variable during the TS you can add a step using "Run command line"
and then pipe it out to a file.

e.g. to write the computer name to C:\File.txt.
Cmd /C %_SMSTSMachineName% > C:\File.txt

Open in new window

Your script looks fine, so it's just a matter of sorting why the TICKETNUMBER is not set.
Note, you could try moving the task up a bit so it's not the very last time, just to check that has no effect.
Variables are set after any "Gather" step, so don't put your test step before them, put it after.

If the file.txt doesn't help then we need to look at your smsts.log (or post it anyway). You can also add a step to explicitly set the variable with "Set TS variable" for testing.

What logic do you want though, and by that I mean how many different spreadsheet names do you need?

PS: Another good example of using variables is by Benoit Lecours, here:
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.


Author Comment

ID: 41765423
So I tried to get the CMD line to give me the variable but it failed. I will continue to try.

Here is how I created the Device Collection

Limiting Collection: All Unknown Computers

Membership Rules
No rule was added

No deployments were set

Distribution Points
No DPs were added

Collection Variables
TICKETNUMBER - Empty value
Do not display

This is how I created the package

This package contains source files - Chose folder that the VBS is located (\\contoso\share\scripts\)
Network path (UNC name)

Program Type

Command line
Run: Normal
Whether or not a user is logged on
Runs with administrative rights
Drive mode: Runs with UNC name

Added to required DPs

This is how I added to the TS

Add - Run Command Line
Command line - cscript.exe Build_Ticket.vbs
Package - Added the package I created earlier
Run step as account - Using an account that has full rights

I put this step after the Join Domain part. After the Join Domain, I have scripts that add to the AD Decryption and Location. Those both work. This is also where the TS completes.
LVL 17

Expert Comment

by:Mike T
ID: 41765573
Can you post the smsts.log please. It's normally in c:\windows\ccm\logs or ccm\smsts\logs if crashed.

Author Comment

ID: 41767013
Sure, here you go. I noticed that it is in fact picking up the value.

Author Comment

ID: 41767017
LVL 17

Accepted Solution

Mike T earned 500 total points (awarded by participants)
ID: 41768532

You've done everything right, and the step is running with return code 0 (and getting the value as you said) but the problem you are hitting is permissions. Specifically, the log errors with:

failed to get the linked token information. It may not be available. Error 1312

which means ERROR_NO_SUCH_LOGON_SESSION or  “A specified logon session does not exist. It may already have been terminated.” which points to a conflict between the context the step is running and the account.

In general, as the TS runs in system context you *cannot* access network shares etc. which is why they provide the "Run as" option. If the OS is W7x64, disable 64-bit redirection (check box).

I don't have a fix, as such but the options I would try are:
switch the script to PowerShell
use a different account (to test)
change the permissions on the share where the XLS lives to include SYSTEM

not necessarily in that order! Testing is tricky because if you run is as admin, I'm guessing it works perfectly. To test running as system people tend to use psexec (from sysinternals).

Author Comment

ID: 41770473
So I tried a different account as well as changing the copy location and destination just to see if there is an issue there. The file coies over from the ccmcache to the root of C: but still doesn't pass the value. I am stuck at this point. Not sure what to do. I am still trying to figure out how to create this in PS.
LVL 17

Expert Comment

by:Mike T
ID: 41795664
There were no other answers.

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome, welcome!  If you are new to the series and haven't been following along, please take a brief moment to review the first three installments: Part 1 (…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question