PowerShell for Windows Admins

May 7 2013   2:15PM GMT

Scripting Games–how not to output data

Richard Siddaway Richard Siddaway Profile: Richard Siddaway

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)
$plog=($pcors * 2)
$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 “*********** ”
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

1  Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.
  • TomLiotta
    I suspect that many of us following this series (me included) are not quite PowerShell experts, so seeing something like this example converted for 'correct' output technique will be valuable. Here's a vote for a follow-up post on this. -- Tom
    125,585 pointsBadges:

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: