Clear-Host $MyLine = [string] $NomFichierACreer = [string] $PartieNomGroup = [string] $ADRoot = 'OU=MonOU,DC=Mondomaine,DC=Com' #Set-Variable $ADRoot -option ReadOnly function Get-ScriptDirectory { $Invocation = (Get-Variable MyInvocation -Scope 1).Value $ScriptFolderPath = Split-Path $Invocation.MyCommand.Path return $ScriptFolderPath } function CheckQuestActiveRolesADM() { #Test la présence des outils Quest $Error.Clear() Get-PSSnapin Quest.ActiveRoles.ADManagement if($Error.Count -ne 0) { Clear-Host Write-Host "`n`n`t`t ERROR - To run this script, the Quest.ActiveRoles.ADManagement must be installed and registered with Powershell." -foregroundcolor red -backgroundColor yellow Write-Host "`t`t go to the Settings menu in Powershell Plus and click on Manage Snapins." -foregroundcolor red -backgroundColor yellow break } } #Test de la présence des outils Quest CheckQuestActiveRolesADM $ObjVbScript = New-Object -ComObject MSScriptControl.ScriptControl $ObjVbScript.language = "vbscript" #Afficher une fenêtre de saisie pour récupérer le tout dans une variable $ObjVbScript.addcode("function getInput() getInput = inputbox(`"Entrez quelque-chose`",`"Saisie d une valeur`",`"`") end function" ) $PartieNomGroup = $ObjVbScript.eval("getInput") if ($PartieNomGroup.Length -igt 0){ $NomFichierACreer = "ADGroupListWith_$PartieNomGroup.txt" $EmplacementFichier = Get-ScriptDirectory $EmplacementFichier = "$EmplacementFichier\$NomFichierACreer" #Création du fichier vierge $MonFichier = New-Item -type file $EmplacementFichier -Force $MesGroupes = Get-QADGroup -name *$PartieNomGroup* -searchroot $ADRoot -sizelimit 0 foreach ($UneLigne in $MesGroupes){ add-content $MonFichier $UneLigne } Write-Host "Le résultat est dans $EmplacementFichier" } else{ Write-Host "Vous n'avez pas indiqué une partie de nom de groupe à chercher" }