Bonsoir,

je sélectionne le groupe AD à partir d'une liste déroulante puis extraie la liste des IDs des membres à supprimer de ce groupe d'un fichier csv.
Voici mon script :
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
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition #path of the folder where is located the current script
 
$name ='*remove.csv'
 
if (test-path "$scriptPath\..\output_files\$name") {clear-content $scriptPath\..\output_files\$name}
 
#creation of the arrays for log (to be done before the foreach)
$remove=@()
 
 # textbox to select the group to clean (the script of the textbox is common and in the file textbox.ps1)
 
$text="Please enter the name of the group to clean:"
. "$scriptPath\textbox.ps1"
$groupcleaned=$objTextBox.Text #name of the group to be cleaned
#one has to use for example sAMAccountName instead of name for any AD cmdlet
$samgroupcleaned = ((Get-ADGroup -Filter {name -eq $groupcleaned} -Server "gad.schneider-electric.com").sAMAccountName)
 
#dropdown list to select a csv file on the disk
. "$scriptPath\sel_disk.ps1" #access to a common code. This script produces the variable $path
 
$csv = Import-Csv -path $path #import of the csv file
 
foreach($line in $csv)
{ 
    $columnvalue = $line.name   #name of SESA
    $data = @()  
    $domains = "eur.gad.schneider-electric.com","apa.gad.schneider-electric.com","nam.gad.schneider-electric.com","gmea.gad.schneider-electric.com"   #enlevé "gad.schneider-electric.com"
    foreach($domain in $domains)
	{
        $rem=Get-ADUser -filter "((EmployeeID -like '$columnvalue') -OR (name -like '$columnvalue')) " -Server $domain
 	$data += $rem ; 
	}
 
	if ($data) { 
            Write-Host "erase $columnvalue"                        
 
            if ($samgroupcleaned) {
                Remove-ADGroupMember -Identity $samgroupcleaned -Member $data -Server "gad.schneider-electric.com"
		$remove +=$line
	    }		    
        }
} 
 
$date=get-date -uformat "%Y%m%d-%H%M%S" #current date in format suited for chronologic search
 
$remove | Export-csv -path $scriptPath\..\output_files\$date-remove.csv
J'obtiens ce message d'erreur :
Remove-ADGroupMember : Le nom de compte spécifié n’est pas membre du groupe
Je l'ai déjà obtenu : https://www.developpez.net/forums/d1...bres-d-groupe/ mais ce qui m'avait aidé ne suffit pas ici. Pouvez-vous m'aider ?