Add new column in csv file

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 6 years, 2 months ago.

  • Author
  • #5240

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


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


    I want the CSV file to look like this:

    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!

You must be logged in to reply to this topic.