none
MDT Set a variable using a script

    Question

  • Using MDT I want to be able to partition a disk based on the disk size.  For instance if the disk is smaller than a certain size format and partition one way, if the disk is larger than that size format and partition it differently.  Originally I created 2 task sequences that used a WMI query to determine the size of drive 0..."SELECT * FROM Win32_DiskDrive where Index = '0' and Size > '107696304947'" for one sequence and ..."SELECT * FROM Win32_DiskDrive where Index = '0' and Size < '107696304947'" for the other sequence.  That failed, apparently because the value is stored in an array and MDT can't work with that.

    So my next approach is to set the disk size to a variable using a script and do the greater than less than operation using this variable.  To that end I created a variable as a task sequence of "GetDrive0Size" and set its value to 0.  Next I run a command line task to execute a wsf script to go and grab the disk size and set it to the GetDrive0Size variable.  This script fails in the task sequence with the error:

    "Failed to save environment to (80070057)"

    "Failed to run the action:  Get Drive 0 Size."

    "Incorrect funtion. (Error: 00000001; Source: Windows)"

    Below is my script, is there an issue with this or can anyone suggest a better way to accomplish what I am trying to do?

    <job id="Z-Sample">
    <script language="VBScript" src="ZTIUtility.vbs" mce_src="ZTIUtility.vbs"/>
    <script language="VBScript">

    ' //***************************************************************************
    ' // ***** Script Header *****
    ' //
    ' // Solution: Solution Accelerator for Business Desktop Deployment
    ' // File: Z-GetDrive0Size.wsf
    ' //
    ' // Purpose: Template
    ' //
    ' // Usage: cscript Z-GetDrive0Size.wsf [/debug:true]
    ' //
    ' // Customer Build Version: 1.0.0
    ' // Customer Script Version: 1.0.0
    ' // Customer History:
    ' //
    ' // ***** End Header *****
    ' //***************************************************************************

    '//----------------------------------------------------------------------------
    '//
    '// Global constant and variable declarations
    '//
    '//----------------------------------------------------------------------------

    Option Explicit

    Dim iRetVal
    Dim strComputer
    Dim objWMIService
    Dim colItems
    Dim objItem
    Dim osd: set env=CreateObject("Microsoft.SMS.TSEnvironment")

    '//----------------------------------------------------------------------------
    '// End declarations
    '//----------------------------------------------------------------------------

    '//----------------------------------------------------------------------------
    '// Main routine
    '//----------------------------------------------------------------------------

    On Error Resume Next
    iRetVal = ZTIProcess
    ProcessResults iRetVal
    On Error Goto 0

    '//---------------------------------------------------------------------------
    '//
    '// Function: ZTIProcess()
    '//
    '// Input: None
    '//
    '// Return: Success - 0
    '// Failure - non-zero
    '//
    '// Purpose: Perform main ZTI processing
    '//
    '//---------------------------------------------------------------------------
    Function ZTIProcess()

         iRetVal = Success

         ZTIProcess = iRetval

         '!!!!!!!!!!!   INSERT YOUR CODE HERE   !!!!!!!!!!!!
         strComputer = "."
         Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
         Set colItems = objWMIService.ExecQuery( _
             "SELECT * FROM Win32_DiskDrive Where Index = '0'",,48)
         For Each objItem in colItems
             env("GetDrive0Size")=objItem.Size
         Next

    End Function

    </script>
    </job>

     

    Monday, November 22, 2010 5:12 PM

Answers

  • How about:

    <job id="ZTI_DiskPartBySize">
    	<script language="VBScript" src="ZTIUtility.vbs"/>
    	<script language="VBScript">
    
    Option Explicit
    
    Const HARD_DISK_SIZE_THRESHOLD_GB = 100
    
    If objWMI.ExecQuery("SELECT * FROM Win32_DiskDrive where Index = '0'").Count > 0 then
    	oLogging.CreateEntry "Found Disk 0", LogTypeInfo
    	
    	If objWMI.ExecQuery("SELECT * FROM Win32_DiskDrive where Index = '0' and Size > '" & ( HARD_DISK_SIZE_THRESHOLD_GB * 1024 * 1024 * 1024 ) & "'").Count > 0 then
    		oLogging.CreateEntry "Disk 0 is Larger than " & HARD_DISK_SIZE_THRESHOLD_GB & " GB", LogTypeInfo
    		oEnvironment.Item("OSDPARTITIONS0SIZE") = 60 * 1024 ' 60 GB
    
    	Else
    		oLogging.CreateEntry "Disk 0 is Less than or equal to " & HARD_DISK_SIZE_THRESHOLD_GB & " GB", LogTypeInfo
    		oEnvironment.Item("OSDPARTITIONS0SIZE") = 30 * 1024 ' 30 GB
    
    	End if
    
    end if
    
    	</script>
    </job>
    

    Keith Garner (KeithGa.com) - Deployment Consultant - http://deployment.XtremeConsulting.com
    • Proposed as answer by Chris NackersMVP, Moderator Tuesday, November 23, 2010 5:13 AM
    • Marked as answer by edelator Tuesday, November 23, 2010 8:51 PM
    • Unmarked as answer by edelator Tuesday, November 23, 2010 8:52 PM
    • Marked as answer by edelator Tuesday, November 23, 2010 8:53 PM
    Monday, November 22, 2010 9:10 PM