Link to home
Start Free TrialLog in
Avatar of Maniman man
Maniman man

asked on

Shrink automation

Hi there, am new to powershell and would need some help to execute conditions with powershell.
The idea is to shrink the operating system partition in powershell.

Example for disk E:  400GB total, we would like to resize to 60GB (shrink 340GB)
C:\> Resize-Partition -DiskNumber 2 -PartitionNumber 1 -Size (60GB)

However sometimes I get an error while using the above script, not beeing able to shrink the desired size, therefore I have to amend the shrink to 320GB or 310GB until the operating system partition gets resized without error.

I would like to have a condition, that would automatically change the shrink size when the error occur, in order to not have to change my script each time I get an error.

Can anyone help?
Thank you
Avatar of bbao
bbao
Flag of Australia image

you can use PS to first get disk capacity and free space then workout the space to be shrunk. something like below.

http://stackoverflow.com/questions/12159341/how-to-get-disk-capacity-and-free-space-of-remote-computer
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial