MDT 2013 TS: How to shrink the Windows partition by a specific size instead of a percentage?

Discussion in 'Scripting' started by Arthur Durand, Jul 22, 2021.

  1. Arthur Durand

    Arthur Durand MDL Novice

    Jul 29, 2015
    17
    14
    0
    MDT 2013 task sequence: How to shrink the Windows partition by a specific size instead of a percentage

    I need to figure out a way to shrink the WIndows partition by a specific size instead of a percentage in the MDT 2013 task sequence so that I can create a recovery partition with a specific size!

    I was thinking of letting the task sequence create the System, MSR and Windows partition and using a custom script to shrink and create the recovery partition by and to a specific size! However, I've already added a VBS script to allow me to select the default disk to use during the Format and Create partitions in the task sequence! The VBS script basicallly just changes the TargetDisk value based on the Disk number I select! I have no experience in writing or editing VBS and would like some adivce! What would be the easiest way to achieve the specific size Recovery partition, still allowing me to select TargetDisk during deployment?

    Any advice would be highly appreciated!
     
  2. Arthur Durand

    Arthur Durand MDL Novice

    Jul 29, 2015
    17
    14
    0
    I ended up deleteing the Recovery partition from the MDT Task Seuence, setting the Windows partition to use 100% of the remaining disk space! I then added powershell and diskpart scripts after the partition and format task sequence to resize the Windows partition by 1GB and to create the Recovery partition!

    Sample of my powershell script (CreateRecoveryPartition-UEFI.ps1):

    Code:
    $OSDiskNumber = Get-Volume | Where {$_.FileSystemLabel -eq "Windows"} | Get-Partition | Get-Disk | Select Number
    
    If (0 -eq ($OSDiskNumber.Number))
    {
        diskpart /s $env:ScriptRoot\CreateRecoveryPartition-UEFI.txt
    }
    If (1 -eq ($OSDiskNumber.Number))
    {
        diskpart /s $env:ScriptRoot\CreateRecoveryPartition-D1-UEFI.txt
    }
    
    CreateRecoveryPartition-UEFI.txt:

    Code:
    rem == CreateRecoveryPartitions-UEFI.txt ==
    select disk 0
    select partition 3
    rem ==    b. Create space for the recovery tools 
    shrink minimum=1000
    rem       ** NOTE: Update this size to match the
    rem                size of the recovery tools
    rem                (winre.wim)                 **
    rem === Create Recovery partition ======================
    create partition primary
    format quick fs=ntfs label="Recovery"
    set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"
    gpt attributes=0x8000000000000001
    list volume
    exit
    
    CreateRecoveryPartition-D1-UEFI:

    Code:
    rem == CreateRecoveryPartitions-UEFI.txt ==
    select disk 1
    select partition 3
    rem ==    b. Create space for the recovery tools 
    shrink minimum=1000
    rem       ** NOTE: Update this size to match the
    rem                size of the recovery tools
    rem                (winre.wim)                 **
    rem === Create Recovery partition ======================
    create partition primary
    format quick fs=ntfs label="Recovery"
    set id="de94bba4-06d1-4d40-a16a-bfd50179d6ac"
    gpt attributes=0x8000000000000001
    list volume
    exit
    
    My scripts makes provision for cases where there's a hard drive and SSD isntalled and the SSD is listed as Disk 1. I also run a custom script before the Partition and Format task sequense to detect the SSD and to set that as the Target OS Disk!