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.
- Browse to Configuration > Service Request Configuration > Form Designer tab.
- Click Add.
- Enter Disk Change Request as the Form Name and Display Name.
- Select Change Request Form as the Form Type.
- Do not select a Completion Workflow, as you will associate the workflow with this form when you create it it in the next section.
- Publish globally or to specific organizations, groups and/or users as suits your needs, and click OK.
- 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).
- 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.
- Browse to Configuration > Service Request Configuration > Completion Workflow tab. Click Add.
- Enter Resize Disk as the Name. Choose to Apply this workflow: after a Change Request is fulfilled. Click Next.
- Click Add > Guest OS > Create File. Configure the step as follows:
- Step Name: Create File
- Step Execution: Execute when conditions are met: '#{target.guestOS}' -contains "2008"
- When Step Fails: Mark workflow step as failed: do not proceed.
- Credentials: Choose an account able to create files on the target. An administrator is recommended.
- 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 $_ } }
- Enter the Destination c:\diskresize.ps1
- Check Overwrite.
- Click Add > Guest OS > Run Program.
- Enter the Step Name Run Program.
- Set Step Execution to Execute when conditions are met and click Edit. Enter the following condition and click OK:
'#{target.guestOS}' -contains "2008"
- Set When Step Fails to Mark workflow step as failed: do not proceed.
- Set Timeout to 300.
- Configure the Credentials to run the step on the target VM’s guest OS. An administrator (Domain or Local) is recommended.
- Set Program Output to Capture program output as comment.
- Set When Step Fails to Mark workflow step as failed: do not proceed.
- Set Command Line to:
powershell.exe c:\resizedisk.ps1
- Click Add > Guest OS > Create File 2012.
- Enter the Step Name Create File 2012.
- Set Step Execution to Execute when conditions are met and click Edit. Enter the following condition and click OK:
'#{target.guestOS}' -contains "2012"
- Set When Step Fails to Mark workflow step as failed: do not proceed.
- Configure the Credentials to run the step on the target VM’s guest OS. A local administrator is recommended.
- 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}
- Enter the Destination c:\diskresize.ps1
- Check Overwrite.
- Click Add > Guest OS > Run Program.
- Enter the Step Name Run Program 2012.
- Set Step Execution to Execute when conditions are met and click Edit. Enter the following condition and click OK:
'#{target.guestOS}' -contains "2012"
- Set When Step Fails to Mark workflow step as failed: do not proceed.
- Set Timeout to 300.
- Configure the Credentials to run the step on the target VM’s guest OS. A local Administrator is recommended.
- Set Program Output to Capture program output as comment.
- Set When Step Fails to Mark workflow step as failed: do not proceed.
- Set Command Line to:
powershell.exe -ExecutionPolicy Bypass c:\diskresize.ps1 -Verb runAs
- Click Next.
- Select Apply this workflow to the selected forms: and choose the Disk Change Request Form. Click Next.
- Click Finish.