I don't see anything glaringly obvious that would cause that problem. I will point that in your "Write-Log" function you have the possibility of sending contents of the "$Line" variable into the success data stream. That could cause problems if you write your programs in a way that uses pipelined data, as in the code sample below (your original code modified to use pipelines).
Do you find anything in your log file that might help you discover where the problem lies? Why all the "Start-Sleep" cmdlets?
Function Write-Log {
[CmdletBinding()]
Param(
[Parameter(Mandatory = $False)]
[ValidateSet("INFO", "WARN", "ERROR", "FATAL", "DEBUG")]
[String]
$Level = "INFO",
[Parameter(Mandatory = $True)]
[string]
$Message,
[Parameter(Mandatory = $False)]
[string]
$logfile = "C:\Temp\GetBiosinfo\BIOSLog.log"
)
$Stamp = (Get-Date).toString("yyyy/MM/dd HH:mm:ss")
$Line = "$Stamp $Level $Message"
If ($logfile) {
Add-Content $logfile -Value $Line
}
Else {
Write-Output $Line
}
}
$computerinfo = [ordered]@{
Hostname = ""
Model = ""
Manufacturer = ""
BIOSVersion = ""
}
Get-Content -Path "C:\Temp\GetBiosInfo\computerlist.txt" |
ForEach-Object {
$computerinfo.Hostname = $_
If (Test-Connection $_ -Count 1 -Quiet) {
Start-Sleep -Seconds 5
Write-Log -Message "$_ is online"
$Model = (Get-WmiObject Win32_ComputerSystemProduct -ComputerName $_).Name
$BIOSManuf = (Get-WmiObject -Class Win32_BIOS -ComputerName $_).Manufacturer
$BIOSVersion = (Get-WmiObject -Class Win32_BIOS -ComputerName $_).SMBIOSBIOSVersion
Start-Sleep -Seconds 5
Write-Log -Message "$_ WMI Info Gathered"
If ( $BIOSManuf -or $BIOSVersion -or $Model ) {
$computerinfo.Manufacturer = $BIOSManuf
$computerinfo.Model = $Model
$computerinfo.BIOSVersion = $BIOSVersion
Start-Sleep -Seconds 5
Write-Log -Message "$_ online info updated in CSV"
}
Else {
$computerinfo.Manufacturer = "Connected but no response"
$computerinfo.Model = ""
$computerinfo.BIOSVersion = ""
Start-Sleep -Seconds 5
Write-Log -Level WARN -Message "$_ online but no response info updated in CSV"
}
}
Else {
Start-Sleep -Seconds 5
Write-Log -Level WARN -Message "$_ is NOT online"
$computerinfo.Manufacturer = "Can't Connect"
$computerinfo.Model = ''
$computerinfo.BIOSVersion = ''
Start-Sleep -Seconds 5
Write-Log -Message "$_ not online info updated in CSV"
}
[PSCustomObject]$computerinfo
} | Export-Csv -Path "C:\Temp\GetBIOSInfo\BIOSInfo.csv" -NoTypeInformation