The code below tests a series of IPs in a txt file.The result is as follows and is written in a txt file.
19.191.12.161 - online
19.191.12.162 - offline
19.191.12.163 - offline
19.191.12.164 - offline
19.191.12.165 - offline
PowerShell script-screenshot-342-.png
also see the scrennshot

Code:
$Output= @()$GetIP = Get-Content "C:\Users\sdragu2\Desktop\GetIP.txt"foreach ($name in $GetIP){    if (Test-Connection -Delay 15 -ComputerName $name -Count 1 -ErrorAction SilentlyContinue)    {        #$Output+= "$name, online"        $Output = $Output + "$name - online"        Write-Host "$Name - online" -ForegroundColor Green    }    else    {        #$Output+= "$name, offline"        $Output = $Output + "$name - offline"        Write-Host "$Name - offline" -ForegroundColor Red    }}Read-Host -Prompt "Press Enter to exit"$Output | Out-file "C:\Users\sdragu2\Desktop\Test-Connection.txt"
Then I made the script in OOP, but another result is displayed.

Code:
class Connection{    [string] $Output = @()    [string] $GetIP = @()    [string] $Path        Connection([string] $Path)    {        $this.GetIP = (Get-Content "$Path")    }    [void] PSPrint()    {        foreach ($name in $this.GetIP)        {            if (Test-Connection -Delay 15 -ComputerName $name -Count 1 -ErrorAction SilentlyContinue)            {                $this.Output+= "$name - online"                Write-Host "$Name - online" -ForegroundColor Green            }            else            {                $this.Output+= "$name - offline"                Write-Host "$Name - offline" -ForegroundColor Red            }        }    }    [void] ExitScript()    {        Read-Host -Prompt "Press Enter to exit"    }    [void] FilePrint()    {        $this.Output | Out-file "C:\Users\sdragu2\Desktop\Test-Connection.txt"    }}$box = [Connection]::new("C:\Users\sdragu2\Desktop\GetIP.txt")$box.PSPrint()$box.ExitScript()$box.FilePrint()
Do you have any idea why it is not displayed correctly in OOP?
PowerShell script-screenshot-343-.png