Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Powershell / new-object PSObject rows

Posted on 2016-09-30
2
459 Views
Last Modified: 2016-09-30
Hello!

I'm trying to figure out how PSObjects are working.
I've got a CSV file like that :


HostName;IP;DriverLang
PRINTER1;192.168.100.100;PCL6
PRINTER2;192.168.100.101;PS

I'm trying to organize the informations in a table (to add more after)

$CSV = Import-CSV "$PSScriptRoot\PRINTERS.csv" -Delimiter ";"

ForEach ($item in $CSV) {
$CSV2 = new-object PSObject
$CSV2 | Add-Member -type Noteproperty -Name HostNames -value $CSV.HostName
$CSV2 | Add-Member -type Noteproperty -Name IPs -value $CSV.IP
$CSV2 | Add-Member -type Noteproperty -Name DriverLangs -value $CSV.DriverLang
Write-Output $CSV2
}

Open in new window


But the result appears like that, when I want only 1 value per line of course.

HostNames            IPs                                DriverLangs
---------            ---                                -----------
{PRINTER1, PRINTER2} {192.168.100.100, 192.168.100.101} {PCL6, PS} 
{PRINTER1, PRINTER2} {192.168.100.100, 192.168.100.101} {PCL6, PS}

Open in new window


Where is my mistake?

Cheers,
0
Comment
Question by:Johann Buve
2 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 41823178
Inside the ForEach loop, you're using the whole $CSV instead of the loop variable "$Item".
$CSV = Import-CSV "$PSScriptRoot\PRINTERS.csv" -Delimiter ";"
ForEach ($item in $CSV) {
	$CSV2 = new-object PSObject
	$CSV2 | Add-Member -type Noteproperty -Name HostNames -value $item.HostName
	$CSV2 | Add-Member -type Noteproperty -Name IPs -value $item.IP
	$CSV2 | Add-Member -type Noteproperty -Name DriverLangs -value $item.DriverLang
	Write-Output $CSV2
}

Open in new window

0
 

Author Comment

by:Johann Buve
ID: 41823192
Damn I'm dumb... Thx!
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This script checks a path to see if a folder exists. If the folder does exist you will get output "The folder has previously been created. No action taken" If not it will create the folder. Then adds one user modify permission to the folder. It …
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question