I’ve received a lot of feedback on my ZTISelectBootDisk.wsf post.
I must admit that the MDT and SCCM way of selecting the correct disk and partition can get a bit frustrating when dealing with multiple disks and partitions. the ZTISelectBootDisk.wsf post was designed to illustrate how to get more control over this process. It is by no means the only solution, but it’s a good start.
Well today I received a e-mail asking for some more control over the disk selection process:
Is there a way to check to see if a disk has data, such as a D: drive? If it does, then do not format it. I (obviously) will always format the C: drive on a new build. […]
I have a server where the OS has been corrupted, or I need to re-build it to Server 2012 R2, whatever my App team needs.
It’s hard to target drives that do *not* have data on them, since *all* drives have data on them, even the C: (OS) drive. :^) Also note that while within WinPE (the MDT Pre-Install Phase), the Drive/Partition that contains the old OS may *not* be currently labeled as C:.
Instead it would be easier to do a search for an existing installation of Windows by enumerating through all the drives, and then setting the OSDDiskIndex variable to that disk. OSDDIskIndex is the variable that ZTIDIskPart.wsf uses by default to blow away the partitions and start the full installation.
Option Explicit RunNewInstance const sSearch = "WHERE DriveType = 3 AND MediaType = 12 AND FreeSpace > 17179869184 AND FileSystem = 'NTFS'" Class ZTISetTargetDiskFromHint Function Main dim Found Dim oDrive Dim oDisk oLogging.CreateEntry "Enumerate through all logical drives", LogTypeInfo for each oDrive in AllLogicalDrivesEx ( sSearch ) if oFSO.FIleExists ( oDRive.Caption & "\Windows\System32\ntoskrnl.exe" ) then oLogging.CreateEntry "Found: " & oDRive.Caption & "\Windows\System32\ntoskrnl.exe" , LogTypeInfo if isobject(Found) then oLogging.CreateEntry "\Windows exists on more than one disk, clean one disk First." , LogTypeError Main = failure exit function End if For Each oDisk in objWMI.ExecQuery("ASSOCIATORS OF {" & oDRive.Path_ & "} WHERE AssocClass = Win32_LogicalDiskToPartition") oLogging.CreateEntry "Found Target: " & oDrive.Path_ & " " & oDisk.Path_ , LogTypeInfo set Found = oDisk exit for Next end if next if isObject(Found) then oLogging.CreateEntry "Found a single Target Canidate: " & Found.Path_, LogTypeInfo if isnumeric(oEnvironment.Item( "OSDDISKINDEX" )) then oLogging.CreateEntry "Existing OS Disk Index is: " & oEnvironment.Item( "OSDDISKINDEX" ), LogTypeInfo if cint(Found.DiskIndex) cint(oEnvironment.Item( "OSDDISKINDEX" )) then oEnvironment.Item( "OSDDISKINDEX" ) = Found.DiskIndex end if end if end if Main = Success End Function End Class