J ai le fichier CSV suivant :
"ITS-Number", "sAMAccountName-Group"
"ITS590002", "R-LOGA"
"ITS590002", "Smart Vision"
"ITS590002", "R-PS3"
"ITS590002", "P-RGP"
"ITS591001", "R-NETKALK"
"ITS591001", "SHILL"
"ITS591001", "R-PS4"
"ITS591001", "Smart Vision"
"ITS591001", "R-LOGA"


j'aimerais obtenir le fichier CSV ci-dessou:
"R-LOGA","Smart Vision"


en effet j'aimerais lister les "sAMAccountName-Group" qui reviennent plus d'une fois
Mon Code:
Code powershell : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$InputCSV = 'C:\temp\Group.csv'
$OutputCSV = 'C:\temp\GroupTXT'
 
$A = import-csv $InputCSV | Group-Object sAMAccountName-Group
 
# get the maximum number of ITS-Number values for a single sAMAccountName-Group
$max = 0
$A | foreach {if ($_.Count -gt $max) {$max = $_.Count}}
$header = ""
1..$max | ForEach { $header += ('ITS-' + $_ + ',') }  # create the header for the CSV
$header += "sAMAccountName-Group"                   # add the last column header
Set-Content -Path $OutputCSV -Value $header
 
$A | ForEach {
    $empty = $max - $_.Count    # how many empty columns in this row?
    $its = @()
    ForEach ($G in $_.Group) {$its += $G.'ITS-Number'} # get each ITS-Number for this sAMAccountName-Group
    $str = $its -join ','
    $str += (',' * $empty) + ',' + $_.Name             # add the appropriate number of empty columns and the sAMAccountName-Group
    $str | Write-Output
} | Add-Content -Path $OutputCSV

celui ci ne fonctionne pas du tout comme prevu. Merci pour votre aide