Question
Lister et copier groupe AD
- j0nj0n
- Auteur du sujet
- Hors Ligne
- Nouveau membre
-
Réduire
Plus d'informations
- Messages : 2
- Remerciements reçus 0
il y a 10 ans 8 mois #20495
par j0nj0n
Lister et copier groupe AD a été créé par j0nj0n
Bonjour,
Je suis vraiment nul en programmation et j'aimerai faire un script interfacé a un GUI permettant de:
1 - faire une recherche d'un compte dans Active Directory
(1.1 - Si possible en utilisant le pop up de recherche AD)
2 - lister les groupes auxquels ce compte appartient
3 - comparer les appartenance de ce compte a un autre compte AD
4 - copier tous les groupes d'un compte a l'autre.
J'ai trouvé un script qui se rapproche pas mal de ce que je veux faire mais j'aimerai faire une interface graphique qui me permettrai de pouvoir choisir les utilisateurs en tapant une partie du nom (d'ou le pop up Active Directory).
Je reste a votre disposition si vous avez des besoins de plus de renseignements.
[code:1]<#
.SYNOPSIS
Script that compares group membership of source users and destination user and adds destination user to source user group
.DESCRIPTION
This script compares the group membership of $sourceacc and $destacc, based on the membership of the source account
the destination account is also to these groups. Script outputs actions taken to the prompt. The script can also be run
without any parameters then the script will prompt for both usernames.
.PARAMETER Sourceacc
User of which group membership is read
.PARAMETER Filename
User that becomes member of all the groups that Sourceacc is member of
.PARAMETER Noconfirm
No user input is required and the script runs automatically
.NOTES
Name: Compare-ADuserAddGroup.ps1
Author: Jaap Brasser
DateCreated: 14-03-2012
.EXAMPLE
.\Compare-ADuserAddGroup.ps1 testuserabc123 testuserabc456
Description
This command will add testuserabc456 to all groups that testuserabc123 is a memberof with the exception of all
groups testuserabc456 is already a member of.
.EXAMPLE
.\Compare-ADuserAddGroup.ps1
#>
param(
$sourceacc,
$destacc,
[switch]$noconfirm
)
# Checks if both accounts are provided as an argument, otherwise prompts for input
if (-not $sourceacc) { $sourceacc = read-host \"Please input source user name, the user the rights will be read from\" }
if (-not $destacc) { $destacc = read-host \"Please input destination user name, the user which will be added to the groups of the source user\" }
# Retrieves the group membership for both accounts
$sourcemember = get-aduser -filter {samaccountname -eq $sourceacc} -property memberof | select memberof
$destmember = get-aduser -filter {samaccountname -eq $destacc} -property memberof | select memberof
# Checks if accounts have group membership, if no group membership is found for either account script will exit
if ($sourcemember -eq $null) {\"Source user not found\";return}
if ($destmember -eq $null) {\"Destination user not found\";return}
# Checks for differences, if no differences are found script will prompt and exit
if (-not (compare-object $destmember.memberof $sourcemember.memberof | where-object {$_.sideindicator -eq '=>'})) {write-host \"No difference between $sourceacc & $destacc groupmembership found. $destacc will not be added to any additional groups.\";return}
# Routine that changes group membership and displays output to prompt
compare-object $destmember.memberof $sourcemember.memberof | where-object {$_.sideindicator -eq '=>'} |
select -expand inputobject | foreach {write-host \"$destacc will be added to:\"([regex]::«»split($_,'^CN=|,OU=.+$'))[1]}
# If no confirmation parameter is set no confirmation is required, otherwise script will prompt for confirmation
if ($noconfirm) {
compare-object $destmember.memberof $sourcemember.memberof | where-object {$_.sideindicator -eq '=>'} |
select -expand inputobject | foreach {add-adgroupmember \"$_\" $destacc}
}
else {
do{
$UserInput = Read-Host \"Are you sure you wish to add $destacc to these groups?`n[Y]es, [N]o or e[X]it\"
if ((\"Y\",\"yes\",\"n\",\"no\",\"X\",\"exit\"«») -notcontains $UserInput) {
$UserInput = $null
Write-Warning \"Please input correct value\"
}
if ((\"X\",\"exit\",\"N\",\"no\"«») -contains $UserInput) {
Write-Host \"No changes made, exiting...\"
exit
}
if ((\"Y\",\"yes\"«») -contains $UserInput) {
compare-object $destmember.memberof $sourcemember.memberof | where-object {$_.sideindicator -eq '=>'} |
select -expand inputobject | foreach {add-adgroupmember \"$_\" $destacc}
}
}
until ($UserInput -ne $null)
}[/code:1]
Merci d'avance pour votre aide.
Edit: J'utilise Sapien PowerShell Studio pour l'interface graphique.<br><br>Message édité par: j0nj0n, à: 20/07/15 06:40
Je suis vraiment nul en programmation et j'aimerai faire un script interfacé a un GUI permettant de:
1 - faire une recherche d'un compte dans Active Directory
(1.1 - Si possible en utilisant le pop up de recherche AD)
2 - lister les groupes auxquels ce compte appartient
3 - comparer les appartenance de ce compte a un autre compte AD
4 - copier tous les groupes d'un compte a l'autre.
J'ai trouvé un script qui se rapproche pas mal de ce que je veux faire mais j'aimerai faire une interface graphique qui me permettrai de pouvoir choisir les utilisateurs en tapant une partie du nom (d'ou le pop up Active Directory).
Je reste a votre disposition si vous avez des besoins de plus de renseignements.
[code:1]<#
.SYNOPSIS
Script that compares group membership of source users and destination user and adds destination user to source user group
.DESCRIPTION
This script compares the group membership of $sourceacc and $destacc, based on the membership of the source account
the destination account is also to these groups. Script outputs actions taken to the prompt. The script can also be run
without any parameters then the script will prompt for both usernames.
.PARAMETER Sourceacc
User of which group membership is read
.PARAMETER Filename
User that becomes member of all the groups that Sourceacc is member of
.PARAMETER Noconfirm
No user input is required and the script runs automatically
.NOTES
Name: Compare-ADuserAddGroup.ps1
Author: Jaap Brasser
DateCreated: 14-03-2012
.EXAMPLE
.\Compare-ADuserAddGroup.ps1 testuserabc123 testuserabc456
Description
This command will add testuserabc456 to all groups that testuserabc123 is a memberof with the exception of all
groups testuserabc456 is already a member of.
.EXAMPLE
.\Compare-ADuserAddGroup.ps1
#>
param(
$sourceacc,
$destacc,
[switch]$noconfirm
)
# Checks if both accounts are provided as an argument, otherwise prompts for input
if (-not $sourceacc) { $sourceacc = read-host \"Please input source user name, the user the rights will be read from\" }
if (-not $destacc) { $destacc = read-host \"Please input destination user name, the user which will be added to the groups of the source user\" }
# Retrieves the group membership for both accounts
$sourcemember = get-aduser -filter {samaccountname -eq $sourceacc} -property memberof | select memberof
$destmember = get-aduser -filter {samaccountname -eq $destacc} -property memberof | select memberof
# Checks if accounts have group membership, if no group membership is found for either account script will exit
if ($sourcemember -eq $null) {\"Source user not found\";return}
if ($destmember -eq $null) {\"Destination user not found\";return}
# Checks for differences, if no differences are found script will prompt and exit
if (-not (compare-object $destmember.memberof $sourcemember.memberof | where-object {$_.sideindicator -eq '=>'})) {write-host \"No difference between $sourceacc & $destacc groupmembership found. $destacc will not be added to any additional groups.\";return}
# Routine that changes group membership and displays output to prompt
compare-object $destmember.memberof $sourcemember.memberof | where-object {$_.sideindicator -eq '=>'} |
select -expand inputobject | foreach {write-host \"$destacc will be added to:\"([regex]::«»split($_,'^CN=|,OU=.+$'))[1]}
# If no confirmation parameter is set no confirmation is required, otherwise script will prompt for confirmation
if ($noconfirm) {
compare-object $destmember.memberof $sourcemember.memberof | where-object {$_.sideindicator -eq '=>'} |
select -expand inputobject | foreach {add-adgroupmember \"$_\" $destacc}
}
else {
do{
$UserInput = Read-Host \"Are you sure you wish to add $destacc to these groups?`n[Y]es, [N]o or e[X]it\"
if ((\"Y\",\"yes\",\"n\",\"no\",\"X\",\"exit\"«») -notcontains $UserInput) {
$UserInput = $null
Write-Warning \"Please input correct value\"
}
if ((\"X\",\"exit\",\"N\",\"no\"«») -contains $UserInput) {
Write-Host \"No changes made, exiting...\"
exit
}
if ((\"Y\",\"yes\"«») -contains $UserInput) {
compare-object $destmember.memberof $sourcemember.memberof | where-object {$_.sideindicator -eq '=>'} |
select -expand inputobject | foreach {add-adgroupmember \"$_\" $destacc}
}
}
until ($UserInput -ne $null)
}[/code:1]
Merci d'avance pour votre aide.
Edit: J'utilise Sapien PowerShell Studio pour l'interface graphique.<br><br>Message édité par: j0nj0n, à: 20/07/15 06:40
Connexion ou Créer un compte pour participer à la conversation.
- Laurent Dardenne
- Hors Ligne
- Modérateur
-
Réduire
Plus d'informations
- Messages : 6311
- Remerciements reçus 68
il y a 10 ans 8 mois #20524
par Laurent Dardenne
Tutoriels PowerShell
Réponse de Laurent Dardenne sur le sujet Re:Lister et copier groupe AD
Salut,
un conseil créer d'abord des fonctions pour chaque traitement, ensuite construit le GUI autour de ces fonctions.
j0nj0n écrit:
un conseil créer d'abord des fonctions pour chaque traitement, ensuite construit le GUI autour de ces fonctions.
j0nj0n écrit:
C'est l'occasion d'apprendreJe suis vraiment nul en programmation
Tutoriels PowerShell
Connexion ou Créer un compte pour participer à la conversation.
Temps de génération de la page : 0.044 secondes
- Vous êtes ici :
-
Accueil
-
forum
-
PowerShell
-
Entraide pour les débutants
- Lister et copier groupe AD