Private/CommonHealthChecks.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 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
# ADFS Service State Function TestIsAdfsRunning() { $testName = "IsAdfsRunning" $serviceStateOutputKey = "ADFSServiceState" try { $adfsServiceStateTestResult = New-Object TestResult -ArgumentList($testName); $adfsServiceState = (Get-WmiObject win32_service | Where-Object {$_.name -eq "adfssrv"}).State If ($adfsServiceState -ne "Running") { $adfsServiceStateTestResult.Result = [ResultType]::Fail; $adfsServiceStateTestResult.Detail = "Current State of adfssrv is: $adfsServiceState"; } $adfsServiceStateTestResult.Output = @{$serviceStateOutputKey = $adfsServiceState} return $adfsServiceStateTestResult; } catch [Exception] { return Create-ErrorExceptionTestResult $testName $_.Exception } } Function TestTLSMismatch { $testName = "TestTLSMismatch"; try { $testResult = New-Object TestResult -ArgumentList ($testName) $tls10Enabled = IsTlsVersionEnabled("1.0"); $tls11Enabled = IsTlsVersionEnabled("1.1"); $tls12Enabled = IsTlsVersionEnabled("1.2"); # If all TLS versions are enabled then there shouldn't be a mismatch between ADFS and WAP. if ($tls10Enabled -and $tls11Enabled -and $tls12Enabled) { return $testResult; } $str = "{0}{1}{2}" -f [int]$tls10Enabled, [int]$tls11Enabled, [int]$tls12Enabled; switch ($str) { "000" { Out-Verbose "All TLS versions are disabled" $testResult.Result = [ResultType]::Fail; $testResult.Detail = "Detected that all TLS versions are disabled. This will cause problems between your STS and Proxy servers. Fix this by enabling the correct TLS version."; } "001" { $message = "Detected that only TLS 1.2 is enabled. Ensure that this is also enabled on your other STS and Proxy servers."; Out-Warning $message; $testResult.Detail = $message; $testResult.Result = [ResultType]::Warning; } "010" { $message = "Detected that only TLS 1.1 is enabled. Ensure that this is also enabled on your other STS and Proxy servers."; Out-Warning $message; $testResult.Detail = $message; $testResult.Result = [ResultType]::Warning; } "100" { $message = "Detected that only TLS 1.0 is enabled. Ensure that this is also enabled on your other STS and Proxy servers."; Out-Warning $message; $testResult.Detail = $message; $testResult.Result = [ResultType]::Warning; } } return $testResult; } catch [Exception] { return Create-ErrorExceptionTestResult $testName $_.Exception; } } Function TestAdfsEventLogs { $testName = "TestAdfsEventLogs"; Out-Verbose "Running test to check event logs for event ids known to be associated with WAP issues." try { $testResult = New-Object TestResult -ArgumentList ($testName); $adfsVersion = Get-AdfsVersion; if($adfsVersion -eq $null) { throw "Unable to determine AD FS version." } $pastPeriod = (Get-Date).AddDays(-7); if ($adfsVersion -eq $adfs2x) { $logName = "AD FS 2.0/Admin"; } else { $logName = "AD FS/Admin"; } Out-Verbose "Event log name = $logName"; $role = Get-AdfsRole; switch ($role) { $adfsRoleSTS { # These are the event IDs for events on AD FS that are known to be related to WAP problems. $id = @(276); } $adfsRoleProxy { # These are the event IDs for events on WAP that are known to be related to WAP problems. $id = @(224, 393, 394); } default { throw "Unable to determine server role." } } Out-Verbose "Checking event IDs = $id"; $events = Get-WinEvent -FilterHashTable @{LogName = $logName; StartTime = $pastPeriod; ID = $id} -ErrorAction SilentlyContinue; if ($events -ne $null -and $events.Count -ne 0) { Out-Verbose "Found events that indicate a problem with WAP and AD FS." $testResult.Result = [ResultType]::Fail; $testResult.Detail = "There were events found in the AD FS event logs that may be causing issues with the AD FS and WAP trust. Check the output for more details." $testResult.Output = @{"Events" = $events}; } return $testResult; } catch [Exception] { return Create-ErrorExceptionTestResult $testName $_.Exception; } } Function TestTimeSync { Param( [string[]] $adfsServers = $null ) Out-Verbose "Checking time synchronization." $testName = "TestTimeSync"; try { $testResult = New-Object TestResult -ArgumentList ($testName); if (Test-RunningRemotely) { $testResult.Detail = "This test does not need to run remotely."; $testResult.Result = [ResultType]::NotRun; return $testResult; } $role = Get-AdfsRole; switch ($role) { $adfsRoleSTS { Out-Verbose "Detected that the current server is an ADFS server."; if ($adfsServers -eq $null -or $adfsServers.Count -eq 0) { Out-Verbose "No farm information was provided. Only checking time synchronization with the local server and reliable time server." if (!(IsServerTimeInSyncWithReliableTimeServer)) { $testResult.Result = [ResultType]::Fail; $testResult.Detail = "This server's time is out of sync with reliable time server. Check and correct any time synchronization issues." } } else { Out-Verbose "Detected that farm information was available, checking time synchronization across multiple servers."; $serversNotInSync = @(); Out-Verbose "Checking localhost"; if (!(IsServerTimeInSyncWithReliableTimeServer)) { $serversNotInSync += "Localhost"; } foreach ($server in $adfsServers) { $session = New-PSSession -ComputerName $server -ErrorAction SilentlyContinue; if ($session -eq $null) { Out-Warning "There was a problem connecting to $server, skipping this server." continue; } Out-Verbose "Checking $server"; $Private = @(Get-ChildItem -Path $PSScriptRoot\*.ps1 -ErrorAction SilentlyContinue); $commonFunctions = (Get-Command $Private).ScriptContents; $commonFunctions = $commonFunctions -join [Environment]::NewLine; $isInSync = Invoke-Command -Session $session -ArgumentList $commonFunctions -ScriptBlock { Param( $commonFunctions ) Invoke-Expression $commonFunctions; return IsServerTimeInSyncWithReliableTimeServer; } if (!$isInSync) { $serversNotInSync += $server; } Remove-PSSession $session } if ($serversNotInSync.Count -ne 0) { $testResult.Result = [ResultType]::Fail; $testResult.Detail = "Some of the servers in your AD FS farm were out of sync with reliable time server. Check the output for a list of servers." $testResult.Output = @{ "ServersOutOfSync" = $serversNotInSync; } } } } $adfsRoleProxy { Out-Verbose "Detected that the current server is a WAP server."; if (!(IsServerTimeInSyncWithReliableTimeServer)) { $testResult.Result = [ResultType]::Fail; $testResult.Detail = "This server's time is out of sync with reliable time server. Check and correct any time synchronization issues." } } default { throw "Unable to determine server role." } } return $testResult; } catch [Exception] { return Create-ErrorExceptionTestResult $testName $_.Exception; } } |