Disclaimer
This is my personal blog. The opinions and views I express are my own. The information I provide is on an as-is basis. I make no representations as to accuracy, completeness, currentness, suitability, or validity of any information on this blog and will not be liable for any errors, omissions, or delays in this information or any losses, injuries or damages arising from its use.

PowerShell Hash Tables and Calculated Properties Basics

This video is a basic overview of how to use hash tables and calculated properties to make PowerShell data more usable.

<#
.SYNOPSIS
    How to use Hash Table and Calculated Properties

.DESCRIPTION
    A basic walk through of how to use Hash Tables and Calculated properties

.PARAMETER <Parameter_Name>
    None

.INPUTS
    None

.OUTPUTS
    None

.NOTES
    Author:         David Hall
    Creation Date:  04/24/2017
      
.EXAMPLE
  None 

.SCRIPT
    - Can contain 1 or multiple items in key / value pairs
        - Label / L / name / n / expression / e

#>
# Example No Hash table or Calculated Properties
Get-WmiObject -Class WIN32_volume -ComputerName localhost -Filter 'drivetype = 3' | 
    Select-Object -Property PScomputerName, 
                            DriveLetter, 
                            Label, 
                            FreeSpace

# Example using a Hash table
Get-WmiObject -Class WIN32_volume -ComputerName localhost -Filter 'drivetype = 3' | 
    Select-Object -Property PScomputerName, 
                            DriveLetter, 
                            Label, 
                            @{
                                LABEL='FreeSpace(GB)';
                                EXPRESSION={($_.freespace/1GB)}
                             }
# Better but not exactly what we're looking for.

Get-WmiObject -Class WIN32_volume -ComputerName localhost -Filter 'drivetype = 3' | 
    Select-Object -Property PScomputerName, 
                            DriveLetter, 
                            Label, 
                            @{
                                LABEL='FreeSpace(GB)';
                                EXPRESSION={'{0:N2}' -f ($_.freespace/1GB)}
                             }

 

2 Comments

    • David Hall | | Reply

      Good Information, Thanks Kevin

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.