Merge of multiple rows to single row in csv Using Powershell
<p>I have a <code>.csv</code> file which looks like </p>

<pre><code>ID, Dept
1,x
1,y
1,z
2,a
2,b
2,c
</code></pre>

<p>output should be</p>

<pre><code>ID, Dept
1, x;y;z
2, a;b;c
</code></pre>

<p>I tried the with below in the PowerShell but it is returning 0 for both columns</p>

<pre><code>$csvValues = Get-Content "DeptDetails.csv"
$duplicates = $csvValues | group-object ID | ? Count -gt 1

$objs = New-Object System.Collections.ArrayList
ForEach ($duplicate in $duplicates){
$objs.Add([pscustomobject]@{ID = ($duplicate.Group.ID | select -Unique) -as [int];
GroupName=($duplicate.Group.Dept | ? Length -gt 0) -join ';'})
}
$objs | Sort ID
</code></pre>