github.com/cloudfoundry-incubator/windows-utilities-tests@v0.11.1-0.20230315194243-a2ce46b74d8a/assets/wuts-release/jobs/check_rdp/templates/post-start.ps1.erb (about) 1 $IsEnabled = [bool]$<%= p("check_rdp.expected") %> 2 3 "Running Test 'check_rdp' - we expect RDP with IsEnabled: $IsEnabled" 4 5 $Errors = @() 6 7 # Firewall 8 9 # The Enabled field is an Enum that converts to bool 10 [int]$RuleDisabled = 1 11 [int]$RuleEnabled = 2 12 [int]$expState = if ($IsEnabled) { $RuleEnabled } else { $RuleDisabled } 13 14 $expectedRules = Get-NetFirewallRule -DisplayName "Remote Desktop*" | where { $_.Enabled -eq $expState } 15 foreach ($rule in $expectedRules) { 16 $Errors += "Expected firewall rule $($rule.Name) to be $IsEnabled got: $($rule.Enabled)" 17 } 18 19 # Service 20 21 $expectedStatus = 'Stopped' 22 23 if ($IsEnabled) { 24 $expectedStatus = 'Running' 25 } 26 27 for ($i=0; $i -lt 20 -and ($(Get-Service 'TermService').Status -ne $expectedStatus); $i++) { 28 Write-Host "Sleeping..." 29 Start-Sleep 5 30 } 31 32 $rdp=(Get-Service 'TermService') 33 if ($rdp.Status -ne $expectedStatus) { 34 $Errors += "Expected TermService to be '$expectedStatus' got: $($rdp.Status)" 35 } 36 37 $startMode = (Get-WmiObject -Class Win32_Service -Property StartMode -Filter "Name='TermService'").StartMode 38 if ($IsEnabled) { 39 if ($startMode -eq 'Disabled') { 40 $Errors += "Expected TermService to not be disabled" 41 } 42 } else { 43 if ($startMode -ne 'Disabled') { 44 $Errors += "Expected TermService to be disabled got: $($rdp.StartType)" 45 } 46 } 47 48 # fDenyTSConnections determines if RDP is enabled 49 50 $denyConnections=(Get-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server").fDenyTSConnections 51 if ($IsEnabled) { 52 if ($denyConnections -ne 0) { 53 $Errors += "Expected 'fDenyTSConnections' to be 0 got: $denyConnections" 54 } 55 } else { 56 if ($denyConnections -ne 1) { 57 $Errors += "Expected 'fDenyTSConnections' to be 1 got: $denyConnections" 58 } 59 } 60 61 # Summary 62 63 if ($Errors.Count) { 64 "Test failed: found $($Errors.Count) errors:" 65 foreach ($msg in $Errors) { 66 "Error: $msg" 67 } 68 Exit 1 69 } 70 71 "Test passed" 72 Exit 0