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

Introduction
In a previous post I showed you how you can check for network connectivity before starting a task sequence in Configuration Manager 2012 R2. In this post I'll add a newer script to also check for storage (SAS, SATA, SCSI, Storage). The added code gives you new abilities to deal with hardware that has changed for whatever reason and it allows you to quickly identify the problem, and identify the storage vendor id and device id so that you can go looking for drivers.

 

As storage is a must (the task sequence must write temp files on your hard disc and also copy packages) adding this change to the script was inevitable. I hope you like the results.

 

Get the new script.

Here's the updated script

 

CheckForNetwork.zip

 

simply replace the earlier script with this one as documented in the process detailed here.

 

Note: if you downloaded the script prior to 2015/4/22 then please download it again as there's a newer version here with fixes and logging added. The new script logs to X:\Windows\Temp\SMSTSLOG\checkfornetwork.log

 

See the results

After implementing the new script in your boot image this is what you'll see when it detects missing storage drivers.

 

warning unable to continue.png

 

As you can see from the message it provides the following info

  • a reason for the popup (no storage detected)
  • lists the detected storage controller
  • lists the PNP Device ID
  • identifies the Computer model

and gives the user some options

  • click OK to reboot.
  • click CANCEL to open a CMD prompt if further troubleshooting is needed

In addition to the above, it also checks for network (if and only if the storage check above passes), and in the event of a network connectivity failure you'll see this

 

cannot connect to network.png

 

which provides the following info

  • a reason for the popup (no network connectivity)
  • lists the detected Network Card
  • lists the PNP Device ID
  • identifies the Computer model

and gives the user some options

  • click YES to retry (for example if the network cable was not connected)
  • click CANCEL to open a CMD prompt if further troubleshooting is needed
  • click OK to reboot.

Well that's it, I hope you like the update ! please test it and give me feedback

 

cheers

niall

Share this post


Link to post
Share on other sites


Can this same solution be implemented within MDT? I'm assuming so but don't know if it is just an edit of the LiteTouch WIM file or if there would have to be other steps as well.

Share this post


Link to post
Share on other sites

hi Tim, I havn't tried it in an MDT only environment yet, but i would imagine the results would be similar, feel free to beat me to it and post your results, in my testing I'm using SCCM CB with MDT integrated..and it works just fine

Share this post


Link to post
Share on other sites

hi, sounds super interesting and usefull I'll try to implement this with an mdt boot img

quick question before how would it reacts if it's a standalone image?

thanks!

Share this post


Link to post
Share on other sites

so I've implemented the script in an MDT 2013 update 2 boot image (integrated with sccm) , works great, detects when no network or when no disk, really really usefull, should be included by default :) Niall, thanks a lot for putting this together and sharing it!

Now... i'm sometimes using a standalone image, using the same boot image, is there a way in the script to detect it (or prestaged media) and bypass the network detection in this case?

yeah I could choose another boot image without the script but I have other customizations  as well and like to keep thing as simple as possible

thanks a lot

Share this post


Link to post
Share on other sites
Now... i'm sometimes using a standalone image, using the same boot image, is there a way in the script to detect it (or prestaged media) and bypass the network detection in this case? 

can you expand on this please ?

Share this post


Link to post
Share on other sites

well in a standalone image you don't need network connectivity to run the task sequence right? you can just run it from an usb key. But it's still using the boot image to boot in winPE at the beginning, so if we have a script asking for network in the boot image without any way to ignore it the task sequence can't start.

hope it helps, let me know if it still unclear?thanks

Share this post


Link to post
Share on other sites

right then the logic would have to change in the script, so that it knows if it's booted via standalone, and if so, skip the checkfornetwork step

 

check for the following variable

 

_SMSTSLaunchMode

 

Specifies the task sequence launch method. The task sequence can have the following values:

  • SMS - specifies that the task sequence is started by using the Configuration Manager client.

  • UFD - specifies that the task sequence is started by using USB media and that the USB media was created in Windows XP/2003.

  • UFD+FORMAT - specifies that the task sequence is started by using USB media and that the USB media was created in Windows Vista or later.

  • CD - specifies that the task sequence is started by using a CD.

  • DVD - specifies that the task sequence is started by using a DVD.

  • PXE - specifies that the task sequence is started from PXE.

  • HD – specifies that the task sequence was started from a hard disk (prestaged media only).

 

and based on the value it returns do the above...

Share this post


Link to post
Share on other sites

right, but I don't think the TS variables are already set up so early in WinPe (I may be wrong), that's why I was thinking an ignore button would just do the trick (there is probably more clever solutions but my coding abilities are somewhat limited)

Share this post


Link to post
Share on other sites

Any comments as to SCCM CB compatibility? I've implemented this in SCCM CB 1702 using a copy of our standard Win10 1607 boot image. It looks like the script is running and immediately exiting, and WinPE then immediately reboots, presumably because that's how WinPE seems to behave when there is nothing left to run.

Any ideas would be appreciated. Otherwise, I'll have to start a cycle of plopping pauses in the script and recompiling and redistributing the wim :/

Thanks,

== Matt

Share this post


Link to post
Share on other sites

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

good work, thanks for the updates and the fix for that scenario !

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...