@@ -10,64 +10,61 @@ function Get-Config {
1010
1111function Verify-LGPO
1212{
13- echo " Running this function Verify-LGPO"
14- echo " Verifying that expected policies have been applied"
13+ Write-Host " Running this function Verify-LGPO"
14+ Write-Host " Verifying that expected policies have been applied"
1515
1616 lgpo / b $PSScriptRoot
17- $LgpoDir = " $PSScriptRoot \" + (Get-ChildItem $PSScriptRoot - Directory | ? { $_.Name -match " {*}" } | select - First 1 ).Name
17+ $LgpoDir = " $PSScriptRoot \" + (Get-ChildItem $PSScriptRoot - Directory | Where-Object { $_.Name -match " {*}" } | Select-Object - First 1 ).Name
1818
1919 $OutputDir = " $PSScriptRoot \lgpo_test"
20- mkdir $OutputDir
20+ New-Item - ItemType Directory - Path $OutputDir - Force
2121
2222 lgpo / parse / m " $LgpoDir \DomainSysvol\GPO\Machine\registry.pol" > " $OutputDir \machine_registry.unedited.txt"
23- Get-Content " $OutputDir \machine_registry.unedited.txt" | select - Skip 3 > " $OutputDir \machine_registry.txt"
23+ Get-Content " $OutputDir \machine_registry.unedited.txt" | Select-Object - Skip 3 > " $OutputDir \machine_registry.txt"
2424
2525 lgpo / parse / u " $LgpoDir \DomainSysvol\GPO\User\registry.pol" > " $OutputDir \user_registry.unedited.txt"
26- Get-Content " $OutputDir \user_registry.unedited.txt" | select - Skip 3 > " $OutputDir \user_registry.txt"
26+ Get-Content " $OutputDir \user_registry.unedited.txt" | Select-Object - Skip 3 > " $OutputDir \user_registry.txt"
2727
28- copy " $LgpoDir \DomainSysvol\GPO\Machine\microsoft\windows nt\Audit\audit.csv" " $OutputDir "
28+ Copy-Item " $LgpoDir \DomainSysvol\GPO\Machine\microsoft\windows nt\Audit\audit.csv" " $OutputDir "
2929 $Csv = Import-Csv " $LgpoDir \DomainSysvol\GPO\Machine\microsoft\windows nt\Audit\audit.csv"
30- $Include = $Csv [0 ].psobject.properties | select - ExpandProperty Name - Skip 1
31- $Csv | select $Include | export-csv " $OutputDir \audit.csv" - NoTypeInformation
30+ $Include = $Csv [0 ].psobject.properties | Select-Object - ExpandProperty Name - Skip 1
31+ $Csv | Select-Object $Include | export-csv " $OutputDir \audit.csv" - NoTypeInformation
3232
33- copy " $LgpoDir \DomainSysvol\GPO\Machine\microsoft\windows nt\SecEdit\GptTmpl.inf" " $OutputDir "
33+ Copy-Item " $LgpoDir \DomainSysvol\GPO\Machine\microsoft\windows nt\SecEdit\GptTmpl.inf" " $OutputDir "
3434
3535 function Compare-LGPOPolicies
3636 {
3737 Param (
38- [string ] $ActualPoliciesFile = (Throw " ActualPoliciesFile param required" ),
39- [string ] $ExpectedPoliciesFile = (Throw " ExpectedPoliciesFile param required" ),
40- [string ] $PolicyDelimiter = (Throw " PolicyDelimiter param required" )
38+ [Parameter (Mandatory )]
39+ [string ] $ActualPoliciesFile ,
40+ [Parameter (Mandatory )]
41+ [string ] $ExpectedPoliciesFile ,
42+ [Parameter (Mandatory )]
43+ [string ] $PolicyDelimiter
4144 )
4245 Write-Host " actual policies $ActualPoliciesFile "
4346 Write-Host " expected policies $ExpectedPoliciesFile "
4447
4548 $delims = [char []]" `r`n`t "
46- $ActualPolicies = (Get-Content $ActualPoliciesFile - Raw).Replace(" `r`n " , " `n " )
47- $ActualPoliciesArray = ( [regex ]::split($ActualPolicies , $PolicyDelimiter ) | foreach {
48- $_.Trim ($delims )
49- } )
49+ $ActualPolicies = (Get-Content $ActualPoliciesFile - Raw).Replace(" `r`n " , " `n " )
50+ $ActualPoliciesArray = ([regex ]::split($ActualPolicies , $PolicyDelimiter ) | ForEach-Object { $_.Trim ($delims ) })
5051
51- $ExpectedPolicies = (Get-Content $ExpectedPoliciesFile - Raw).Replace(" `r`n " , " `n " )
52- $ExpectedPoliciesArray = ( [regex ]::split($ExpectedPolicies , $PolicyDelimiter ) | foreach {
53- $_.Trim ($delims )
54- } )
52+ $ExpectedPolicies = (Get-Content $ExpectedPoliciesFile - Raw).Replace(" `r`n " , " `n " )
53+ $ExpectedPoliciesArray = ([regex ]::split($ExpectedPolicies , $PolicyDelimiter ) | ForEach-Object { $_.Trim ($delims ) })
5554
5655 $count = 0
5756 foreach ($policy in $ExpectedPoliciesArray ) {
58- if ($policy -notin $ActualPoliciesArray ) {
59- Write-Error " Actual policies do not include policy: $policy "
60- $count += 1
61- }
57+ if ($policy -notin $ActualPoliciesArray ) {
58+ Write-Error " Actual policies do not include policy: $policy "
59+ $count += 1
60+ }
6261 }
6362 if (-not $count -eq 0 ) {
64- Write-Error " There are missing policies"
65- return 1
63+ Write-Error " There are missing policies"
64+ return 1
6665 }
6766 }
6867
69- $newLineDelimiter = [System.Environment ]::NewLine
70-
7168 $OsVersion = Get-OSVersion
7269 switch ($OsVersion )
7370 {
@@ -95,7 +92,7 @@ function Verify-Dependencies {
9592
9693 Get-ChildItem $BOSH_BIN | ForEach-Object {
9794 Write-Host " Checking for $_ .Name"
98- $files.remove ($_.Name )
95+ $files.Remove ($_.Name )
9996 }
10097
10198 If ($files.Count -gt 0 ) {
@@ -128,10 +125,10 @@ function Verify-Acls {
128125
129126 $errCount = 0
130127
131- Get-ChildItem - Path $path - Recurse | foreach {
128+ Get-ChildItem - Path $path - Recurse | ForEach-Object {
132129 $name = $_.FullName
133130 If (-Not ($_.Attributes -match " ReparsePoint" )) {
134- Get-Acl $name | Select - ExpandProperty Access | ForEach-Object {
131+ Get-Acl $name | Select-Object - ExpandProperty Access | ForEach-Object {
135132 $ident = (' {0},{1}' -f $_.IdentityReference , $_.AccessControlType ).ToString()
136133 If (-Not $expectedacls.Contains ($ident )) {
137134 $errCount += 1
@@ -177,34 +174,34 @@ function Verify-Services {
177174}
178175
179176function Verify-FirewallRules {
180- function get-firewall {
181- param ([string ] $profile )
182- $firewall = (Get-NetFirewallProfile - Name $profile )
183- $result = " {0},{1},{2}" -f $profile , $firewall.DefaultInboundAction , $firewall.DefaultOutboundAction
177+ function Get-FirewallProfile {
178+ param ([string ] $ProfileName )
179+ $firewall = (Get-NetFirewallProfile - Name $ProfileName )
180+ $result = " {0},{1},{2}" -f $ProfileName , $firewall.DefaultInboundAction , $firewall.DefaultOutboundAction
184181 return $result
185182 }
186183
187- function check-firewall {
188- param ([string ] $profile )
189- $firewall = (get-firewall $profile )
184+ function Test-FirewallProfile {
185+ param ([string ] $ProfileName )
186+ $firewall = (Get-FirewallProfile $ProfileName )
190187 Write-Host $firewall
191- if ($firewall -ne " $profile ,Block,Allow" ) {
188+ if ($firewall -ne " $ProfileName ,Block,Allow" ) {
192189 Write-Host $firewall
193- Write-Error " Unable to set $profile Profile"
190+ Write-Error " Unable to set $ProfileName Profile"
194191 Exit 1
195192 }
196193 }
197194
198- check - firewall " public"
199- check - firewall " private"
200- check - firewall " domain"
195+ Test-FirewallProfile " public"
196+ Test-FirewallProfile " private"
197+ Test-FirewallProfile " domain"
201198
202199}
203200
204201function Verify-MetadataFirewallRule {
205202 $MetadataServerAllowRules = Get-NetFirewallRule - Enabled True - Direction Outbound | Get-NetFirewallAddressFilter | Where-Object - FilterScript { $_.RemoteAddress -Eq ' 169.254.169.254' }
206- If ($MetadataServerAllowRules -Ne $null ) {
207- $RuleNames = $MetadataServerAllowRules | foreach { $_.InstanceID }
203+ If ($null -Ne $MetadataServerAllowRules ) {
204+ $RuleNames = $MetadataServerAllowRules | ForEach-Object { $_.InstanceID }
208205 If ($RuleNames.Count -ne 2 ) {
209206 Write-Error " Expected 2 firewall rules"
210207 $RuleNames
@@ -223,21 +220,23 @@ function Verify-MetadataFirewallRule {
223220
224221function Verify-InstalledFeatures {
225222 function Assert-IsInstalled {
226- param (
227- [string ] $feature = (Throw " feature param required" )
228- )
229- If (! (Get-WindowsFeature $feature ).Installed) {
223+ param (
224+ [Parameter (Mandatory )]
225+ [string ] $feature
226+ )
227+ If (! (Get-WindowsFeature $feature ).Installed) {
230228 Write-Error " Failed to find $feature "
231229 Exit 1
232230 } else {
233231 Write-Host " Found $feature feature"
234232 }
235233 }
236234 function Assert-IsNotInstalled {
237- param (
238- [string ] $feature = (Throw " feature param required" )
239- )
240- If (! (Get-WindowsFeature $feature ).Installed) {
235+ param (
236+ [Parameter (Mandatory )]
237+ [string ] $feature
238+ )
239+ If (! (Get-WindowsFeature $feature ).Installed) {
241240 Write-Host " Feature $feature is not installed"
242241 } else {
243242 Write-Error " Feature $feature is installed"
@@ -252,8 +251,8 @@ function Verify-InstalledFeatures {
252251function Verify-ProvisionerDeleted {
253252 $adsi = [ADSI ]" WinNT://$env: COMPUTERNAME "
254253 $user = " Provisioner"
255- $existing = $adsi.Children | where {$_.SchemaClassName -eq ' user' -and $_.Name -eq $user }
256- if ( $existing -eq $null ) {
254+ $existing = $adsi.Children | Where-Object {$_.SchemaClassName -eq ' user' -and $_.Name -eq $user }
255+ if ($null -eq $existing ) {
257256 Write-Host " $user user is deleted"
258257 } else {
259258 Write-Error " $user user still exists. Please run 'Remove-Account -User $user '"
@@ -266,43 +265,43 @@ function Verify-NetBIOSDisabled {
266265 $nbtstat = nbtstat.exe - n
267266 " results for nbtstat: $nbtstat "
268267
269- $nbtstat | foreach {
270- $DisabledNetBIOS = $DisabledNetBIOS -or $_ -like ' *No names in cache*'
268+ $nbtstat | ForEach-Object {
269+ $DisabledNetBIOS = $DisabledNetBIOS -or $_ -like ' *No names in cache*'
271270 }
272271}
273272
274273function Verify-AgentBehavior {
275- $agent = Get-Service | Where { $_.Name -eq ' bosh-agent' }
276- if ($agent -eq $null ) {
277- Write-Error " Missing service: bosh-agent"
278- Exit 1
274+ $agent = Get-Service | Where-Object { $_.Name -eq ' bosh-agent' }
275+ if ($null -eq $agent ) {
276+ Write-Error " Missing service: bosh-agent"
277+ Exit 1
279278 }
280279 if ($agent.StartType -ne " Automatic" ) {
281- Write-Error " verify-agent-start-type: bosh-agent start type is not 'Automatic' got: '$ ( $agent.StartType.ToString ()) '"
282- Exit 1
280+ Write-Error " verify-agent-start-type: bosh-agent start type is not 'Automatic' got: '$ ( $agent.StartType.ToString ()) '"
281+ Exit 1
283282 }
284283
285284 $RegPath = " HKLM:\SYSTEM\CurrentControlSet\Services\bosh-agent"
286285
287- if ((Get-ItemProperty $RegPath ).DelayedAutostart -ne 1 ) {
288- Write-Error " verify-agent-start-type: Expected DelayedAutostart to equal 1"
289- Exit 1
286+ if ((Get-ItemProperty $RegPath ).DelayedAutostart -ne 1 ) {
287+ Write-Error " verify-agent-start-type: Expected DelayedAutostart to equal 1"
288+ Exit 1
290289 }
291290
292291 $ServicesPipeTimeoutPath = " HKLM:\SYSTEM\CurrentControlSet\Control"
293- if ((Get-ItemProperty $ServicesPipeTimeoutPath ).ServicesPipeTimeout -ne 60000 ) {
294- Write-Error " Error: expected ServicesPipeTimeout to equal 60s"
295- Exit 1
292+ if ((Get-ItemProperty $ServicesPipeTimeoutPath ).ServicesPipeTimeout -ne 60000 ) {
293+ Write-Error " Error: expected ServicesPipeTimeout to equal 60s"
294+ Exit 1
296295 }
297296
298297 if ((Get-Service wuauserv).Status -ne " Stopped" ) {
299- Write-Error " Error: expected wuauserv service to be Stopped"
300- Exit 1
298+ Write-Error " Error: expected wuauserv service to be Stopped"
299+ Exit 1
301300 }
302301
303302 $StartType = (Get-Service wuauserv).StartType
304303 if ($StartType -ne " Disabled" ) {
305- Write-Host " Warning: wuauserv service StartType is not disabled: ${StartType} "
304+ Write-Host " Warning: wuauserv service StartType is not disabled: ${StartType} "
306305 }
307306}
308307
@@ -323,31 +322,31 @@ function Verify-RandomPassword {
323322}
324323
325324function Verify-NTPSync {
326- echo " Verifying NTP sync works correctly"
325+ Write-Host " Verifying NTP sync works correctly"
327326 w32tm / query / configuration
328327
329328 Set-Date - Date (Get-Date ).AddHours(-8 )
330329 $OutOfSyncTime = Get-Date
331330
332331 $TimeSetCorrectly = $false
333332
334- for ($i = 0 ; $i -lt 10 ; $i ++ ) {
335- Sleep 1
333+ for ($i = 0 ; $i -lt 10 ; $i ++ ) {
334+ Sleep 1
336335
337- w32tm / resync / rediscover
338- w32tm / resync
336+ w32tm / resync / rediscover
337+ w32tm / resync
339338
340- if ((Get-Date ) -le $OutOfSyncTime ) {
341- Write-Host " Time not reset correctly via NTP on attempt $ ( $i + 1 ) of 10: $ ( Get-Date ) less than or equal to $OutOfSyncTime "
342- } else {
343- $TimeSetCorrectly = $true
344- break
345- }
339+ if ((Get-Date ) -le $OutOfSyncTime ) {
340+ Write-Host " Time not reset correctly via NTP on attempt $ ( $i + 1 ) of 10: $ ( Get-Date ) less than or equal to $OutOfSyncTime "
341+ } else {
342+ $TimeSetCorrectly = $true
343+ break
344+ }
346345 }
347346
348347 if (-not $TimeSetCorrectly ) {
349- Write-Error " Time not reset correctly via NTP after 10 attempts"
350- Exit 1
348+ Write-Error " Time not reset correctly via NTP after 10 attempts"
349+ Exit 1
351350 }
352351}
353352
@@ -367,18 +366,18 @@ function Verify-PSVersion5 {
367366 $PSMajorVersion = $PSVersionTable.PSVersion.Major
368367
369368 if ($PSMajorVersion -lt 5 ) {
370- Write-Error " Powershell Major version is $PSMajorVersion . It should be at least 5"
369+ Write-Error " PowerShell Major version is $PSMajorVersion . It should be at least 5"
371370 Exit 1
372371 }
373372
374- Write-Host " Powershell is up to date: Version is: $ ( $PSVersiontable .PSversion ) "
373+ Write-Host " PowerShell is up to date: Version is: $ ( $PSVersionTable .PSVersion ) "
375374}
376375
377376function Verify-VersionFile {
378377 $VersionFileExists = Test-Path " C:\\var\\vcap\\bosh\\etc\\stemcell_version" - PathType Leaf
379378
380379 if (-Not $VersionFileExists ) {
381- Write-Error " Version file does not exits at path C:\\var\\vcap\\bosh\\etc\\stemcell_version"
380+ Write-Error " Version file does not exist at path C:\\var\\vcap\\bosh\\etc\\stemcell_version"
382381 Exit 1
383382 }
384383
0 commit comments