Jump to content


anyweb

Updated Script: How can I check for network connectivity & storage before starting a task sequence in System Center 2012 R2 Configuration Manager ?

Recommended Posts

we are using it in a SCCM 1702 CB environment with 1703 adk boot wims. no problems

you have probably made a 'mistake' in the script editing, causing it to fail and reboot, you can test the scripts 'manually'  by creating standalone media (usb) and testing that way... over and over

Share this post


Link to post
Share on other sites

Good to know. And good point. The only change I made was the edit of the IPs to check, but I probably got a little ambitious by replacing the IPs with a DNS hostname. I'll try swapping it out with the IP.

Thanks,

== Matt

Edit: Actually it looks like I messed up the wim injection. Disregard!

Edited by mmseng

Share this post


Link to post
Share on other sites

Fix for bootloops when a TS is initiated from Software Center and the script is detecting failures during the checks.

Change

Sub Reboot
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "wpeutil reboot"
End Sub

To

Sub Reboot

Set objFSO2 = CreateObject("Scripting.FileSystemObject")
Set colDrives = objFSO2.Drives
For Each objDrive in colDrives
	if objDrive.DriveType=2 then
		SMSTSDrive=objFSO2.FolderExists(objDrive.DriveLetter + ":\_SMSTaskSequence")
		if SMSTSDrive then
			BootDrive=objDrive.DriveLetter&":\"
		end if
	end if
Next

Set WshShell = WScript.CreateObject("WScript.Shell")
PEFirmware="HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\PEFirmwareType"
PeBoot = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\PEBootType"

FirmwareType=WshShell.RegRead(PEFirmware)
BootType=WshShell.RegRead(PeBoot)


If lcase(BootType)="ramdisk:sourceidentified" then
	If FirmwareType=2 then
		BCD=BootDrive&"_SMSTaskSequence\BCD-EFI\BCD"
	else
		BCD=BootDrive&"_SMSTaskSequence\backup\boot\BCD"

	end if
	WshShell.Run("bcdedit /import " & BCD & " /clean"),1,true
	wscript.sleep(2000)
end if
WshShell.Run "wpeutil reboot"

End Sub

This will also cause the TS to continue in the full OS.
If you want to prevent that add something like this after the first reboot. (Since checkfornetwork.vbs shouldn't fail if it succeeded the first time)

image.png.f3b20a106bc6d06e53ec9bd356a68ca6.png

 

Side note.

The start cmd part is good but it's a LPE-exploit waiting to happen. All you have to do is start a TS from SC and then pull the cable and you're 'local system'.
Don't bind it to cancel since the x in the corner returns the same thing.

Detect if "command support" is enabled on the boot image and only give the choice to start a cmd.exe if so.

Add the last 2 lines accordingly.

' updated 2015/4/26 logging folder creation fix
'
On Error Resume Next
DIM objShell, WshNetwork, sPingTarget, iNumberofFails, iFailureLimit, LogFileName, logfile, objFSO, objFile, outFile, CheckPartitions
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objShell = WScript.CreateObject( "WScript.Shell" )
sysDrv=objShell.ExpandEnvironmentStrings( "%SYSTEMDRIVE%" )
Buttons=vbOKOnly

And this.

function isDebug()
FoundINI=objFSO.FileExists(sysdrv+"\Windows\System32\winpeshl.ini")
If (FoundINI=vbTrue) then
	'wscript.echo Cstr(bExists) & " " & bExists
	Set file = objFSO.OpenTextFile (sysdrv+"\Windows\System32\winpeshl.ini", 1, vbFalse, -1)

	row = 0
	Do Until file.AtEndOfStream
		line = file.Readline
		'WScript.Echo lcase(line)
		If (instr(lcase(line),"tsbootshell.exe")<>0) then
			TsBootShell=replace(lcase(line),"tsbootshell.exe","tsbootshell.ini")
			'Wscript.echo TsBootShell
			TsINI=objFSO.FileExists(objShell.ExpandEnvironmentStrings(TsBootShell))
			If (TsINI=vbTrue) then
				Set ReadTsINI = objFSO.OpenTextFile (objShell.ExpandEnvironmentStrings(TsBootShell), 1, vbFalse, -1)
				strTSINItext=ReadTsINI.readall
				If (instr(lcase(strTSINItext),lcase("EnableDebugShell=true"))<>0) then
				'WScript.Echo "DebugMode"
				Buttons=vbYESNO
				end if
			ReadTsINI.Close
			end if

		end if
		row = row + 1
	Loop

file.Close
end if

end function

Add a 'If' on the buttons shown and that's been taken care of as well.

E.g.

if (Buttons=vbOKOnly) then
Message="Kunde inte hitta en hårddisk att installera Windows på." & vbCrLf & vbCrLf & " Meddela IT att detta kan vara orsaken:" & vbCrLf & vbCrLf & "* Saknar drivrutiner för hårddisken . " & vbCrLf & "* Hårddisken kan vara trasig. " & vbCrLf & vbCrLf & "Hårdvara: " & vbCrLf & vbCrLf & SataResult &"Dator: "& MakeModel & vbCrLf & vbCrLf & "Tryck [OK] när du är klar."
Else
Message="Kunde inte hitta en hårddisk att installera Windows på." & vbCrLf & vbCrLf & " Meddela IT att detta kan vara orsaken:" & vbCrLf & vbCrLf & "* Saknar drivrutiner för hårddisken . " & vbCrLf & "* Hårddisken kan vara trasig. " & vbCrLf & vbCrLf & "Hårdvara: " & vbCrLf & vbCrLf & SataResult &"Dator: "& MakeModel & vbCrLf & vbCrLf & "Tryck [YES] för att få installationen att misslyckas eller [NO] för att starta en CMD-prompt."
end if
result=MsgBox (Message, Buttons, "Warning: Unable to continue")

'result = MsgBox ("Unable to find a valid internal storage device." & vbCrLf & vbCrLf & "Possible causes can be: " & vbCrLf & vbCrLf & "* Missing Storage drivers. " & vbCrLf & "* Missing HDD/SSD. " & vbCrLf & vbCrLf & "Please inform the person supporting you that the following hardware was detected: " & vbCrLf & vbCrLf & SataResult &"Computer: "& MakeModel & vbCrLf & vbCrLf & "Press [OK] to exit and reboot or press [Cancel] to open a CMD prompt to troubleshoot further."_
', vbOKCancel, "Warning: Unable to continue")

		Select Case result
		Case vbOK
				Set objShell = Nothing
				'objShell.Run("x:\windows\system32\winpeshl.exe"),1,true
				Reboot
		Case vbNo
				Set objShell = WScript.CreateObject( "WScript.Shell" )
				objShell.Run("cmd.exe /s")
				msgbox "When you are finished, press [OK]"
				Reboot
		End Select

Edit: And of course calling the function early in the script.

CheckForNetwork.gif

  • Like 1

Share this post


Link to post
Share on other sites

the script is downloadable still (scroll up this page for the link...), you just need to be a logged on member to download it, so please try again

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.