Powershell para extraer todos los usuarios de directorio activo de ciertos grupos a CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################### | |
### RAUL UNZUE - ELBLOGDENEGU | |
### SCRIPT POWERSHELL | |
## EXTRAER USUARIOS GRUPOS AD | |
################### | |
$groups = (Get-AdGroup -SearchBase "OU=IMPRESORAS,DC=NEGU,DC=LOCAL" -filter * | Where {$_.name -like "**"} | select name -expandproperty name) | |
$Table = @() | |
$Record = @{ | |
"Group Name" = "" | |
"Name" = "" | |
"Username" = "" | |
} | |
Foreach ($Group in $Groups) { | |
$Arrayofmembers = Get-ADGroupMember -identity $Group -recursive | select name,samaccountname | |
foreach ($Member in $Arrayofmembers) { | |
$Record."Group Name" = $Group | |
$Record."Name" = $Member.name | |
$Record."UserName" = $Member.samaccountname | |
$objRecord = New-Object PSObject -property $Record | |
$Table += $objrecord | |
} | |
} $Table | export-csv "C:\Users\raul\Desktop\usuarios-grupos.csv" -NoTypeInformation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment