Repository: microsoft/CSS-Exchange
File: Shared/IISFunctions/Get-IISModules.ps1 (PowerShell)

Code before:
                                            SignatureDetails = $signatureDetails
                                        })
                                } catch {
                                    Write-Verbose "Unable to validate file signing information"
                                    Invoke-CatchActionError $CatchActionFunction
                                }
                            } else {
                                Write-Verbose "Module: $($m.Name) found in module skip list and so, will be skipped"
                            }
                        }
                    } else {
                        Write-Verbose "No modules are loaded by IIS"
                    }
                } catch {
                    Write-Verbose "Failed to process global module information. $_"
                    Invoke-CatchActionError $CatchActionFunction
                }
            }
            end {
                return $iisModulesList
            }
        }
    }
    process {
        $iisModulesParams = @{
            Modules = $ApplicationHostConfig.configuration.'system.webServer'.globalModules.add
        }

        if ($SkipLegacyOSModulesCheck) {
            $iisModulesParams.Add("ModulesToSkip", $modulesToSkip)
        }

        $modules = GetIISModulesSignatureStatus @iisModulesParams

        # Validate if all modules that are loaded are digitally signed
        $allModulesAreSigned = (-not($modules.Signed.Contains($false)))
        Write-Verbose "Are all modules loaded by IIS digitally signed? $allModulesAreSigned"

        # Validate that all modules are signed by Microsoft Corp.
        $allModulesSignedByMSFT = (-not($modules.SignatureDetails.IsMicrosoftSigned.Contains($false)))
        Write-Verbose "Are all modules signed by Microsoft Corporation? $allModulesSignedByMSFT"

        # Validate if all signatures are valid (regardless of whether signed by Microsoft Corp. or not)
        $allSignaturesValid = $null -eq ($modules |
                Where-Object { $_.Signed -and $_.SignatureDetails.SignatureStatus -ne 0 })
    }
    end {
        return [PSCustomObject]@{
            AllSignedModulesSignedByMSFT = $allModulesSignedByMSFT
            AllSignaturesValid           = $allSignaturesValid
            AllModulesSigned             = $allModulesAreSigned

Review comment (suggestion):
When setting `Modules` variable, this is where you do something like `Where-Object { $SkipLegacyOSModulesCheck -and (in list of skip modules) } 

Code after:
                            }
                        }
                    } else {
                        Write-Verbose "No modules are loaded by IIS"
                    }
                } catch {
                    Write-Verbose "Failed to process global module information. $_"
                    Invoke-CatchActionError $CatchActionFunction
                }
            }
            end {
                return $iisModulesList
            }
        }
    }
    process {
        $ApplicationHostConfig.configuration.'system.webServer'.globalModules.add | ForEach-Object {
            if ($SkipLegacyOSModulesCheck) {
                if ((GetModulePath $_.image) -notin $modulesToSkip) {
                    $modulesToCheckList.Add($_)
                }
            } else {
                $modulesToCheckList.Add($_)
            }
        }

        $modules = GetIISModulesSignatureStatus -Modules $modulesToCheckList

        # Validate if all modules that are loaded are digitally signed
        $allModulesAreSigned = (-not($modules.Signed.Contains($false)))
        Write-Verbose "Are all modules loaded by IIS digitally signed? $allModulesAreSigned"

        # Validate that all modules are signed by Microsoft Corp.
        $allModulesSignedByMSFT = (-not($modules.SignatureDetails.IsMicrosoftSigned.Contains($false)))
        Write-Verbose "Are all modules signed by Microsoft Corporation? $allModulesSignedByMSFT"

        # Validate if all signatures are valid (regardless of whether signed by Microsoft Corp. or not)
        $allSignaturesValid = $null -eq ($modules |
                Where-Object { $_.Signed -and $_.SignatureDetails.SignatureStatus -ne 0 })
    }
    end {
        return [PSCustomObject]@{
            AllSignedModulesSignedByMSFT = $allModulesSignedByMSFT
            AllSignaturesValid           = $allSignaturesValid
            AllModulesSigned             = $allModulesAreSigned
            ModuleList                   = $modules
        }
    }
}