March 27 2012

Running multiple commands in SCCM ‘Run Command Line’ Task Sequence step

I use a maximum of one Google Ad per post to help offset some of my blog hosting costs.


A quick post on something that’s not overly technical. I was editing a SCCM task sequence and I wanted to run multiple commands on the task sequence ‘Run Command Line’ step without using a batch file.  I remember that Command Processor allows the & character to join commands together. I tested this out in the task sequence step and it work successfully. In this example it was “cmd /c del c:windowssystem32hal.dll /Q & cmd /c del c:windowssystem32ntoskrnl.exe /Q & cmd /c del c:windowssystem32ntkrnlpa.exe /Q ”



I use a maximum of one Google Ad per post to help offset some of my blog hosting costs.


February 28 2012

Powershell MAC address format validation for SCCM computer association

Recently I was writing a Powershell form frontend for SCCM Opearting System Deployment so technicians didn’t need to go into the MMC console to perform refresh, upgrade or new computer SCCM OSD scenarios.  In the new computer scenario, we need to do a computer association between the computer name and MAC address – which needs to be in the 00:00:00:AA:AA:AA format.

Therefore my Powershell form needs to do MAC address format validation. I took a look at this script and made a fair few modifications for my scenario. I’ve shown the relevant sections of my script below – it checks for valid MAC address hex characters and then converts 00-00-00-AA-AA-AA or 000000AAAAAA or 0000.00AA.AAAA formats to 00:00:00:AA:AA:AA format. As I said, this is part of a bigger Powershell form and I use a textbox to display messages, so you will see references to it like $textboxResults.Text or $text which you can ignore or re-use for yourself, the validation part is most important:

$MACAddress = $txtMAC.Text.toUpper()
$inParamsAddEntry.MACAddress =$MACAddress
<# This section checks for valid MAC address hex characters and then converts 00-00-00-AA-AA-AA or 000000AAAAAA or 0000.00AA.AAAA to 00:00:00:AA:AA:AA format #>
$patterns = @(
if ($MACAddress -match ($patterns -join '|')) {$true} else
$text = "$(get-date -format "dd/MM/yy HH:mm:ss") ERROR: Invalid MAC address specified: '$MACAddress'"
$textboxResults.Text = $stringBuilder.ToString()
$Delimiter = ':'
$rawAddress = $MacAddress -replace 'W'
switch ($Delimiter)
{$_ -match ':|-'}
if ($MacAddress -match ":")
$text = "$(get-date -format "dd/MM/yy HH:mm:ss") MAC address $MacAddress already in correct format"
$textboxResults.Text = $stringBuilder.ToString()
for ($i = 2 ; $i -le 14 ; $i += 3) {
$result = $rawAddress = $rawAddress.Insert($i, $_)}
$text = "$(get-date -format "dd/MM/yy HH:mm:ss") MAC address converted from $MacAddress to $result"
$textboxResults.Text = $stringBuilder.ToString()
for ($i = 2 ; $i -le 14 ; $i += 3)
$result = $rawAddress = $rawAddress.Insert($i, $_)
$text = "$(get-date -format "dd/MM/yy HH:mm:ss") MAC address converted from $MacAddress to $result"
$textboxResults.Text = $stringBuilder.ToString()
} # End switch
# Use $result from here onward for correctly formatted MAC address
$rawAddress = $txtMAC.Text.toUpper()
$MACAddress = $txtMAC.Text.toUpper()

So when I run my Powershell form, I have a few scenarios:

Invalid MAC address entered


Correct format MAC address entered


Wrong format MAC address entered


January 24 2012

Force SCCM optional advertisement to run

I needed a script that was going to run tigger optional SCCM advertisement to run. Why? Because I was using Opalis to trigger multiple advertisements across multiple systems in a certain sequence. I had tried the SCCM Client Center Integration Pack for Opalis, however the Run Advertisements function didn’t seem to work. So my Opalis workbook simply calls the below script and passes it the SCCM package ID and program name (ie force_run.vbs PACKAGEID PROGRAMNAME). See below for VBScript:

' Purpose: Forces optional advertised programs that meet packageID and program name criteria to run
' Note: There must already be a SCCM advertisement in place
' Use: force_run.vbs PACKAGEID PROGRAMNAME (case sensitive)
' Author:

' Get input parameters
Dim Arg, packageID, programName
Set Arg = WScript.Arguments
packageID = Arg(0)
programName = Arg(1)
Set uiResource = CreateObject("UIResource.UIResourceMgr")
Set programList = uiResource.GetAvailableApplications

' Set flags for error tracking
flag_package = "notavailable"
flag_program = "notavailable"

' Match each given packageID and program name against applications available to the machine
For each p in programList
If p.PackageID = packageID then
flag_package = "available"
If p.Name = programName Then
uiResource.ExecuteProgram p.ID, p.PackageID,True
flag_program = "available"
Exit For
End If
End If

' Give feedback if the given packageID or program name do not match available applications
If flag_package = "notavailable" then
wscript.echo packageID & " does not match any Package ID in available applications"
End If
If flag_program = "notavailable" and flag_package = "available" then
wscript.echo programName & " does not match any program name in available applications or is not associated with Package ID " & packageID
End If

' Give feedback if everything matches
If flag_program = "available" and flag_package = "available" then
wscript.echo "Program name " & programName & " from package ID " & packageID & " ran successfully."
End If

' Clean up
Set uiResource = Nothing
Set Arg = Nothing


December 28 2011

Custom message prior to installing software

In the past when using SMS or SCCM and I’ve needed to notify the user that a software installation is going to take place, I would write a VBScript utilizing wshShell.Popup and WScript.Sleep. Today I came across a good piece of free software that provides a bit of a nicer interface to display these messages.

Check out ‘Coretech Auto Install Warning’:


December 10 2011

Running program in SYSTEM context

This is an old trick, one that I have been using for many years, but I’ve never documented it. Often when working with SCCM, you will need to test how something will operate when running in the SYSTEM context (as opposed USER context) – scripts, exes, msis, lots of things. I’ve used the trick with PSEXEC, where you just run ‘psexec.exe -i -s cmd.exe’ and you are presented with a command prompt running in the SYSTEM context – from here you can run your test commands. There is a good writeup about it over here – if you need any further information.

December 7 2011

Set custom SCCM task sequence variable to client DHCP server

I had a requirement to be able set a custom SCCM Task Sequence variable to the value (IP address) of the DHCP server that had issued the IP address to the client . This meant that later in the Task Sequence I could re-use this value for other things, in this case it was to map a network drive, eg \%DHCP_Server%temp. I used a VB script to set this:

' Purpose: Set SCCM task sequence variable 'DHCP_Server' to the value of the DHCP server IP address
' Date: 06/12/2011
' Version: 1.0

strComputer = "."

' Create Task Sequence environment object
dim osd: set env = CreateObject("Microsoft.SMS.TSEnvironment")

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\" & strComputer & "rootcimv2")

' Find active network adapter
Set colAdapters = objWMIService.ExecQuery _
("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
n = 1

For Each objAdapter in colAdapters

' Set variable in the Operating System Deployment environment
env("DHCP_Server") = objAdapter.DHCPServer

n = n + 1

When you dump out the Task Sequence variables, you can then see it at the top of the list: