We help IT Professionals succeed at work.
Get Started

Powershell Export-CSV only gives one result

rstorm1
rstorm1 asked
on
3,051 Views
Last Modified: 2014-05-14
Working with Powershell to pull computer name, manufacturer, and model from a list of computers using Get-WMIObject.  The script works in the Powershell window, but I can't get more than one result (the last computer in the list) in the output when piping to Export-CSV.   I understand that Powershell is probably overwriting the information until it reaches the end of the computer list, but don't know how to fix this.  Does someone have a concise solution on how to get this to work?
Here is what I have so far:

$a = Get-Content "C:\temp\Names.txt"
foreach ($i in $a)
    {$i + "`n" + "=========================="; Get-WMIObject Win32_ComputerSystem -computername $i | Select-Object Name, Manufacturer, Model | Export-CSV "C:\temp\MakeModel.csv"}
Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 8 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE