• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1175
  • Last Modified:

Powershell / new-object PSObject rows

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
Johann Buve
Asked:
Johann Buve
1 Solution
 
oBdACommented:
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
 
Johann BuveAuthor Commented:
Damn I'm dumb... Thx!
0

Featured Post

 The Evil-ution of Network Security Threats

What are the hacks that forever changed the security industry? To answer that question, we created an exciting new eBook that takes you on a trip through hacking history. It explores the top hacks from the 80s to 2010s, why they mattered, and how the security industry responded.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now