I want to set a variable for unit sizes like GB or TB to be used in calculating disk capacity. This is my working example:
$SourceDriveLetter = "C"
$SourceDrive = Get-Volume -DriveLetter $SourceDriveLetter
$SourceCapacity = [math]::Round(($SourceDrive.Size/1TB),2)
$SourceCapacity
0.42
I want to set something like this so I can easily change from TB to GB. I use the $Unit elsewhere in an email report.
$SourceDriveLetter = "C"
$Unit = "TB"
$UnitCalc = 1 * [int]$Unit
$SourceDrive = Get-Volume -DriveLetter $SourceDriveLetter
$SourceCapacity = [math]::Round(($SourceDrive.Size/$UnitCalc),2)
$SourceCapacity
I know $Unit is a string to begin with, no exactly sure how to represent it as a literal with the math calculation in $UnitCalc. Any help would greatly be appreciated.