Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Stop Powershell Script if disk size is less than X

I wonder if you could help me out guys.
I need to stop a powershell script if the disk size of partition E is less than 10GB, and to continue if it´s more than 10GB.

So far i managed to get my disk size listed with this.

Get-WmiObject -Class win32_logicaldisk | Format-Table DeviceId,@{n="FreeSpace";e={[math]::Round($_.FreeSpace/1GB,2)}}

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

And i get this result:

DeviceId Freespace
A 0
C 77.9
D 0
E 34.05

So, i want to stop the powershell script if E unit has less than 10GB.
How can i do it?

Thanks in advance

>Solution :

If you want to put the Freespace of E in a variable you can do this :

$VarSpace = $(Get-WmiObject -Class win32_logicaldisk | Where-Object -Property Name -eq C:).FreeSpace/1GB

then you can do a simple if for check :

if ($VarSpace -le 10){ <Something for stopping you script like exit> }
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading