I am new to powershell and have been struggling with a script for a week or two now.
I am trying to get powershell to obtain disk information on a machine, then analyse the percentage free and write and event to the eventlog if a certain condition is met.
So e.g
check the disks and if the capacity <400GB and percent free is <10% then write an event(i have the event log write bit working) to the event log. Our monitoring system picks up event logs and can perform actions based on them.
However, i also want the following:
If capacity is >400GB and percent free is <10 and free space is less than 40GB then write an event to the event log.
I am able to calculate the percentfree using the following:
{Name="percentFree";Expression={[int]($_.Freespace/$_.Size * 100)}}
however, i dont seem to be able to create a $percentfree object from the abpve calculation that i can then use in the IF statement.
Using the above, to test, i used
Write $percentfree
it simply writes the above expression.
Any help would be greatly appreciated. please be Gentle, i am new to this.
Thanks