I am hoping this is the correct forum for this question. I am working on a PS script to monitor disk space on my SQL servers. I am familiar with PS but am having an issue and I think it is related to the WMI cmdlet which I have not used often. I am trying to get the size of the disk and pass it into a foreach loop in order to determine what the next action will be depending on disk size.
This is the simplified command I am using. I am trying to save the results to a variable to pass in a foreach loop but the results are outputting it some sort of string table with a column header that i can not pass in my loop correctly. Any suggestions would be appreciated. Thanks You!
If you are looking at making this into reusable code change this around to work on one server, or multiple.
If you want to keep with your same code you need to specify the property for "$size" as "$size.size". You can get around doing this by changing your variable command to this:
This will expand the size property into a string so your "$AllDisks" variable will just hold a string list of all the sizes.
You can also pass in an array of servers to the Get-WmiObject cmdlet, so doing something like