Add new column in csv file

by oleschmi at 2012-10-29 07:34:01

Hi.

I need to generate an IPaddress based on the computernames in a CSV file.
The CSV file looks like this:

"MacAddress","Parent",IPaddress
"00:50:56:b0:27:54","8011TS111",
"00:50:56:b0:27:56","8011TS112",

I want the CSV file to look like this:
"MacAddress","Parent",IPaddress
"00:50:56:b0:27:54","8011TS111",10.200.0.111
"00:50:56:b0:27:56","8011TS112",10.200.0.112

I have this code but I can’t get it to do what I want:
$IPrange = "10.200.0."
$b = Import-CSV C:\test.csv
$b | % {
$numbers = $.Parent.TrimStart("8011TS")
$IPadr = $IPrange+$numbers
$b | Select *,@{Name="IPaddress";Expression={$IPadr}} | Export-CSV C:\testnew.csv
}

How can I solve this?
by mikefrobbins at 2012-10-29 13:44:16
Import-Csv C:\test.csv |
Select-Object MacAddress, Parent, @{Name="IPaddress";Expression={ForEach-Object {"10.200.0."+$
.Parent.substring(6)}}} |
Export-Csv C:\testnew.csv -NoTypeInformation
by oleschmi at 2012-10-30 00:43:21
Worsk great. Thanks!