0

im trying to create a small status script, checking ram, cpu og drives. Right now im doing a foreach on get volume. Is it possible to create a variable in the end of my foreach called driveletter + output

So the variable could look like this $Coutput or $Doutput, depending on the driveletter?

$ByteDivider = 1073741824

$Disks = Get-Volume | Select -ExpandProperty Driveletter

foreach($disk in $disks){

$DrivLetter = Get-Volume -DriveLetter $disk | Select-Object -ExpandProperty Driveletter

$Size = Get-Volume -DriveLetter $disk | Select-Object -ExpandProperty Size
$SizeInGB = $Size/$ByteDivider
$SizeRounded = '{0:f0}' -f $SizeInGB


$FreeSpace = Get-Volume -DriveLetter $disk | Select-Object -ExpandProperty SizeRemaining
$FreeSpaceInGB = $FreeSpace/$ByteDivider

$UsedSpace = $SizeInGB-$FreeSpaceInGB
$UsedSpaceRounded = '{0:f0}' -f $UsedSpace

Write-Host ("Drive: $DrivLetter Used:$UsedSpaceRounded/$SizeRounded")

}
1
  • What is output to you? So you want variables that read $Cused:312/121? Commented Apr 28, 2022 at 16:18

1 Answer 1

1

I figured it out

New-Variable -Name $disk+Output -Value $data -Force
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.