Simple enough, you are only telling it to output 1 object. That object was made after your ForEach loop, so it's only seeing the results of the last cycle of the loop. What you want to do is move the object creation inside your ForEach loop, and have an array that contains those objects. Then once your ForEach loop finishes you can output that to the CSV. This slightly modified script should do what you want:
#[CmdletBinding()]
param (
$computername = (get-content -path 'c:\powershell\computernames.txt'),
[string]$ErrorLog = 'c:\powershell\useful\errorlog\retry.txt',
[switch]$LogErrors
)
[Array]$Collection = foreach ($computer in $computername){
$os = Get-WmiObject Win32_OperatingSystem -computer $computer
$bios = Get-WmiObject Win32_BIOS -computer $computer
$model = Get-WmiObject Win32_ComputerSystem -computer $computer
$AD = Get-ADComputer $computer -Properties LastLogonDate
$ping = Test-Connection -quiet -computername $computer
New-Object -TypeName PSObject -Property @{
Computername = $computer
OnlineStatus = $ping
LoggedIn = $model.username
OSVersion = $os.Caption
LastLogonDate = $AD.LastLogonDate
}
}
$Collection | Export-Csv TestADComputers.csv -NoTypeInformation