Checking LOG - Foreach Stopping on just 1 computer

Welcome Forums General PowerShell Q&A Checking LOG - Foreach Stopping on just 1 computer

This topic contains 2 replies, has 2 voices, and was last updated by

 
Participant
3 years, 10 months ago.

  • Author
    Posts
  • #23264

    Participant
    Points: 0
    Rank: Member

    Hello i have a list of computers that i want to check a log file , after an Install I am doing. I am getting no errors but The foreach loop isnt going thru my whole list. its only collecting the data for 1 computer, which is working.

    Here is what I have. Any Help would be great.

    
    $OnlineOnly = ipcsv $CsvFile | ? Online -eq 'TRUE'
    
    ForEach ($c in $OnlineOnly) {
    
    $content = get-content "\\$($c.Computername)\c$\windows\temp\MSXML.txt" -raw
    $match = "Product: MSXML 4.0 SP3 Parser -- Installation completed successfully"
    
    $data = if ($content -match "$($match)") {New-Object PSObject -Property @{Host = $($c.Computername); Value = $true}} else {New-Object PSObject -Property @{Host = $($c.Computername); Value = $false}}
    
    }
    
    
  • #23265

    Keymaster
    Points: 1,785
    Helping HandTeam Member
    Rank: Community Hero

    Oy, with the aliases.

    As written, $data will be overwritten each time through the loop. At the end of the loop, it'll contain the last computer it processed. If your goal is to output the objects to the pipeline, you shouldn't be saving them into a variable.

  • #23267

    Participant
    Points: 0
    Rank: Member

    Oy .. lol

    Thanks Don

The topic ‘Checking LOG - Foreach Stopping on just 1 computer’ is closed to new replies.