forked from vexx32/PSKoans
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAboutGetMember.Koans.ps1
132 lines (99 loc) · 4.52 KB
/
AboutGetMember.Koans.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using module PSKoans
[Koan(Position = 106)]
param()
<#
Get-Member
Following on from our last Koan about cmdlet verbs, lets cover the nouns.
As previously stated, the noun portion indicates the target of a given command.
If you use the "Get-Member" cmdlet on any object you'll see its type name, or data type.
For example:
PS C:\Users\Administrator\Documents\GitHub\Dev\PSKoans> Get-Process | Get-Member
TypeName: System.Diagnostics.Process
Name MemberType Definition
---- ---------- ----------
Handles AliasProperty Handles = Handlecount
Name AliasProperty Name = ProcessName
NPM AliasProperty NPM = NonpagedSystemMemorySize64
PM AliasProperty PM = PagedMemorySize64
SI AliasProperty SI = SessionId
VM AliasProperty VM = VirtualMemorySize64
WS AliasProperty WS = WorkingSet64
You'll also see properties and methods. Together with the TypeName, this tells us everything
we need to know in order to access the object's data and any actions it can perform.
Accessing a property or method is done via dot notation, which boils down to:
$Object.Property
$Object.Method()
We'll cover why we have to use parentheses with method calls later.
#>
Describe "Get Member" {
<#
Use Get-Member to identify properties or methods of some common objects!
Make sure you use a different cmdlet each time, we'll be checking :)
#>
It 'allows us to explore properties on an object' {
# Get some properties!
<# EXAMPLE
$Cmdlet1 = 'Get-Process'
$PropertyName = 'Threads'
$Reason = $BecauseString -f $PropertyName, $cmdlet1
& (Get-Command -Name $Cmdlet1) |
Get-Member -MemberType Property -Name $PropertyName |
Should -Not -BeNullOrEmpty -Because $Reason
#>
$BecauseString = "property '{0}' should be present in output from {1}"
$Cmdlet1 = '____'
$PropertyName = '____'
$Reason = $BecauseString -f $PropertyName, $cmdlet1
& (Get-Command -Name $Cmdlet1) |
Get-Member -MemberType Property -Name $PropertyName |
Should -Not -BeNullOrEmpty -Because $Reason
$Cmdlet2 = '____'
$PropertyName = '____'
$Reason = $BecauseString -f $PropertyName, $cmdlet2
& (Get-Command -Name $Cmdlet2) |
Get-Member -MemberType Property -Name $PropertyName |
Should -Not -BeNullOrEmpty -Because $Reason
$Cmdlet3 = '____'
$PropertyName = '____'
$Reason = $BecauseString -f $PropertyName, $cmdlet3
& (Get-Command -Name $Cmdlet3) |
Get-Member -MemberType Property -Name $PropertyName |
Should -Not -BeNullOrEmpty -Because $Reason
$cmdlet1, $cmdlet2, $cmdlet3 |
Get-Unique |
Should -HaveCount 3 -Because "three unique cmdlets should be supplied"
}
It 'allows us to explore methods on an object' {
# Get some methods!
<# EXAMPLE
$Cmdlet1 = 'Get-Process'
$MethodName = 'Close'
$Reason = $BecauseString -f $MethodName, $cmdlet1
& (Get-Command -Name $Cmdlet1) |
Get-Member -MemberType Property -Name $MethodName |
Should -Not -BeNullOrEmpty -Because $Reason
#>
$BecauseString = "method '{0}' should be present in output from {1}"
$Cmdlet1 = '____'
$MethodName = '____'
$Reason = $BecauseString -f $MethodName, $cmdlet1
& (Get-Command -Name $Cmdlet1) |
Get-Member -MemberType Method -Name $MethodName |
Should -Not -BeNullOrEmpty -Because $Reason
$Cmdlet2 = '____'
$MethodName = '____'
$Reason = $BecauseString -f $MethodName, $cmdlet2
& (Get-Command -Name $Cmdlet2) |
Get-Member -MemberType Method -Name $MethodName |
Should -Not -BeNullOrEmpty -Because $Reason
$Cmdlet3 = '____'
$MethodName = '____'
$Reason = $BecauseString -f $MethodName, $cmdlet3
& (Get-Command -Name $Cmdlet3) |
Get-Member -MemberType Method -Name $MethodName |
Should -Not -BeNullOrEmpty -Because $Reason
$cmdlet1, $cmdlet2, $cmdlet3 |
Get-Unique |
Should -HaveCount 3 -Because "three unique cmdlets should be supplied"
}
}