@@ -12,129 +12,212 @@ $cred = New-Object PSCredential "Company\Administrator", $Secure
12
12
$all = @ ()
13
13
Describe DC1 {
14
14
15
- $dc = New-PSSession - VMName DC1 - Credential $cred - ErrorAction SilentlyContinue
16
- $all += $dc
17
- # set error action preference to suppress all error messsages
18
- Invoke-Command { $errorActionPreference = ' silentlyContinue' } - session $dc
15
+ Try {
16
+ $dc = New-PSSession - VMName DC1 - Credential $cred - ErrorAction Stop
17
+ $all += $dc
19
18
20
- It " [DC1] Should accept domain admin credential" {
21
- $dc.Count | Should Be 1
22
- }
19
+ # set error action preference to suppress all error messsages
20
+ Invoke-Command { $errorActionPreference = ' silentlyContinue' } - session $dc
23
21
24
- # test for features
25
- $feat = Invoke-Command { Get-WindowsFeature | Where-Object installed} - session $dc
26
- $needed = ' AD-Domain-Services' , ' DNS' , ' RSAT-AD-Tools' ,
27
- ' RSAT-AD-PowerShell'
28
- foreach ($item in $needed ) {
29
- It " [DC1] Should have feature $item installed" {
30
- $feat.Name -contains $item | Should Be " True"
22
+ It " [DC1] Should accept domain admin credential" {
23
+ $dc.Count | Should Be 1
31
24
}
32
- }
33
25
34
- It " [DC1] Should have an IP address of 192.168.3.10" {
35
- $i = Invoke-command - ScriptBlock { Get-NetIPAddress - interfacealias ' Ethernet' - AddressFamily IPv4} - Session $dc
36
- $i.ipv4Address | should be ' 192.168.3.10'
37
- }
26
+ # test for features
27
+ $feat = Invoke-Command { Get-WindowsFeature | Where-Object installed} - session $dc
28
+ $needed = ' AD-Domain-Services' , ' DNS' , ' RSAT-AD-Tools' ,
29
+ ' RSAT-AD-PowerShell'
30
+ foreach ($item in $needed ) {
31
+ It " [DC1] Should have feature $item installed" {
32
+ $feat.Name -contains $item | Should Be " True"
33
+ }
34
+ }
38
35
39
- It " [DC1] Should have a domain name of $domain " {
40
- $r = Invoke-command { Get-ADDomain - ErrorAction SilentlyContinue } - session $dc
41
- $r .name | should Be $domain
42
- }
36
+ It " [DC1] Should have an IP address of 192.168.3.10 " {
37
+ $i = Invoke-Command - ScriptBlock { Get-NetIPAddress - interfacealias ' Ethernet ' - AddressFamily IPv4 } - Session $dc
38
+ $i .ipv4Address | Should be ' 192.168.3.10 '
39
+ }
43
40
44
- $OUs = Invoke-command { Get-ADorganizationalUnit - filter * - ErrorAction SilentlyContinue} - session $dc
45
- $needed = ' IT' , ' Dev' , ' Marketing' , ' Sales' , ' Accounting' , ' JEA_Operators'
46
- foreach ($item in $needed ) {
47
- It " [DC1] Should have organizational unit $item " {
48
- $OUs.name -contains $item | Should Be " True"
41
+ It " [DC1] Should have a domain name of $domain " {
42
+ $r = Invoke-Command {
43
+ Try {
44
+ Get-ADDomain - ErrorAction Stop
45
+ }
46
+ Catch {
47
+ # ignore the error - Domain still spinning up
48
+ }
49
+ } - session $dc
50
+ $r.name | Should Be $domain
49
51
}
50
- }
51
- $groups = Invoke-Command { Get-ADGroup - filter * - ErrorAction SilentlyContinue} - session $DC
52
- $target = " IT" , " Sales" , " Marketing" , " Accounting" , " JEA Operators"
53
- foreach ($item in $target ) {
54
52
55
- It " [DC1] Should have a group called $item " {
56
- $groups.Name -contains $item | Should Be " True"
53
+ $OUs = Invoke-Command {
54
+ Try {
55
+ Get-ADOrganizationalUnit - filter * - ErrorAction Stop
56
+ }
57
+ Catch {
58
+ # ignore the error - Domain still spinning up
59
+ }
60
+ } - session $dc
61
+
62
+ $needed = ' IT' , ' Dev' , ' Marketing' , ' Sales' , ' Accounting' , ' JEA_Operators'
63
+ foreach ($item in $needed ) {
64
+ It " [DC1] Should have organizational unit $item " {
65
+ $OUs.name -contains $item | Should Be " True"
66
+ }
57
67
}
58
68
59
- }
69
+ $groups = Invoke-Command {
70
+ Try {
71
+ Get-ADGroup - filter * - ErrorAction Stop
72
+ }
73
+ Catch {
74
+ # ignore the error - Domain still spinning up
75
+ }
76
+ } - session $DC
77
+
78
+ $target = " IT" , " Sales" , " Marketing" , " Accounting" , " JEA Operators"
79
+ foreach ($item in $target ) {
80
+
81
+ It " [DC1] Should have a group called $item " {
82
+ $groups.Name -contains $item | Should Be " True"
83
+ }
84
+ }
60
85
61
- $users = Invoke-Command { Get-AdUser - filter * - ErrorAction SilentlyContinue} - session $dc
62
- It " [DC1] Should have at least 15 user accounts" {
63
- $users.count | should BeGreaterThan 15
64
- }
86
+ $users = Invoke-Command {
87
+ Try {
88
+ Get-ADUser - filter * - ErrorAction Stop
89
+ }
90
+ Catch {
91
+ # ignore the error - Domain still spinning up
92
+ }
93
+ } - session $dc
94
+
95
+ It " [DC1] Should have at least 15 user accounts" {
96
+ $users.count | Should BeGreaterThan 15
97
+ }
65
98
66
- $computer = Invoke-Command { Get-ADComputer - filter * - ErrorAction SilentlyContinue} - session $dc
67
- It " [DC1] Should have a computer account for Cli1" {
68
- $computer.name -contains " cli1" | Should Be " True"
69
- }
99
+ $computer = Invoke-Command {
100
+ Try {
101
+ Get-ADComputer - filter * - ErrorAction SilentlyContinue
102
+ }
103
+ Catch {
104
+ # ignore the error - Domain still spinning up
105
+ }
106
+ } - session $dc
107
+
108
+ It " [DC1] Should have a computer account for Cli1" {
109
+ $computer.name -contains " cli1" | Should Be " True"
110
+ }
70
111
71
- It " [DC1] Should have a computer account for Cli2" {
72
- $computer.name -contains " cli2" | Should Be " True"
112
+ It " [DC1] Should have a computer account for Cli2" {
113
+ $computer.name -contains " cli2" | Should Be " True"
114
+ }
115
+ It " [DC1] Should have a computer account for S1" {
116
+ $computer.name -contains " S1" | Should Be " True"
117
+ }
73
118
}
74
- It " [DC1] Should have a computer account for S1" {
75
- $computer.name -contains " S1" | Should Be " True"
119
+ Catch {
120
+ It " [DC1] Should allow a PSSession" {
121
+ $false | Should Be $True
122
+ }
76
123
}
77
-
78
124
} # DC
79
125
80
126
Describe S1 {
81
- $s1 = New-PSSession - VMName S1 - Credential $cred - ErrorAction SilentlyContinue
82
- $all += $s1
83
- It " [S1] Should accept domain admin credential" {
84
- $s1.Count | Should Be 1
85
- }
127
+ Try {
128
+
129
+ $s1 = New-PSSession - VMName S1 - Credential $cred - ErrorAction Stop
130
+ $all += $s1
86
131
87
- It " [S1] Should have an IP address of 192.168.3.50" {
88
- $i = Invoke-command - ScriptBlock { Get-NetIPAddress - interfacealias ' Ethernet' - AddressFamily IPv4} - Session $S1
89
- $i.ipv4Address | should be ' 192.168.3.50'
132
+ # set error action preference to suppress all error messsages
133
+ Invoke-Command { $errorActionPreference = ' silentlyContinue' } - session $s1
134
+
135
+ It " [S1] Should accept domain admin credential" {
136
+ $s1.Count | Should Be 1
137
+ }
138
+
139
+ It " [S1] Should have an IP address of 192.168.3.50" {
140
+ $i = Invoke-Command - ScriptBlock { Get-NetIPAddress - interfacealias ' Ethernet' - AddressFamily IPv4} - Session $S1
141
+ $i.ipv4Address | Should be ' 192.168.3.50'
142
+ }
143
+ $dns = Invoke-Command {Get-DnsClientServerAddress - InterfaceAlias ethernet - AddressFamily IPv4} - session $s1
144
+ It " [S1] Should have a DNS server configuration of 192.168.3.10" {
145
+ $dns.ServerAddresses -contains ' 192.168.3.10' | Should Be " True"
146
+ }
90
147
}
91
- $dns = Invoke-Command {Get-DnsClientServerAddress - InterfaceAlias ethernet - AddressFamily IPv4} - session $s1
92
- It " [S1] Should have a DNS server configuration of 192.168.3.10" {
93
- $dns.ServerAddresses -contains ' 192.168.3.10' | Should Be " True"
148
+ Catch {
149
+ It " [S1] Should allow a PSSession" {
150
+ $false | Should Be $True
151
+ }
94
152
}
95
-
96
153
} # S1
97
154
98
155
Describe Cli1 {
99
156
100
- $cl = New-PSSession - VMName cli1 - Credential $cred - ErrorAction SilentlyContinue
101
- $all += $cl
102
- It " [CLI] Should accept domain admin credential" {
103
- $cl = New-PSSession - VMName cli1 - Credential $cred - ErrorAction SilentlyContinue
104
- $cl.Count | Should Be 1
105
- }
157
+ Try {
106
158
107
- It " [CLI] Should have an IP address of 192.168.3.100" {
108
- $i = Invoke-command - ScriptBlock { Get-NetIPAddress - interfacealias ' Ethernet' - AddressFamily IPv4} - session $cl
109
- $i.ipv4Address | should be ' 192.168.3.100'
110
- }
159
+ $cl = New-PSSession - VMName cli1 - Credential $cred - ErrorAction Stop
160
+ $all += $cl
111
161
112
- $dns = Invoke-Command {Get-DnsClientServerAddress - InterfaceAlias ethernet - AddressFamily IPv4} - session $cl
113
- It " [CLI] Should have a DNS server configuration of 192.168.3.10" {
114
- $dns.ServerAddresses -contains ' 192.168.3.10' | Should Be " True"
115
- }
162
+ # set error action preference to suppress all error messsages
163
+ Invoke-Command { $errorActionPreference = ' silentlyContinue' } - session $cl
116
164
165
+ It " [CLI1]] Should accept domain admin credential" {
166
+ $cl.Count | Should Be 1
167
+ }
168
+
169
+ It " [CLI1]] Should have an IP address of 192.168.3.100" {
170
+ $i = Invoke-Command - ScriptBlock { Get-NetIPAddress - interfacealias ' Ethernet' - AddressFamily IPv4} - session $cl
171
+ $i.ipv4Address | Should be ' 192.168.3.100'
172
+ }
173
+
174
+ It " [CLI1]] Should have RSAT installed" {
175
+ $pkg = Invoke-Command {Get-WindowsCapability - online - name * rsat* } - session $cl
176
+
177
+ # write-host ($pkg | Select-object Name,Displayname,State | format-list | Out-String) -ForegroundColor cyan
178
+ $pkg | Where-Object { $_.state -ne " installed" } | Should be $Null
179
+ }
180
+
181
+ $dns = Invoke-Command {Get-DnsClientServerAddress - InterfaceAlias ethernet - AddressFamily IPv4} - session $cl
182
+ It " [CLI1]] Should have a DNS server configuration of 192.168.3.10" {
183
+ $dns.ServerAddresses -contains ' 192.168.3.10' | Should Be " True"
184
+ }
185
+ }
186
+ Catch {
187
+ It " [CLI1] Should allow a PSSession" {
188
+ $false | Should Be $True
189
+ }
190
+ }
117
191
} # cli1
118
192
119
193
Describe Cli2 {
120
194
121
- $cl2 = New-PSSession - VMName cli2 - Credential $cred - ErrorAction SilentlyContinue
122
- $all += $cl2
123
- It " [CLI2] Should accept domain admin credential" {
124
- $cl2 = New-PSSession - VMName cli1 - Credential $cred - ErrorAction SilentlyContinue
125
- $cl2.Count | Should Be 1
126
- }
195
+ Try {
127
196
128
- It " [CLI2] Should have an IP address of 192.168.3.101" {
129
- $i = Invoke-command - ScriptBlock { Get-NetIPAddress - interfacealias ' Ethernet' - AddressFamily IPv4} - session $cl2
130
- $i.ipv4Address | should be ' 192.168.3.101'
131
- }
197
+ $cl2 = New-PSSession - VMName cli2 - Credential $cred - ErrorAction Stop
198
+ $all += $cl2
132
199
133
- $dns = Invoke-Command {Get-DnsClientServerAddress - InterfaceAlias ethernet - AddressFamily IPv4} - session $cl2
134
- It " [CLI2] Should have a DNS server configuration of 192.168.3.101" {
135
- $dns.ServerAddresses -contains ' 192.168.3.10' | Should Be " True"
136
- }
200
+ # set error action preference to suppress all error messsages
201
+ Invoke-Command { $errorActionPreference = ' silentlyContinue' } - session $cl2
202
+ It " [CLI2] Should accept domain admin credential" {
203
+ $cl2.Count | Should Be 1
204
+ }
137
205
206
+ It " [CLI2] Should have an IP address of 192.168.3.101" {
207
+ $i = Invoke-Command - ScriptBlock { Get-NetIPAddress - interfacealias ' Ethernet' - AddressFamily IPv4} - session $cl2
208
+ $i.ipv4Address | Should be ' 192.168.3.101'
209
+ }
210
+
211
+ $dns = Invoke-Command {Get-DnsClientServerAddress - InterfaceAlias ethernet - AddressFamily IPv4} - session $cl2
212
+ It " [CLI2] Should have a DNS server configuration of 192.168.3.101" {
213
+ $dns.ServerAddresses -contains ' 192.168.3.10' | Should Be " True"
214
+ }
215
+ }
216
+ Catch {
217
+ It " [CLI2] Should allow a PSSession" {
218
+ $false | Should Be $True
219
+ }
220
+ }
138
221
} # cli2
139
222
140
- $all | Remove-PSSession
223
+ $all | Remove-PSSession
0 commit comments