forked from RyanC92/Powershell-Repository
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHowTo-AddSubvariables.ps1
35 lines (26 loc) · 1.11 KB
/
HowTo-AddSubvariables.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#Howto - Add Subvariables - Any of these would work
# properties, via add-member (also supports methods, scripts, etc)
$foo = new-object psobject
$foo | add-member noteproperty name1 value1
$foo | add-member noteproperty name2 value2
# properties, via select-object or format-table
$foo = new-object psobject |
select @{Name="name1"; Expression={"value1"}},
@{Name="name2"; Expression={"value2"}}
# hashtable, native syntax
$foo = @{name1="value1"
name2="value2"}
# properties, via hashtable (v2.0 only)
$foo = new-object psobject -Property @{
name1="value1"
name2="value2"
}
# properties, via dynamic compilation (v2.0 only - also supports methods)
add-type @'
public class FooType
{
public string name1 = "value1";
public string name2 = "value2";
}
'@
$foo = new-object FooType