PowerShell script runs a command to give me total bytes and total free bytes of my harddisk. I want to pick those two returned values as variables to do some calculations with but I'm not sure how to set a variable to a specific part of a command's output.
After looking through similar questions I cant apply the same logic to my situations. I have never used PowerShell before and not very familiar with Windows servers. Any recommended tutorials would be welcomed.
fsutil volume diskfree C:
Total # of free bytes : 1234567
Total # of bytes: 7654321
I would instead use PowerShell's Get-WmiObject
command and look at the Win32_LogicalDisk
class. You could do something like this:
$cDrive = Get-WmiObject -Class Win32_LogicalDisk -Filter "DeviceId='C:'"
That way you can get the free space and size attributes of the drive and manipulate them however you like. For example, this would show you the free space on the C drive in GB:
[Math]::Round( $cDrive.FreeSpace / 1GB)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments