Deployment and Imaging Group

 View Only

How to use Unmanaged Tokens in Altiris 7.x script tasks 

Jan 09, 2015 01:54 PM

Introduction

Script Tasks in Altiris 7.x have 2 types of Tokens available. The more well know token type can be found in the 7.x Symantec Management Console under Settings > Deployment > Tokens. These tokens provide data to the script at run time through database queries, an example being %COMPNAME% which adds the computer's name to the task instance being started. There is plenty of documentation on this type of token so I won't be including any further details in this article.

The second type of token is what I'm currently calling Unmanaged Tokens that look like %!Some Text!% and allow for manual input when a task is scheduled against a target. I call them unmanaged because they're not managed outside the script(s) that use them like the other type are. If anyone knows what this type of token is really called please let me know, documentation is basically non-existent.

Unmanaged Tokens

My example is a small computer rename script written in vbscript. Saving the following into a Script Task will cause the Quick Run button to be hidden requiring that the script be executed through the New Schedule button, this is because Altiris identified %!New Computer Name!% in the script.

NewPCName = "%!New Computer Name!%"
If NewPCName = "" then WScript.quit 13
If NewPCName = "%COMPNAME%" then WScript.quit 13

Set objWMIService = GetObject("Winmgmts:root\cimv2")

' Call always gets only one Win32_ComputerSystem object.
For Each objComputer in objWMIService.InstancesOf("Win32_ComputerSystem")
        Return = objComputer.rename(NewPCName,"","")
        If Return <> 0 Then
           WScript.quit Err.Number
        Else
           WScript.quit 0
        End If
Next

 

Clicking New Schedule results in a standard virtual window with one addition, there's an input box named after whatever is between the %! !% symbols as seen in the following image. Multiple tokens can be used in a single script.

Rename Computer Script.png

Note: This example script must be configured with domain credentials that allow for changing a machine's name in Active Directory. I believe technically the AD permissions are create/delete objects.

Jobs

When including these scripts in client jobs more functionality is exposed. As seen in the next image.

Rename Computer Job.png

With the task highlighted in the job you see the Task Input options on the right. By default "Prompt me for task input each time this job is run" is selected. Using one of the other options like "use a set value" allow you to re-use the same script in many jobs each with their own value based on the job's purpose. <EDIT>The option to "use output from a previous task" combined with script name - Script output only works if the previous tasks output is only the value, vbscripts that include the logo text in the output don't work so a Command Prompt script is better.</EDIT> I also haven't seen any difference between the original default option and "prompt at run time".

Conclusion

In addition to Script Tasks I've also found these tokens useful in SQL Query tasks, and they appear to be standard in many Automation Policy tasks. For those interested the input values are stored in the TaskInputParameterValue table and and can be referenced by TaskInstanceGuid and includes a Name column for the token and the Value.

Hopefully the information in this article is useful to others.

Credit: I don't remember the name of the script but I got the idea to start researching these tokens a few years ago based on a script from a DS 7.1 sample pack.

Statistics
0 Favorited
6 Views
0 Files
0 Shares
0 Downloads

Tags and Keywords

Comments

Sep 10, 2019 12:44 PM

Any luck on that script Cody? Looking this over today; I am wondering if there is a way to sue this script or another script that is similar but prompts for the computer name on the computer that is in automatiion instead of naming the computer on the console?

Aug 29, 2019 01:42 PM

Unfortunately that script only gives you a glimpse into the total process with no explainations. That script itself is copying an xml file from a package on a package server to the X: drive in WinPE, replacing a value with the computer name and then ending. Previous scripts take care of identifying the closest package server, authentication, etc. Later scripts run a scripted OS install from a command script task with the unattend xml file and copy drivers based on part number before reboot to production and continuing with further OS configuration and core application installation.

In short, it's a mess that I've since streamlined and hope to share once I get the latest updates to Prod.

Aug 29, 2019 12:42 PM

Hi Cody, whenver you get back to your computer will be fine. Currently, how we image our computers is with pxe boot > deloyment menu > choose your image job. Ghost images (deploy image task) > win10 mini setup > unattend.xml is set to auto login as Administrator > we manually run a job of standard applications from the altiris console against computer name INFORMA-%%%%%. My first task within the job is a powershell script that prompts to name the computer. Thta computer name prompt would be more beneficial at the start of the whole process instead of in the middle.

Aug 29, 2019 12:38 PM

Pretty hefty script m.taylor. I'll have to copy into a script task and work with it.

Aug 29, 2019 12:14 PM

Like one of the attached "Name Computer at" images mj? I've retired our build jobs where you can name the machine from the schedule dialog because our Technician workflow is more in line with the Initial/Managed Deployment Menu's that kick off the automation dialog attached. But to do it from Schedule you just need the setup pictured in Name Computer Setup. The script itself is just a modified version of the Token Replacement script from the old Deployment Solution Samples for v7.1 SP1 x64 sample pack. There's a lot left unexplained in this script sorry, it's an old mess.

Set objShell = CreateObject("Wscript.Shell")
Set wshSystemEnv = objShell.Environment("SYSTEM")

strComputer = "."
strPackageServer = wshSystemEnv("Company_Package_Server")
strPackagesShare = "\\" & strPackageServer & "\PackageShare$"

strProcArch = "%!Enter x86 or x64!%"

Source = strPackagesShare & "\{PackageGUID}\cache\sysprep\" & strProcArch & "\W10Ent1809K_Unattend.xml"
Destination = "X:\W10Ent1809K_Unattend.xml"
PCName = "%!Computer Name!%"

Set fso = CreateObject ("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_BaseBoard",,48)
' Get model name of system board from the Win32_BaseBoard Name via WMI
For Each objItem in colItems
	strProduct = objItem.Product
	Wscript.Echo "Model Product Value: " & strProduct
Next

strModelRootFolder = strPackagesShare & "\{PackageGUID}\cache"
If fso.FolderExists(strModelRootFolder) Then
	Wscript.Echo "Located: " & Replace(strModelRootFolder, "PackageShare$", "Share$", 1, -1, 1)
	Set objModelRoot = fso.GetFolder(strModelRootFolder)
	Set colModelFolders = objModelRoot.SubFolders
	For Each strModelFolder in colModelFolders
		Models = Split(strModelFolder, "_")
		For Each ModelNo in Models
			If ModelNo = strProduct Then
				If fso.FolderExists(strModelFolder & "\" & strProcArch) Then
					strProdNamePath = strModelFolder & "\" & strProcArch
					Wscript.Echo "Located: " & Replace(strProdNamePath, "PackageShare$", "Share$", 1, -1, 1)
'					Set objRootFolder = fso.GetFolder(strProdNamePath)
'					Set colSubfolders = objRootFolder.SubFolders
'					For Each objFolder in colSubfolders
'						fso.CopyFolder strProdNamePath & "\" & objFolder.name, strLocalINF, True
'					Next
				End If
			End If
		Next
	Next
Else
	Wscript.Echo "Failed to locate: " & Replace(strModelRootFolder, "PackageShare$", "Share$")
	Wscript.Quit 2
End If



'Provide a list of token names and values to replace
Dim tokens
Set tokens = New TokenList
If (PCName = "" or PCName = "none") then PCName = "%COMPNAME%"
tokens.AddToken "COMPNAME", PCName
tokens.AddToken "DriverSource", strProdNamePath


'Main program

'Constants that do not change
Const ForReading = 1
Const ForWriting = 2

'Declare Variables for use in token replacement.
Dim fileSource, fileDestination, objFSO, strContent

'Create a file system object
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")

'Open the source file and read it's content
Set fileSource = objFSO.OpenTextFile(Source, ForReading, False)
strContent = fileSource.ReadAll()
fileSource.Close

'str replacement 
'read thru each entry in the array and substitute in the tokenized file
For i = 0 To tokens.Size
    strContent = Replace(strContent, "%" & tokens.Name(i) & "%" , tokens.Value(i))
Next    

'Open Destination file and write updated content to it
Set fileDestination = objFSO.OpenTextFile(Destination, ForWriting, True)
fileDestination.Write(strContent)
fileDestination.Close



'TokenList Class   
Const ARRAY_INCREMENT_SIZE = 10
Class TokenList
                Public aData
                Public iCount
                Public iSize
                
                Private Sub Class_Initialize()
                                iCount = 0
                                iSize = ARRAY_INCREMENT_SIZE
                                ReDim aData(1, iSize)
                End Sub
                
                Public Function AddToken(Name, Value)
                                If iCount > iSize Then
                                                iSize = iSize + ARRAY_INCREMENT_SIZE
                                                ReDim Preserve aData(1, iSize)
                                End If
                                aData(0, iCount) = Name
                                aData(1, iCount) = Value
                                iCount = iCount + 1
                End Function
                
                Public Property Get Name(iPos)
                                If iPos < 0 OR iPos >= iCount Then Exit Property 'Invalid range
                                Name = aData(0, iPos)
                End Property
                
                Public Property Get Value(iPos)
                                If iPos < 0 OR iPos >= iCount Then Exit Property 'Invalid range
                                Value = aData(1, iPos)
                End Property
                
                Public Property Get Size()
                        Size = iCount
                
                End Property
                
                
End Class

 

Aug 29, 2019 11:37 AM

Hey mj we have a script doing just that, not near my computer right now post it for you later today

Aug 29, 2019 11:32 AM

Curious, is there a way to prompt for the computer name before applying a deploy image job/task? For example, in sccm the deploy image task sequence can have a variable added in called 'OSDComputerName' this will prompt the end-user to name the computer first, then image the computer. The name is stored somewhere and then applied to the imaged computer. Could this vbscript be modified or used in some way with altiris to perform the same approach of naming the computer, storing it somewhere while the computer is being imaged by ghost then applying the name when the time comes?

Aug 17, 2016 04:47 PM

Thanks aaron, name makes a lot of sense. I nicknamed them in comparison to the DS tokens. Over the years I've seen their pretty well used in Automation Policies and Monitoring and Alerting without much explaination either, thanks for those links.

Aug 17, 2016 04:45 PM

Sorry I don't know, the script itself was just to provide an example of the tokens. Maybe add some echo statements to the rename script and enable saving output to view your results?

Aug 17, 2016 09:37 AM

I think you'll find that these unmanaged tokens are called "Input Parameter Tokens", and yes their documentation is buried deep in the bowels of the Altiris Solution SDK docs.

See http://portals.altiris.com/portals/13/sdk/smp%207.0/SolutionDev/TokensUsedInTaskCreation.html for direct reference and sample code.

See http://portals.altiris.com/portals/13/sdk/smp%207.0/SolutionDev/InputParameters.html for more example usage and code.

It's unfortunate that there's not more detail in the actual Jobs and Tasks documentation for Altiris admins and users guides. This connect post and these two Solution SDK articles are really the only references I can find on how to use this super-helpful task function.

Aug 16, 2016 08:56 AM

i have tried running this job and it states the script completes and restarts the computer but the name is not changed.  i have verified that the account used has permissions to rename computers.  any thoughts/ideas that i might try to get this to work?

Apr 18, 2016 04:55 AM

This is brilliant. I don't know when this feature was introduced (since 7.0?) but I wish I had known about this three years ago.

Aug 05, 2015 10:20 PM

Awesome tip CB! I didn't get a notification on this post but very glad I checked back.

Jun 23, 2015 02:39 PM

PRO TIP:  Set the text of the input variable prompt!

It's no fun having a variable named %!PleasePutRequestedDataHere!% so why not have any variable name you want then use language localization to provide a robust message to the task user.

See the attachment for an example.

You will be creating a localization string in the database to allow this to function.  Use this simple stored procedure to create or update your text: 

EXECUTE [spSetString] 'F44D3809-D1D5-47BC-BD9D-EEFB45F1A7DC','Test1','','Friendly text goes here'

 

Only parameters 2 and 4 should be edited, they are the variable and the desired text. Param 1 is a type guid and parameter 3 sets a blank language.  Be sure to IISRESET after making string changes.

Sit back and enjoy your well-informed users!

Jan 15, 2015 12:59 AM

The last sentence prior to the Conclusion section should really be:

The option "prompt at run time" is for when you have more than one input item in the right hand pane, the radio buttons shown in the last screen shot are global for as many unmanaged tokens as exist.

Jan 09, 2015 04:50 PM

Minor helpful update that provides even more options, change is inside <EDIT></EDIT> tags near the end.

Jan 09, 2015 02:03 PM

This is fantastic! I had no idea this functionality existed. Time to start playing around with it...

Related Entries and Links

No Related Resource entered.