Вопрос

If we have a webpage on port 1055, perfstat is installed. It will update the spread sheet with either a yes or no.

Here is the strange thing. - Two Computers .. Computer1 has perfstat and Computer2 does not - If I place Computer2 in the txt file first, the results come out correct. False and True-
- If I place Computer1 first in the txt file, both machines come up as true! :(

I have something screwed up with the if statement. As soon as it goes into the IF section, the results are incorrect.

Here is my code

$Computers = Get-Content -Path C:\temp\servers.txt


foreach ($Server in $computers)
{

    $reply = Invoke-WebRequest http://$Server":1055" | Select-Object Content

    if ($reply.Content -like "*Windows PerfStat v1.1.4*")
    {
        $Sheet1.Cells.Item($intRow, 1) = $server
        $Sheet1.Cells.Item($intRow, 2) = "Yes"
    }
    else
    {
        $Sheet1.Cells.Item($intRow, 1) = $server
        $Sheet1.Cells.Item($intRow, 2) = "No"
    }
    $intRow = $intRow + 1
}
Это было полезно?

Решение

the problem is that Computer2 is not sending a result to feed into $reply. As such, if Computer1 is run first $Reply still has the same value when Computer2 runs. Add a remove-variable reply before your $reply = line:

foreach ($Server in $computers) {
if($reply){remove-variable reply}
$reply = Invoke-WebRequest http://$Server":1055" | Select-Object Content
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top