Skip to content

Instantly share code, notes, and snippets.

@btipling
Last active May 28, 2020 22:21
Show Gist options
  • Save btipling/72f97245d8222a815f592c3a6e76926c to your computer and use it in GitHub Desktop.
Save btipling/72f97245d8222a815f592c3a6e76926c to your computer and use it in GitHub Desktop.
Demonstrates how to use params, hash tables and convert them into objects and how to use ExpandProperty
param ([string] $name, [int] $value = 0)
$table = @{ Name = $name; Value = $value }
Write-Host "Your table is:"
Write-Output $table
Write-Host "`n"
Write-Host "It has this many items in it: " $table.Count
Write-Host "`n`n"
$asObj = [PSCustomObject]$table
Write-Host "Your Object is:"
Write-Output $asObj
Write-Host "members on the object are:`n"
$asObj | Get-Member | Select-Object -ExpandProperty Name
.\params_to_hash.ps1 -name "foo" -value 22
Your table is:
Name Value
---- -----
Name foo
Value 22
It has this many items in it: 2
Your Object is:
Name : foo
Value : 22
members on the object are:
Equals
GetHashCode
GetType
ToString
Name
Value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment