Skip to content

Instantly share code, notes, and snippets.

@raulunzue
Last active December 12, 2020 10:09
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Powershell para extraer todos los usuarios de directorio activo de ciertos grupos a CSV
###################
### 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