This article describes a solution you can use to automatically expand an existing partition to use all of the space on a disk that’s been resized by a change request. To do so, you will create a Disk Change Request form, and associate the form with a Completion Workflow that contains the steps to resize for both Windows 2008 and Windows 2012.


Disk Change Request Form


Create a form for disk change requests following the procedure below.

  1. Browse to Configuration > Service Request Configuration > Form Designer tab.
  2. Click Add.
  3. Enter Disk Change Request as the Form Name and Display Name.
  4. Select Change Request Form as the Form Type.
  5. Do not select a Completion Workflow, as you will associate the workflow with this form when you create it it in the next section.

  6. Publish globally or to specific organizations, groups and/or users as suits your needs, and click OK.
  7. Edit the content to include the header Disk Change Request and appropriate Storage options to suit your needs (must include Change Existing Disks as the allowed Actions).

  8. Click Save.


 

Completion Workflow


Next, follow the procedure below to create a completion workflow to run for requests originating with the form you created in the previous section.

  1. Browse to Configuration > Service Request Configuration > Completion Workflow tab. Click Add.
  2. Enter Resize Disk as the Name. Choose to Apply this workflow: after a Change Request is fulfilled. Click Next.
  3. Click Add > Guest OS > Create File.
    1. Enter the Step Name Create File.
    2. Set Step Execution to Execute when conditions are met and click Edit. Enter the following condition and click OK: 
      #{target.guestOS} -contains "2008"

       

    3. Set When Step Fails to Mark workflow step as failed: do not proceed.
    4. Configure the Credentials to run the step on the target VM’s guest OS. An administrator (Domain or Local) is recommended.
    5. Enter the following Contents: 
      'rescan' | diskpart
      start-sleep -Seconds 10
      function List-Disks {
        'list disk' | diskpart |
          ? { $_ -match 'disk (\d+)\s+online\s+\d+ .?b\s+\d+ [gm]b' } |
          % { $matches[1] }
      }
      function List-Partitions($disk) {
        "select disk $disk", "list partition" | diskpart |
          ? { $_ -match 'partition (\d+)' } |
          % { $matches[1] }
      }
      function Extend-Partition($disk, $part) {
        "select disk $disk","select partition $part","extend" | diskpart | Out-Null
      }
      List-Disks | % {
        $disk = $_
        List-Partitions $disk | % {
          Extend-Partition $disk $_
        }
      }

       

    6. Enter the Destination c:\diskresize.ps1
    7. Check Overwrite.
  4. Click Add > Guest OS > Run Program.
    1. Enter the Step Name Run Program.
    2. Set Step Execution to Execute when conditions are met and click Edit. Enter the following condition and click OK: 
      #{target.guestOS} -contains "2008"

       

    3. Set When Step Fails to Mark workflow step as failed: do not proceed.
    4. Set Timeout to 300.
    5. Configure the Credentials to run the step on the target VM’s guest OS. An administrator (Domain or Local) is recommended.
    6. Set Program Output to Capture program output as comment.
    7. Set When Step Fails to Mark workflow step as failed: do not proceed.
    8. Set Command Line to: 
      powershell.exe c:\resizedisk.ps1

       

  5. Click Add > Guest OS > Create File 2012.
    1. Enter the Step Name Create File 2012.
    2. Set Step Execution to Execute when conditions are met and click Edit. Enter the following condition and click OK: 
      #{target.guestOS} -contains "2012"

       

    3. Set When Step Fails to Mark workflow step as failed: do not proceed.
    4. Configure the Credentials to run the step on the target VM’s guest OS. A local administrator is recommended.
    5. Enter the following Contents: 
      Update-HostStorageCache
      Start-Sleep -Seconds 20
      $GetPartition = Get-Partition
      $driveletters = $GetPartition.DriveLetter   
      $driveletters = $driveletters | ? {$_}   
        Write-Host "Array size AFTER removing empty lines : $($driveletters.Count)"
      Foreach ($letter in $driveletters){
        Write-Host "DriveLetter ="$letter
        $GetInfo = Get-partition -DriveLetter $letter
        $DiskNum = $GetInfo.DiskNumber
        $partitionnum = $GetInfo.PartitionNumber
        $Max = Get-PartitionSupportedSize -DiskNumber $DiskNum -PartitionNumber $partitionnum
        $sizemax = $max.SizeMax
        $exception = Resize-Partition -DiskNumber $DiskNum -PartitionNumber $partitionnum -Size $SizeMax}

       

    6. Enter the Destination c:\diskresize.ps1
    7. Check Overwrite.
  6. Click Add > Guest OS > Run Program.
    1. Enter the Step Name Run Program 2012.
    2. Set Step Execution to Execute when conditions are met and click Edit. Enter the following condition and click OK: 
      #{target.guestOS} -contains "2012"

       

    3. Set When Step Fails to Mark workflow step as failed: do not proceed.
    4. Set Timeout to 300.
    5. Configure the Credentials to run the step on the target VM’s guest OS. A local Administrator is recommended.
    6. Set Program Output to Capture program output as comment.
    7. Set When Step Fails to Mark workflow step as failed: do not proceed.
    8. Set Command Line to: 
      powershell.exe -ExecutionPolicy Bypass c:\diskresize.ps1 -Verb runAs

       

  7. Click Next.
  8. Select Apply this workflow to the selected forms: and choose the Disk Change Request Form. Click Next.

  9. Click Finish.