I would like ps to do the following, and it’s kicking my ass as a complete powershell nub. The report has the IP addresses already and I need the hostnames. I have a CSV that is a report from a log server and appears like this
Source Device,Translated IP,Source IP,Destination IP,Port,Protocol,Description,Messages,Out Bytes device name,111.111.111.111,222.222.222.222,333.333.333.333,80,tcp,ftp,2,1
I need to add fields to the header, every row below it, and do grab the hostnames from the ip’s. The header should look like this
Source Device,Translated IP,TransName,Source IP,SourceName,Destination IP,Port,Protocol,Description,Messages,Out Bytes FW_Primary,111.111.111.111,222.222.222.222,somewebsite,333.333.333.333,somewebsite,21,tcp,ftp,2,0
As a nub, I’ve managed to get SOME aspects of this done. For instance I have a script using get-content from the source csv and export-csv the lookup on a fresh file. Problem is I don’t know how I could use get-content to pull from anything but the first column. So for it to work, I’d have to delete everything but ‘Source IP’
Import-Csv wc.csv | foreach-object { $_ | add-member -membertype noteproperty -Name 'Source IP Name' -value "" -passthru | add-member -membertype noteproperty -Name 'Dest IP Name' -value "" -passthru | } | Export-Csv wc1.csv -NoTypeInformation
I’ve managed to figure out how to add columns using the add-member function but, I can’t figure out how to embed the columns so that they aren’t placed in the end. Any help would be appreciated.