hello i am trying to figure out why my output for machines not onine is not being written to the txt file. the file gets created, but its blank. thank you for the help.
$computers = Get-Content .\machines.txt
$computers.Trim() | ForEach {
if (Test-Connection -cn $_ -Count 1 -Quiet) {
$biosInfo = get-wmiobject Win32_BIOS -cn $_ #
$computerInfo = get-wmiobject Win32_ComputerSystem -cn $_ #
$SysEnclosureInfo = get-wmiobject Win32_SystemEnclosure -cn $_ #
$ChassisTypeInfo = get-wmiobject Win32_SystemEnclosure -cn $_ | Select ChassisTypes
$ChassisResult = $ChassisTypeInfo.ChassisTypes
$props = [ordered]@{"Computer Name" = $_"Computer Domain" = $computerInfo.Domain"Manufacturer" = $computerInfo.Manufacturer"Model" = $computerInfo.Model"Serial Number" = $biosInfo.SerialNumber"Asset Tag (BIOS)" = $SysEnclosureInfo.SMBIOSAssetTag"Memory" = [int]($computerInfo.TotalPhysicalMemory/1mb)
UserName = $computerInfo.UserName
ChassisTypeInfo = switch($ChassisResult){ `
{'10','9' -contains $_} {"Laptop"} `
{'3','4','5','6','7','15','16' -contains $_} {"Desktop"} `
default {"Error"} }
}
New-Object PsObject -Property $props
} else {Write-Host "$_" | out-file .\outputerror.txt}
} | Sort ComputerName | Export-csv .\outputfile.csv -notypeinformation