Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

test-connection write output to txt file not working?

$
0
0

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


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>