We help IT Professionals succeed at work.

Powershell Excel Script

Experts,

I am looking for a script to do the following :


CSV1
Server, IP address, Role, Address, Reboot Policy

CSV2
Server, Chassis Address, management IP,

I would like the final CSV to have the following Columns and rows
CSV3
Server, IP Address, Chassis, Management Address, Reboot Policy, Role

I would like to Merge the two CSV's using the server field from CSV2.

This is a little above my scripting level at the moment.
Comment
Watch Question

CERTIFIED EXPERT
Most Valuable Expert 2019
Most Valuable Expert 2018
Commented:
Try it like that; it creates a hash table of csv2 as lookup, and inserts them as calculated properties into csv1:
$servers2 = @{}
Import-Csv -Path C:\Temp\Servers2.csv | ForEach-Object {$servers2[$_.Server] = $_}
Import-Csv -Path C:\Temp\Servers1.csv |
	Select-Object -Property `
		Server, 'IP address', Role, Address, 'Reboot Policy',
		@{n='Chassis Address'; e={$servers2[$_.Server].'Chassis Address'}},
		@{n='Management IP'; e={$servers2[$_.Server].'Management IP'}} |
	Export-Csv -NoTypeInformation -Path C:\Temp\Servers3.csv

Open in new window

CERTIFIED EXPERT

Author

Commented:
That was exactly what I needed. Thanks!
Senior IT System EngineerSenior Systems Engineer
CERTIFIED EXPERT

Commented:
Wow, that's cool, so the hash table can be used just like SQL table to join the two table based on certain criteria ?

Explore More ContentExplore courses, solutions, and other research materials related to this topic.