Forum Discussion

kjetilj's avatar
kjetilj
Copper Contributor
Jul 16, 2021

Importing CSV, splitting names and joining

Hi, Very new to PowerShell and scripting so I'm trying to do a lab exercise.   I'm trying to take input from a CSV file where the name is formatted as "Surname, Name". When I split this it returns...
  • gastone's avatar
    gastone
    Jul 16, 2021

    kjetilj 

    Here is a possible solutions

     

    $Users = Import-Csv -Path "C:\Users\user\Scripts\Labs\StuffForLabs\UserListB.csv" -Delimiter ";" |
    ForEach-Object {
    ($_.Name -split ', ')
    }
    for ($i=0; $i -le ($users.count-1); $i=$i+2 ){
    $Users[$i+1] + " " + $Users[$i]
    }

     

     

    this is the output

     

    Dorthy  Rhodes
    Chauncey Woodward
    Julian  Horn

     

Resources