21 January 2013

A couple of days after I made my last post I realized that, for that specific purpose, I could have just dynamically created hashtables as the values of each array.  It would look like this pseudo-code:

$array = @()
$array += @{
   DriveLetter = $object.DriveLetter
   TotalSpace = $object.Size
   FreeSpace = $object.FreeSpace
}

Just remember to first declare the array variable as an array or you’ll get errors.  Then as I enumerate through each returned object it’s as simple as:

ForEach ($disk in $array) {
  write-host "Drive: $disk.DriveLetter has $disk.FreeSpace free space out of a total of $disk.TotalSpace"
}

Or whatever I wanted to do with it.  Now that I think about it, creating a specific name for each variable isn’t necessary and I can’t think of any scenarios where I really need to do that.  I guess it could happen, though, so I’ll leave my previous post up.


There are no comments.



You must be logged in to post a comment.

Links

RSS 2.0 Feed

Support

Brave Rewards
This site supports Brave Rewards. Please consider tipping or adding it to your monthly contributions if you find anything helpful!

For other ways: Support

Support this blog! If you have found it helpfu you can send me crypto. Any amount is appreciated!
ETH: 0xBEaF72807Cb5f4a8CCE23A5E7949041f62e8F8f0 | BTC: 3HTK5VJWr3vnftxbrcWAszLkRTrx9s5KzZ | SHIB: 0xdb209f96dD1BdcC12f03FdDfFAD0602276fb29BE
Brave Users you can send me BAT using the browser.