Repository: microsoft/CSS-Exchange
File: Admin/Test-AMSI.ps1 (PowerShell)

Code before:

        $LogFolder = $null
        $isDisabled = $false

        if ($SearchHttpRequestFiltering) {
            $OriginalLogFolder = Join-Path $ExchangePath "Logging\HttpRequestFiltering\"
            if ($Server.Equals($env:COMPUTERNAME, [System.StringComparison]::OrdinalIgnoreCase)) {
                $LogFolder = $OriginalLogFolder
            } else {
                $LogFolder = "\\$Server\$($OriginalLogFolder.Replace(':','$'))"
            }
        }

        if ($SearchIIS) {
            $getIISLogPath = {
                $webSite = Get-Website "Default Web Site"
                $logPath = $webSite.logFile.directory
                $resolvedPath = [System.IO.Path]::GetFullPath([System.Environment]::ExpandEnvironmentVariables($logPath))
                "$resolvedPath\w3svc$($webSite.id)"
            }

            $OriginalLogFolder = Invoke-ScriptBlockHandler -ComputerName $server -ScriptBlock $getIISLogPath
            if ($server.Equals($env:COMPUTERNAME, [System.StringComparison]::OrdinalIgnoreCase)) {
                $LogFolder = $OriginalLogFolder
            } else {
                $LogFolder = "\\$server\$($OriginalLogFolder.Replace(':','$'))"
            }

            $getIISLogDisabled = { (Get-WebConfigurationProperty -PSPath "IIS:\Sites\Default Web Site\ecp" -Filter "system.webServer/httpLogging" -Name donTLog).Value }
            $isDisabled = (Invoke-ScriptBlockHandler -ComputerName $server -ScriptBlock $getIISLogDisabled)
            if ($isDisabled) {
                Write-Host "We could not get IIS log for $Server because it is disabled" -ForegroundColor Yellow
                return
            }
        }

        if ($null -eq $LogFolder) {
            Write-Host "We could not get log folder for $Server" -ForegroundColor Yellow
        } else {
            Write-Host "Looking for request $UrlStem on server $Server" -ForegroundColor Yellow
            if ($SearchIIS) {
                Write-Host "IIS logs on Folder $OriginalLogFolder ..."
            } else {
                Write-Host "HttpRequestFiltering logs on Folder $OriginalLogFolder ..."
            }

            if (Test-Path $LogFolder -PathType Container) {
                $timeout1min = (Get-Date).AddMinutes(1)
                $foundRequest = $false
                do {
                    Start-Sleep -Seconds 1

Review comment (suggestion):
What happens if `$OriginalLogFolder` is set to `$null`

Code after:

        $LogFolder = $null
        $isDisabled = $false

        if ($SearchHttpRequestFiltering) {
            $OriginalLogFolder = Join-Path $ExchangePath "Logging\HttpRequestFiltering\"
            if ($Server.Equals($env:COMPUTERNAME, [System.StringComparison]::OrdinalIgnoreCase)) {
                $LogFolder = $OriginalLogFolder
            } else {
                $LogFolder = "\\$Server\$($OriginalLogFolder.Replace(':','$'))"
            }
        }

        if ($SearchIIS) {
            $getIISLogPath = {
                $webSite = Get-Website "Default Web Site"
                $logPath = $webSite.logFile.directory
                $resolvedPath = [System.IO.Path]::GetFullPath([System.Environment]::ExpandEnvironmentVariables($logPath))
                "$resolvedPath\w3svc$($webSite.id)"
            }

            $OriginalLogFolder = $null
            $OriginalLogFolder = Invoke-ScriptBlockHandler -ComputerName $server -ScriptBlock $getIISLogPath
            if ($OriginalLogFolder) {
                if ($server.Equals($env:COMPUTERNAME, [System.StringComparison]::OrdinalIgnoreCase)) {
                    $LogFolder = $OriginalLogFolder
                } else {
                    $LogFolder = "\\$server\$($OriginalLogFolder.Replace(':','$'))"
                }

                $getIISLogDisabled = { (Get-WebConfigurationProperty -PSPath "IIS:\Sites\Default Web Site\ecp" -Filter "system.webServer/httpLogging" -Name donTLog).Value }
                $isDisabled = (Invoke-ScriptBlockHandler -ComputerName $server -ScriptBlock $getIISLogDisabled)
                if ($isDisabled) {
                    Write-Host "We could not get IIS log for $Server because it is disabled" -ForegroundColor Yellow
                    return
                }
            } else {
                Write-Host "We could not get IIS log for $Server" -ForegroundColor Red
                return
            }
        }

        if ($LogFolder) {
            if (Test-Path -Path $LogFolder -PathType Container) {
                Write-Host "Looking for request $UrlStem on server $Server" -ForegroundColor Yellow
                if ($SearchIIS) {
                    Write-Host "IIS logs on Folder $OriginalLogFolder ..."
                } else {
                    Write-Host "HttpRequestFiltering logs on Folder $OriginalLogFolder ..."
                }