Scripting Games–how not to output data

I haven’t finished blogging about event 1 yet but this caught my eye.

Things aren’t too bad until we hit the bunch of  write-host calls

$wrks = (Get-Content -path C:\IPList.txt)
foreach ($wrk in $wrks)
{
    $osver = Get-WMIObject -class win32_operatingsystem -ComputerName $wrk
    $procs = @(Get-WMIObject -class win32_processor -ComputerName $wrk)
    $psok=($procs.SocketDesignation).count
    $pcors=(($procs.numberofcores[0])*$psok)
    $plog=($pcors * 2)
    $psped=$procs.MaxClockSpeed[0]
    $mem = Get-WMIObject -class win32_physicalmemory -ComputerName $wrk
    $memtotal = ($mem | Measure-Object -Property capacity -Sum)
    $memgb = $memtotal.sum/1gb
Write-host "*******************************************************"
Write-Host "Machine Name: " $osver.CSName
Write-Host "OS: "$osver.caption
Write-Host "Service Pack: "$osver.csdversion
Write-Host "Build #: "$osver.version
Write-Host "*********** "
Write-Host "Memory Installed:"
Write-Host "*********** "
Write-Host "Memory (GB): $memgb "
Write-Host "Slots used:" $memtotal.Count
Write-Host "*********** "
Write-Host "Processor(s) Installed:"
Write-Host "*********** "
Write-Host "Sockets:" $psok
Write-Host "Cores:" $pcors
Write-Host "Logical Procs:" $plog
Write-Host "*********** "
Write-Host "Processor Details:"
Write-Host "*********** "
$procs
Write-Host ""
}

The correct way is to create an object and output that

I’ll be blogging a sample answer when the games are over.  for now be aware that write-host is worse than backticks

Published Tue, May 7 2013 21:14 by RichardSiddaway

Leave a Comment

(required) 
(required) 
(optional)
(required) 
If you can't read this number refresh your screen
Enter the numbers above: