Last active
May 28, 2020 22:21
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.\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