PoshCode Archive  Artifact [662a34a420]

Artifact 662a34a420bac2a2b57ffdccda57508417990dded8de18c3c316cd5a944f9d8a:

  • File PowerShell-script-for-shrinking-a-.ps1 — part of check-in [ca5c8ef67b] at 2018-06-10 12:56:34 on branch trunk — PowerShell script for shrinking a partition, works with Vista and Server 2008. (user: unknown size: 1065)

# encoding: ascii
# api: powershell
# title: 
# description: PowerShell script for shrinking a partition, works with Vista and Server 2008.
# version: 0.30
# license: CC0
# x-poshcode-id: 1163
# x-archived: 2009-06-27T19:37:17
#
#
$DriveLetter = "D:"
$MaxShrink = 0.30	# 0.30 equals 30%
$MinShrink = 0.20	# 0.20 equals 20%
$FileLocation = $env:Temp
$FileName4DiskPart = "Shrink.txt"

$DiskDrive = GWMI -CL Win32_LogicalDisk | Where {$_.DeviceId -Eq "$DriveLetter"}
$DriveSize = ($DiskDrive.Size /1GB)
$DriveSize = [int]$DriveSize

$DesiredShrink = [int]($DriveSize * $MaxShrink)
$MinimumShrink = [int]($DriveSize * $MinShrink)

#Write-Host DiskSize $DriveSize GB
#Write-Host DesiredShrink $DesiredShrink GB
#Write-Host MinimumShrink $MinimumShrink GB

Write "Select volume $DriveLetter" |Out-file $FileLocation\$FileName4DiskPart -encoding ASCII
Write "shrink desired=$DesiredShrink minimum=$MinimumShrink" |Out-file $FileLocation\$FileName4DiskPart -append -encoding ASCII

&cmd " /c diskpart" " /s $FileLocation\$FileName4DiskPart"