VBScript

Script to delete any Drive:\smspkg\*.pck files of the specified file age

Posted on Updated on

There are many scripts and examples out there for cleaning up PCK files.  The below script is my rendition to cleanup PCK files that are older than the specified number of days.  This script can be executed via a package in ConfigMgr on systems that are a DP.  Oh and I added some basic logging to the script as well :-)


' Script to delete any Drive:\smspkg\*.pck files of the specified file age
sLogFile = "c:\windows\temp\dp_pck_cleanup.log"
iFileAge = 365

Set oFSO = CreateObject ("Scripting.FileSystemObject") 
Set oOutputFile = oFSO.OpenTextFile (sLogFile, 8, True) 
Set oWMI = GetObject("winmgmts:\\.") 
Set colItems = oWMI.ExecQuery("SELECT * FROM Win32_LogicalDisk") 

oOutputFile.WriteLine "******** PCK cleanup began ********  " & Date

For Each oDrive in colItems 
	sDrive=left(oDrive.caption,1) 
	'wscript.echo "sDrive: " & sDrive
	If (oFSO.FolderExists(sDrive & ":\smspkg\")) Then    
		oOutputFile.WriteLine "Smspkg exists on drive " & sDrive
		Set receive = oFSO.GetFolder(sDrive & ":\smspkg\") 
		Set colFiles = receive.Files 
		
		For Each oFile in colFiles 
			sFileName=(lcase(oFile))
			'wscript.echo sFileName
			If (right(sFileName, 4) = ".pck") then 
				'wscript.echo "This is a PCK file"
				If DateDiff("d", oFile.DateLastModified, Date) > iFileAge Then 
					oOutputFile.WriteLine oFile & " exists with modified date: " & oFile.DateLastModified & ", Size (MB):" & vbtab & int(oFile.Size/1048576) 
					oFSO.DeleteFile oFile,TRUE 
					oOutputFile.WriteLine "      Deleted successfully "
				End If 
			End If 
		Next 
	Else
		oOutputFile.WriteLine "No smspkg folder on " & sDrive
	End If 
Next 

Script to delete specific IE cookies

Posted on Updated on

An old script to share :-) It will delete IE cookies specified in variable CookieName

'==========================================================================
' NAME: DeleteIeCookiesCraigslist
' AUTHOR: Nick Moseley , https://t3chn1ck.wordpress.com
' DATE  : 8/11/2011
'
' COMMENT: Deletes the cookies specified in variable CookieName
'==========================================================================
Option Explicit

Const CookieName = "EnterCookieName"
Const ForAppending = 8
Const HKLM = &H80000002
Const EnableLogging = True

' Basic objects
Dim oReg, oShell, oFSO, iCountFiles
Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject ("Scripting.FileSystemObject")
iCountFiles = 0

'==========================================================================
' Begin log file etnries
'==========================================================================
If EnableLogging = True Then 
	Dim oVersionLog
	If Not oFSO.FileExists("C:\Windows\Temp\DeleteIeCookies.log") Then
		oFSO.CreateTextFile "C:\Windows\Temp\DeleteIeCookies.log"
	End If
	Set oVersionLog = oFSO.OpenTextFile ("C:\Windows\Temp\DeleteIeCookies.log", ForAppending, True)
	
	oVersionLog.WriteLine "Delete Craigslist cookies"
	oVersionLog.WriteLine "  => Began at " & Date & " " & Time
End If
'==========================================================================

' Get list of folders in C:\Users
Dim oUserFolders, oFolder, colFiles, oUserCookieFolder, oFile
Set oUserFolders = oFSO.GetFolder("C:\Users") 

For Each oFolder In oUserFolders.subfolders 
	DeleteFile ("C:\Users\" & oFolder.name & "\AppData\Roaming\Microsoft\Windows\Cookies") 
	DeleteFile ("C:\Users\" & oFolder.name & "\AppData\Roaming\Microsoft\Windows\Cookies\Low") 
Next 

' End logging
If EnableLogging = True Then 
	oVersionLog.WriteLine "  => Total number of deleted cookies: " & iCountFiles
	oVersionLog.WriteLine "  => Completed at " & Date & " " & Time
	oVersionLog.Close
End If

WScript.Quit

Sub DeleteFile (sFolderPath)
	If oFSO.FolderExists (sFolderPath) Then
		Set oUserCookieFolder = oFSO.GetFolder(sFolderPath)
		Set colFiles = oUserCookieFolder.Files
		For Each oFile In colFiles
			If InStr (oFile.Name, CookieName) Then 
				If EnableLogging = True Then
					oVersionLog.WriteLine "  => Deleted " & sFolderPath & "\" & oFile.Name
				Else
					WScript.Echo sFolderPath & "\" & oFile.Name
				End If
				oFSO.DeleteFile sFolderPath & "\" & oFile.Name
				iCountFiles = iCountFiles + 1
			End If
		Next 
	End If	
End Sub

Script to reset IE 8 zoom

Posted on Updated on

An old script to share :-)  It will help to fix an old problem that occurred in IE 8, if that’s even still around and in use today ;-)

'==========================================================================
' AUTHOR  : Nick Moseley
' COMMENT : This script will parse all User profiles on the computer, load their
' 	HKCU hive, then set the appropriate registry keys.
' HISTORY : 
'	1.0 (01/01/2009) - Original script
'	1.1 (04/07/2009) - Added code for default user profile
'	1.2 (06/07/2009) - Added code for writing changes to C:\Windows\Version Log.txt
'	2.0 (03/01/2010) - Added support/samples for DWORD values. Added custom
'		error codes to check for failed regkey or value creations. Added
'		a skip for svcdesktopauthclient account.
'	2.1 (05/04/2011) - FIxed the logging to not use asterisks
'==========================================================================
Option Explicit

Const ForAppending = 8
Const HKLM = &H80000002
Const sUserKey = "\Software\Microsoft\Internet Explorer\Zoom" ' Note: key must have a leading backslash
Const sDWORDValueName = "ResetZoomOnStartup2"
Const sDWORDValue = "1"

Dim oReg, oFSO, oFile, oUserSubkey, aUserProfiles, oShell
Dim sProfileLCase, sRegExe, sRegLoad, sRegUnload, sHiveName, sSubPath, sProfile, sValueName, sKeyPathUserProfiles, sValue, ReturnVal

Set oReg = GetObject("winmgmts:\\.\root\default:StdRegProv")
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject ("Scripting.FileSystemObject")

'==========================================================================
' Begin log file etnries
'==========================================================================
If Not oFSO.FileExists("C:\Windows\Temp\ResetIe8zoom.log") Then
	oFSO.CreateTextFile "C:\Windows\Temp\ResetIe8zoom.log"
End If
Set oFile = oFSO.OpenTextFile ("C:\Windows\Temp\ResetIe8zoom.log", ForAppending, True)

oFile.WriteLine "Configuration of user settings for IE 8 Reset Zoom Level"
oFile.WriteLine "  => Began at " & Date & " " & Time
oFile.WriteLine "  => For each user profile, set " & sDWORDValueName & " (string) to " & sDWORDValue & " in HKCU" & sUserKey
'==========================================================================


' Begin configuration of existing user profiles
sValueName = "ProfileImagePath"
sKeyPathUserProfiles = "SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList"
sRegExe = "C:\Windows\system32\reg.exe"

oReg.EnumKey HKLM, sKeyPathUserProfiles, aUserProfiles

' Existing User Profiles
For Each oUserSubkey In aUserProfiles
    sSubPath = sKeyPathUserProfiles & "\" & oUserSubkey
    oReg.GetExpandedStringValue HKLM,sSubPath,sValueName,sValue
  
    sProfile = Split(sValue, "\")
    sProfileLCase = LCase(sProfile(2))
  
    If sProfileLCase = "system32" Then
    	oFile.WriteLine "  => Skipped user profile: system32"
    ElseIf sProfileLCase = "localservice" Then
    	oFile.WriteLine "  => Skipped user profile: localservice"
    ElseIf sProfileLCase = "networkservice" Then
    	oFile.WriteLine "  => Skipped user profile: networkservice"
    ElseIf sProfileLCase = "serviceprofiles" Then
    	oFile.WriteLine "  => Skipped user profile: serviceprofiles"
    ElseIf sProfileLCase = "svcdesktopauthclient" Then
    	oFile.WriteLine "  => Skipped user profile: svcdesktopauthclient"
    Else
    	sHiveName = "TempHive_" & sProfileLCase
    
    	' Load user's profile hive into a temp location
    	sRegLoad = " LOAD HKLM\" & sHiveName & " """ & sValue & "\ntuser.dat"""
    	oShell.Run sRegExe & sRegLoad, 0, True
    
    	' Call subroutine to change registry key
    	SetConfigUserHive (sHiveName)
		oFile.WriteLine "  => Set user profile: " & sProfileLCase
    
    	' Unload user's profile hive
    	sRegUnload = " UNLOAD HKLM\" & sHiveName
    	oShell.Run sRegExe & sRegUnload, 0, True
    End If  
Next

' Default User Profile
sHiveName = "TempHive_DefaultUser"
sRegLoad = " LOAD HKLM\" & sHiveName & " ""C:\Users\Default\ntuser.dat"""
oShell.Run sRegExe & sRegLoad, 0, True
SetConfigUserHive (sHiveName)
oFile.WriteLine "  => Set user profile: Default User"
sRegUnload = " UNLOAD HKLM\" & sHiveName
oShell.Run sRegExe & sRegUnload, 0, True

' End logging
oFile.WriteLine "  => Completed at " & Date & " " & Time
WScript.Quit (oFile.Close)

Sub SetConfigUserHive (sTempHive)
	Dim sTempHiveKeyPath

	' Path of registry keys
	sTempHiveKeyPath = sTempHive & sUserKey

	' Create registry key if the value doesn't already exist
	If oReg.GetDWORDValue(HKLM, sTempHiveKeyPath & "\", sDWORDValueName) <> 0 Then
		ReturnVal = oReg.CreateKey(HKLM, sTempHiveKeyPath)
	End If

	' Create DWORD Value
	ReturnVal = oReg.SetDWORDValue(HKLM, sTempHiveKeyPath & "\", sDWORDValueName, sDWORDValue)
End Sub



Script to disable NIC power save features

Posted on Updated on

An old script to share :-)  It will parse the list of available network adapters to then disable power save features.

'==========================================================================
' NAME: SetNetworkPnPCapabilities
' AUTHOR: Nick Moseley , https://t3chn1ck.wordpress.com
' COMMENT: Parses list of available network adapters to then disable power
'	save features.  For more info, see Microsoft KB837058
' VERSION HISTORY:
'	1.0 (05/09/2011) - Initial script
'	1.1 (05/10/2011) - Fixed logical bug within the If statement for Wan/Lan
'	2.0 (05/10/2011) - Added logging into registry for future inventory
'	3.0 (08/17/2011) - Commented out changes to disable NIC power save as
'		this needs to be enabled in order to support WOL
'==========================================================================
Option Explicit
Const ForAppending = 8

Dim oShell, oWMI, colNetworkAdapterItems, sNetworkAdapterReg
Set oShell = CreateObject ("WScript.Shell")
Set oWMI = GetObject("winmgmts:\\.\root\cimv2")
Set colNetworkAdapterItems = oWMI.ExecQuery ("Select * from Win32_NetworkAdapter")
sNetworkAdapterReg = "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\"

' Logging
Dim oFSO, oVersionLog
Set oFSO = CreateObject ("Scripting.FileSystemObject")
Set oVersionLog = oFSO.OpenTextFile ("C:\Windows\Temp\SetNetworkPnPCapabilities.log", ForAppending, True)
oVersionLog.WriteLine "Configuration of Network Adapters"
oVersionLog.WriteLine "  => Started (" & Date & " " & Time & ")"

' Get all objects and take action on network adapters
Dim oItem, sIndexValue, sLomValue
For Each oItem In colNetworkAdapterItems
	If InStr(lcase(oItem.Name),"wan miniport")=0 _
	  And InStr(LCase(oItem.Name),"microsoft isatap")=0 _ 
	  And Trim(oItem.Name)<>"RAS Async Adapter" _
	  And InStr(LCase(oItem.Name),"cisco")=0 Then 
		If oItem.Index < 10 Then
			sIndexValue = "000" & oItem.Index
		Else
			sIndexValue = "00" & oItem.Index
		End If
		
		' ****************************************
		' IMPORTANT: NIC power save as needs to be enabled in order to support WOL
		' Configure/disable Power save on NIC
		'oShell.RegWrite sNetworkAdapterReg & sIndexValue & "\PnPCapabilities", "56", "REG_DWORD"
		'oVersionLog.WriteLine "  => Disabled network adapter power save on device """ & oItem.Name & """"
		'oVersionLog.WriteLine "     Set PnPCapabilities (dword) to 38 in " & sNetworkAdapterReg & sIndexValue
		' ****************************************
				
		' Configure/enable WAN/LAN switching
		sLomValue = ReadRegistryKey (sNetworkAdapterReg & sIndexValue, "LOM")
		If sLomValue<>"1"  And sLomValue<>"null" Then
			oShell.RegWrite sNetworkAdapterReg & sIndexValue & "\LOM", "1", "REG_SZ"
			oVersionLog.WriteLine "  => Enabled WAN/LAN switching on device """ & oItem.Name & """"
			oVersionLog.WriteLine "     Set LOM (string) to ""1"" in " & sNetworkAdapterReg & sIndexValue
		End If		
	End If 
Next 

' End
oVersionLog.WriteLine "  => Completed (" & Date & " " & Time & ")"
WScript.Quit (oVersionLog.Close)

Function ReadRegistryKey (sReadKey, sReadValue)
	On Error Resume Next
	Dim sGetValue
	sGetValue = oShell.RegRead (sReadKey & "\" & sReadValue)
	
	If Err.Number <> 0 Then
		ReadRegistryKey = "null"
	Else
		ReadRegistryKey = cstr(sGetValue)
	End If 	
End Function

Script to Disable WiFi Device

Posted on Updated on

An old script to share :-) Below is an example script that was once used to disable WiFi devices on desktop computers attached to the LAN, but that came with a built-in and enabled WiFi device.


'==========================================================================
' NAME: DisableWifi
' AUTHOR: Nick Moseley, Archstone
' COMMENT: Determines if a network adapter device is wireless/wifi and then
' executes a devcon command to disable the device. This should only target
' Vostro desktops where there is wireless adapter
' VERSION HISTORY:
' 1.0 (05/13/2011) - Initial Script
' 2.0 (05/25/2011) - Added logging into registry for future inventory
'==========================================================================
Option Explicit
Const ForAppending = 8

Dim oWMI, oShell, colItems, oFSO, oFile
Set oShell = CreateObject ("WScript.Shell")
Set oWMI = GetObject ("winmgmts:\\.\root\cimv2")
Set colItems = oWMI.ExecQuery ("Select * from Win32_PnPEntity where name like '%wireless%' or name like '%wifi %'")

'Start logging
Set oFSO = CreateObject("Scripting.fileSystemObject")
Set oFile = oFSO.OpenTextFile ("C:\Windows\Temp\DisableWifi.log", ForAppending, True)
oFile.WriteLine "Disable wireless network adapter"
oFile.WriteLine "  => Started (" & Date & " " & Time & ")"

' If count=0 of the collection, then no wireless devices found
If colItems.count=0 Then
oFile.WriteLine "  => WARNING: Wireless network adapter not found!"
Else
Dim oItem, sDeviceType
oFSO.CopyFile oFSO.GetFile(Wscript.ScriptFullName).ParentFolder & "\devcon\i386\devcon.exe ", "C:\Windows\Temp\devcon.exe"
' Parse the collection of wireless devices to be disabled
For Each oItem In colItems
sDeviceType = UCase(Left(oItem.DeviceID, 3))
If sDeviceType = "PCI" Then
oShell.Run "C:\Windows\Temp\devcon.exe disable ""@" & oItem.deviceID & ""
oFile.WriteLine "  => Disabled " & oItem.Name
oFile.WriteLine "     Device ID: " & oItem.DeviceID
End If
Next
End If
' End
oFile.WriteLine "  => Completed (" & Date & " " & Time & ")"
WScript.Quit (oFile.Close)

Script to enable NIC magic packets

Posted on Updated on

An old script to share :-)  It will enable magic packets for NIC devices.

'==========================================================================
' NAME: EnableNICMagicPackets
' AUTHOR: Nick Moseley , https://t3chn1ck.wordpress.com
' COMMENT: Parses list of available network adapters to then disable power
'	save features.  For more info, see Microsoft KB837058
' VERSION HISTORY:
'	1.0 (05/09/2011) - Initial script
'	1.1 (05/10/2011) - Fixed logical bug within the If statement for Wan/Lan
'	2.0 (05/10/2011) - Added logging into registry for future inventory
'	3.0 (08/26/2011) - Modified the disable NIC power save to instead be
'		enabled, so as to support Wake On LAN. Windows network devices
'		should have selected (on Power Management) option ""Only allow a 
'		magic packet to wake the computer""
'==========================================================================
Option Explicit
Const ForAppending = 8

Dim oShell, oWMI, colNetworkAdapterItems, sNetworkAdapterReg
Set oShell = CreateObject (""WScript.Shell"")
Set oWMI = GetObject(""winmgmts:\\.\root\cimv2"")
Set colNetworkAdapterItems = oWMI.ExecQuery (""Select * from Win32_NetworkAdapter"")
sNetworkAdapterReg = ""HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\""

' Logging
Dim oFSO, oVersionLog
Set oFSO = CreateObject (""Scripting.FileSystemObject"")
Set oVersionLog = oFSO.OpenTextFile (""C:\Windows\Temp\EnableNICMagicPackets.log"", ForAppending, True)
oVersionLog.WriteLine ""Configuration of Network Adapters""
oVersionLog.WriteLine ""  > Started ("" & Date & "" "" & Time & "")""

' Get all objects and take action on network adapters
Dim oItem, sIndexValue, sLomValue
For Each oItem In colNetworkAdapterItems
	If InStr(lcase(oItem.Name),""wan miniport"")=0 _
	  And InStr(LCase(oItem.Name),""microsoft isatap"")=0 _ 
	  And Trim(oItem.Name)<>""RAS Async Adapter"" _
	  And InStr(LCase(oItem.Name),""cisco"")=0 Then 
		If oItem.Index < 10 Then
			sIndexValue = ""000"" & oItem.Index
		Else
			sIndexValue = ""00"" & oItem.Index
		End If

		' ****************************************
		' IMPORTANT: NIC power save as needs to be enabled in order to support WOL
		' Configure/enable Power save on NIC. Value 256 (dec) converts to 100 (hex) in registry.
		oShell.RegWrite sNetworkAdapterReg & sIndexValue & ""\PnPCapabilities"", ""256"", ""REG_DWORD""
		oVersionLog.WriteLine ""  > Enabled network adapter power save on device """""" & oItem.Name & """"""""
		oVersionLog.WriteLine ""     Set PnPCapabilities (dword) to 100 in "" & sNetworkAdapterReg & sIndexValue
		' ****************************************

		' Configure/enable WAN/LAN switching, possible when subkey LOM exists
		sLomValue = ReadRegistryKey (sNetworkAdapterReg & sIndexValue, ""LOM"")
		If sLomValue<>""1""  And sLomValue<>""null"" Then
			oShell.RegWrite sNetworkAdapterReg & sIndexValue & ""\LOM"", ""1"", ""REG_SZ""
			oVersionLog.WriteLine ""  > Enabled WAN/LAN switching on device """""" & oItem.Name & """"""""
			oVersionLog.WriteLine ""     Set LOM (string) to """"1"""" in "" & sNetworkAdapterReg & sIndexValue
		End If		
	End If 
Next 


' End
oVersionLog.WriteLine ""  > Completed ("" & Date & "" "" & Time & "")""
WScript.Quit (oVersionLog.Close)

Function ReadRegistryKey (sReadKey, sReadValue)
	On Error Resume Next
	Dim sGetValue
	sGetValue = oShell.RegRead (sReadKey & ""\"" & sReadValue)
	
	If Err.Number <> 0 Then
		ReadRegistryKey = ""null""
	Else
		ReadRegistryKey = cstr(sGetValue)
	End If 	
End Function

Script to configure IE setting for auto detect LAN

Posted on Updated on

As I was recently doing some cleanup of old files and or scripts that I’ve written years ago, I came across the below script to change a users IE auto detect LAN.


' This script launches IE (hidden) then changes the auto detect LAN settings
' Written by Nick Moseley on 1/10/11

Const HKCU = &amp;H80000001

Dim oReg, oShell
Set oReg= GetObject(&quot;Winmgmts:root\default:StdRegProv&quot;)
Set oShell = CreateObject (&quot;WScript.Shell&quot;)

' Launch IE
Dim sIeExe
sIeExe = &quot;&quot;&quot;C:\Program Files\Internet Explorer\iexplore.exe&quot;&quot;&quot;
oShell.Run sIeExe, 0, False
WScript.Sleep 30000

' Get the binary regkey
Dim sKeyPath, sValueName, sKeyValue, iRetVal1, iRetVal2
sKeyPath = &quot;Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections&quot;
sValueName = &quot;DefaultConnectionSettings&quot;
iRetVal1 = oReg.GetBinaryValue (HKCU,sKeyPath,sValueName,sKeyValue)

' Set array position 9 to value 9
sKeyValue(8)=1

'write new value to registry
iRetVal2 = oReg.SetBinaryValue(HKCU,sKeyPath,sValueName,sKeyValue)

VBScript to Disable Devices with Devcon

Posted on Updated on

The following VBScript can be used as an example for disabling devices with Microsoft’s devcon utility.

'==========================================================================
' NAME: DisableWifi
' AUTHOR: Nick Moseley, https://t3chn1ck.wordpress.com
' COMMENT: Determines if a network adapter device is wireless/wifi and then
' executes a devcon command to disable the device
' VERSION HISTORY:
' 1.0 (05/13/2011) - Initial Script
' 2.0 (05/25/2011) - Added logging into registry for future inventory
'==========================================================================
Option Explicit
Const ForAppending = 8

Dim oWMI, oShell, colItems, oFSO, oFile
Set oShell = CreateObject ("WScript.Shell")
Set oWMI = GetObject ("winmgmts:\\.\root\cimv2")
Set colItems = oWMI.ExecQuery ("Select * from Win32_PnPEntity where name like '%wireless%' or name like '%wifi %'")

'Start logging
Set oFSO = CreateObject("Scripting.fileSystemObject")
Set oFile = oFSO.OpenTextFile ("C:\Windows\Temp\WifiLog.txt", ForAppending, True)
oFile.WriteLine "Disable wireless network adapter"
oFile.WriteLine " => Started (" & Date & " " & Time & ")"

' If count=0 of the collection, then no wireless devices found
If colItems.count=0 Then
 oFile.WriteLine " => WARNING: Wireless network adapter not found!"
Else
 Dim oItem, sDeviceType
 WScript.Echo Wscript.ScriptFullName & "\devcon\i386\devcon.exe "
 oFSO.CopyFile oFSO.GetFile(Wscript.ScriptFullName).ParentFolder & "\devcon\i386\devcon.exe ", "C:\Windows\Temp\devcon.exe"
 ' Parse the collection of wireless devices to be disabled
 For Each oItem In colItems
 sDeviceType = UCase(Left(oItem.DeviceID, 3))
 If sDeviceType = "PCI" Then
 oShell.Run "C:\Windows\Temp\devcon.exe disable ""@" & oItem.deviceID & ""
 oFile.WriteLine " => Disabled " & oItem.Name
 oFile.WriteLine " Device ID: " & oItem.DeviceID
 End If
 Next
End If

' Set registry values for SCCM inventory
oShell.RegWrite "HKLM\Software\CompanyName\ImageInfo\DisabledWirelessNIC", "True", "REG_SZ"

' End
oFile.WriteLine " => Completed (" & Date & " " & Time & ")"
WScript.Quit (oFile.Close)

OSD Options Chooser v3

Posted on Updated on

The following custom HTA can be used during OSD when imaging computers with ConfigMgr.  It has been updated from my previous version and will do the following:

Remember to enable HTA support in your boot images – https://t3chn1ck.wordpress.com/2010/01/28/hta-support-in-sccm-boot-images/

OSDOptionsV3

<!--
Created by Nick Moseley https://t3chn1ck.wordpress.com
For this script to function, HTA support must have been added into the boot image
See for more information - http://technet.microsoft.com/en-us/library/dd799244.aspx

This HTA/VBscript is used to present a GUI during imaging of a corporate PC. It prompts for:
	1) PC name (automatically populated if the PC already exists in SCCM)
	2) Time zone (currently just PST, AZT, and MST)
	3) If the PC will be used as a VM parent image or as a physical PC
	4) One-off software
	5) Additional browsers
	6) Department selection
	7) Management selection
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>OSD Computer Details</title>
<HTA:APPLICATION ID="objNoTitleBar" APPLICATIONNAME="OSD Computer Details" SCROLL="auto" SINGLEINSTANCE="yes" CAPTION="no">

<script language="VBScript">
window.resizeTo 550,255
window.moveTo 3,3

' Hide the task sequence window
'On Error Resume Next

Dim oTaskSequence, oTSProgressUI
Set oTaskSequence = CreateObject ("Microsoft.SMS.TSEnvironment")
Set oTSProgressUI = CreateObject("Microsoft.SMS.TsProgressUI")
oTSProgressUI.CloseProgressDialog

Sub PreloadOptions
	Dim sTSMachineName, bPromptName
	sTSMachineName = ucase(oTaskSequence("_SMSTSMachineName"))

	If left(sTSMachineName,6) = "MININT" Then
		bPromptName = True
	ElseIf sTSMachineName = "MINWINPC" Then
		bPromptName = True
	Else
		bPromptName = False
	End If

	If bPromptName Then
		ComputerName.value = ""
	Else
		ComputerName.value = sTSMachineName
	End If
End Sub

Sub FinishClickTasks
	'====================================
	' Get/set computer name
	'====================================
	Dim sComputerName
	sComputerName = UCase(ComputerName.Value)

	' Check that a PC name was entered
	Do
		If sComputerName = "" Then
			MsgBox "Error: Computer name cannot be left empty!", vbCritical, "Error"
			sComputerName = InputBox ("Please enter a computer name to continue", "", , 30,30)
		End If
	Loop Until sComputerName <> ""

	oTaskSequence ("OSDComputerName") = sComputerName

	'====================================
	' Get/set department configuration
	'====================================
	For Each oSelection in DepartmentChooser.Options
		If oSelection.Selected Then
			oTaskSequence ("OSDDepartment") = lcase(oSelection.InnerText)
		End If
	Next

	'====================================
	' Get/set managerial position
	'====================================
	For Each oSelection in ManagerRole.Options
		If oSelection.Selected Then
			oTaskSequence ("ManagerRole") = lcase(oSelection.InnerText)
		End If
	Next

	'====================================
	' OSConfig selection
	'====================================
	For Each oSelection in OSConfig
		If oSelection.Checked Then
			oTaskSequence ("OSDOSConfig") = lcase(oSelection.value)
		End If
	Next

	'====================================
	' Get/set Other Apps
	'====================================
	If SevenZip.checked Then oTaskSequence ("OSD7zip") = "true" End If
	If Firefox.checked Then oTaskSequence ("OSDFirefox") = "true" End If
	If NotepadPlusPlus.checked Then oTaskSequence ("OSDNotepadPlusPlus") = "true" End If
	If GoogleChrome.checked Then oTaskSequence ("OSDGoogleChrome") = "true" End If
	If PaintNet.checked Then oTaskSequence ("OSDPaintNet") = "true" End If
	If Safari.checked Then oTaskSequence ("OSDAppleSafari") = "true" End If

	'====================================
	' Get/set Time Zone configuration
	'====================================
	For Each oSelection in TZChooser.Options
		If oSelection.Selected Then
			oTaskSequence ("OSDTimeZone") = oSelection.id
		End If
	Next

	'====================================
	' Terminate the HTA
	'====================================
	window.close
End Sub

</script>
</head>

<!------------------------------------------------>
<!---------------- HTML goes here ---------------->
<!------------------------------------------------>
<body STYLE="font:12 pt arial; color:white; background-color:#006699" onload="PreloadOptions">
<table cellpadding="3" border=1>
	<tr valign=top>
		<td>
			<p>
			<b>Computer Name</b><br>
			<input type=text id="ComputerName" name=ComputerName size=22>
			<p>
			<b>Time Zone</b><br>
			<select size="1" name="TZChooser">
				<option value="00" id="Mountain Standard Time">MST (US Mountain)<BR>
				<option value="01" id="Pacific Standard Time">PST (US West Coast)<BR>
				<option value="02" id="US Mountain Standard Time">AZT (US Arizona)<br>
				<!--<option value="03" id="Central Standard Time">CST (US Central)<BR>-->
				<!--<option value="04" id="Eastern Standard Time">EST (US East Coast)<BR>-->
			</select>
			<p>
			<b><u>OS Configuration</b></u><br>
			<input type="radio" value="standalone" name="OSConfig" checked="True"> Standalone PC/VM<br>
			<input type="radio" value="vmparent" name="OSConfig"> VM Parent
		</td>
		<td>
			<b><u>Software Options</b></u><br>
			<input type="checkbox" name="SevenZip"> 7-zip Utility<br>
			<input type="checkbox" name="NotepadPlusPlus"> Notepad++<br>
			<input type="checkbox" name="PaintNet"> Paint.Net<br>
			<p>
			<b><u>Internet Browsers</b></u><br>
			<input type="checkbox" name="Safari"> Apple Safari<br>
			<input type="checkbox" name="Firefox"> Firefox Browser<br>
			<input type="checkbox" name="GoogleChrome"> Google Chrome<br>
		</td>
		<td>
			<p>
			<b><u>Department Selection</b></u><br>
			<select size="1" name="DepartmentChooser">
				<option value="00"> Standard PC</option>
				<option value="01"> Accounting</option>
				<option value="02"> Human Resources</option>
				<option value="03"> Information Technology</option>
			</select>
			<p>
			<b><u>Management Role</b></u><br>
			<select size="1" name="ManagerRole">
				<option value="00"> n/a</option>
				<option value="01"> Supervisor</option>
				<option value="02"> Manager</option>
				<option value="03"> Director</option>
				<option value="03"> VP</option>
			</select>
			<p>
			<button accesskey=N type=submit id=buttonFinish onclick=FinishClickTasks>Finish</button>
		</td>
	</tr>
</table>
<!------------------------------------------------>
<!------------------ End HTML -------------------->
<!------------------------------------------------>

</body>
</html>

Script to Rename Computer During OSD

Posted on Updated on

In assisting a recent customer implement an upgrade from WinXP to Win7, they requested that the names be changed to fit a new standard as part of the in-place imaging process.  In this particular case, all of the computers had a name that ended with a sequential number (1, 2, 3, …) plus an “A” tacked on at the end.  They wanted the “A” removed and for the PC name just to end with the sequential number.

This was a pretty easy fix to accomplish through a VBScript which

  1. Retrieves the active OSDComputerName task sequence variable
  2. Detects if the last letter is an “A”
  3. Truncates the name to remove the “A”
  4. Re-sets OSDComputerName to the new value

'==========================================================================
' NAME: PCNameStandardization.vbs
' AUTHOR: Nick Moseley, <a href="https://t3chn1ck.wordpress.com">https://t3chn1ck.wordpress.com</a>
' COMMENT: This script will detect if the current computer name ends with ' the letter 'A' so that it can be removed.
'==========================================================================
Option Explicit
Dim oTaskSequence, sComputerName, iNameLength
Set oTaskSequence = CreateObject ("Microsoft.SMS.TSEnvironment")

sComputerName = ucase(oTaskSequence("OSDComputerName")) iNameLength = Len(sComputerName)

If right(sComputerName,1) = "A" Then
oTaskSequence("OSDComputerName") = left(sComputerName, iNameLength-1)
  ' The echo statement is not displayed, but rather registered in SMSTS.log
wscript.echo ">>>> Set OSDComputerName from " & sComputerName & " to " & oTaskSequence("OSDComputerName")
End If

To add this into your task sequence:

  1. Put this script into a package for your general OSD Scripts
  2. Ensure you have the step to capture the computer name
    CaptureWinSettings
  3. Immediately after the capture windows settings, run the PC Standardization Script
    PCNameStandardization
  4. On whatever step you have that prompts for the PC Name, add a condition to not execute if variable OSDComputerName does not exist.  This is so that task sequence will not be held up on the other end waiting for someone to enter a PC name for one you’ve already set.
    PromptPCNameCondition
  5. Finally – ensure ConfigMgr environment is configured to automatically resolve conflicting records!  See this as to why https://t3chn1ck.wordpress.com/2013/02/14/error-initializing-client-registration-0x80040222/