Split multi value column into multiple record PowerShell

Illarionov, Sergei 1 Reputation point
2022-09-12T13:51:45.527+00:00

Hi everyone. I would appreciate any help.
I have a column with multiple values in PowerShell and I want to split them into multiple records. In my case I can do it only in PowerShell and then I am going to export it in CSV.240116-image.png

Windows for business Windows Client for IT Pros Directory services Active Directory
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2022-09-12T14:16:08.037+00:00

    Assuming you're working with a CSV you've exported from that spreadsheet:

    Import-Csv "your-csv-here.csv" |  
        ForEach-Object {  
            $name = $_.Name  
            $_.MemberOfGroups -split ";"|  
                ForEach-Object{  
                    [PSCustomObject]@{  
                        Name = $name  
                        MemberOfGroups = $_  
                    }  
        } | Export-Csv "new-csv-here.csv" -NoTypeInformation  
    

    If you're working from an Excel spreadsheet you can install the ImportExcel PowerShell module and change the 1st line from "Import-Csv" to "Import-Excel".

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.