Processing lists from txt file or others

by Trepidation at 2013-04-18 08:08:31

I’m looking for a simple tutorial, and I think I am just searching for the wrong words.

I want to write something to scan certain WMI entries, and then spit them out to a CSV or whatever. I searched around, and I swear I must be using the wrong terms to find it. Somebody has to have posted something to look at memory of a PC, or CPU, or bios revision… etc. I figured if I found something, I could dissect it mentally and figure out a good way to do it. Since I wasn’t able to do that, I will ask this:

If I am writing a script to perform functions on a list provided by a simple text file. What are some really good ways for handling this? Does someone have a link so they don’t have to write it all out to me. I know this is kinda ultra basic, most of my stuff tends to be singular in nature so this is new territory.
by ArtB0514 at 2013-04-18 08:27:46
What you are looking for is one of the foreach looping processes. Say that your text file has a list of computer names. Then you would want to use one of these methods:

foreach ($Computer in (Get-Content C:\PathToFile\ComputerNames.txt)) {
#Peform your task here using $Computer for the -ComputerName property

Get-Content C:\PathToFile\ComputerNames.txt | foreach-object {
#Perform your task here using $_ for the -ComputerName property

The two Get-Help items you need to read for more details are ForEach-Object and about_Foreach.
by notarat at 2013-04-18 10:30:25
Jesse Hamrick over at wrote a really nice script to gather WMI information for computers. … Inv_v2.ps1

You may want to check it out to see how it gathers information and creates an excel file and places the information into the spreadsheet. I think of it as training in about 40-11 different things I need to learn, lol