I had a situation today where I needed to be able to execute a script during an MDT/OSD WinPE platform build (that’s a mouthful for basically saying it’s imaging a new Windows desktop computer, but running in the stage prior to the “real” Windows being operational, so it’s running in the Pre-Execution environment which is a stripped-down, nuts-n-bolts, diet-lite version of Windows just for bootstrapping and doing other low-level chores. Ok, back to the regularly scheduled boredom you can’t wait to dive into…)
The problem is that the MDAC environment that can be optionally bolted onto the WinPE loader is pretty strange (I’ve already blogged about this, search). That left FileSystemObject as a workaround, and it works great. BUT. There’s always a “BUT”… The OSD task sequencer has issues trying to connect to an anonymous UNC share. It expects a mapped drive with credentials (after all, the WinPE session is not part of a domain, so it’s a rogue workgroup ninja, running around buck nekkid trying to get into your cookie jars) and then there’s some new issues with NTLMv2 and Kerberos with Windows Server 2008 R2 and trying to allow “Everyone” to have read-only access to a shared folder. It’s not very workable.
Another issue is that if you load the TXT data file into the task sequencer, then everytime it needs to be updated (in our case, daily or more frequent), it increments the hash ID in SCCM. That invalidates the sequence until an Admin approves the change. Cumbersome. Sort of like everytime a teacher would write on the chalkboard, all the kids’ pencils stopped working until the teacher turns around to push an “approve” button on her desk. Yeah. That won’t do.
Then it hit me> WinPE supports the XmlHttp object. So…. I just copy the .TXT data file to an intranet web server, drop it into a virtual folder that allows anonymous authentication, and switch from FSO to XmlHTTP to fetch the file from the URL (rather than UNC) and BOOM! Like a kick to the forehead with ice-climbing boots, it works. And I didnt’ have to stop and code some SOAP web services layer and a SQL table or anything (that would be more “robust” for sure, but time didn’t allow for such luxuries).
The code looks something like this (I had to severely compact and simplify this):
' a tab-delimited text file...
url = "http://intranet.contoso.msft/textfile.txt"
findValue = "12345"
Set http = CreateObject("Microsoft.XmlHttp")
http.Open "GET", url, False
textData = http.responseText
For each txtLine in Split(textData, vbCRLF)
If Trim(txtLine) <> "" Then
arrText = Split(Trim(txtLine), vbTab)
column1 = Trim(arrText(0))
column2 = Trim(arrText(1))
'... and so on...
If column1 = findValue Then
returnValue = column2
Set http = Nothing