VMware Cloud Community
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Issue with declaring variable

Hi,

I am trying to shrink the windows drives and I have issues with variable

If I use the below command, it works

Resize-Partition -DriveLetter E -Size ((Get-Partition -DriveLetter E).Size - 10GB)

But I want to use a variable in defining the size using variable, how can I do it ?

Please help

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can do like this

$shrinkSizeGB = Read-Host "Enter Disk Size To Be Reduced In GB"

$shrinkSize = $shrinkSizeGB * 1GB

$newSize = (Get-Partition -DriveLetter E).Size - $shrinkSize

Resize-Partition -DriveLetter E -Size $newSize


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

You mean like this?

$shrinkSize = 10GB

$newSize = (Get-Partition -DriveLetter E).Size - $shrinkSize

Resize-Partition -DriveLetter E -Size $newSize


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

Hi LucD,

Thanks for your reply.

For $shrinkSize = 10GB

How can I enter only number, I am GB to populated automatically from the input


$shrinkSize = Read-Host "Enter Disk Size To Be Reduced In GB"

Please help!!!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can do like this

$shrinkSizeGB = Read-Host "Enter Disk Size To Be Reduced In GB"

$shrinkSize = $shrinkSizeGB * 1GB

$newSize = (Get-Partition -DriveLetter E).Size - $shrinkSize

Resize-Partition -DriveLetter E -Size $newSize


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ganapa2000
Hot Shot
Hot Shot
Jump to solution

That Worked.....Thank you very much Smiley Happy

0 Kudos