Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.69 KB | None | 0 0
  1. #############################################################################
  2. # PowerShell para extraer información de Active Directory. #
  3. # Se crea directorio C:\FSO y los outputs se guardan en outcommand.txt #
  4. # Informacion que extrae: #
  5. # >Numero total de usuarios #
  6. # >Numero total de maquinas #
  7. # >Numero total de servidores #
  8. # >Numero total de administradores del dominio #
  9. # >Lista de GPO's activas en el Dominio #
  10. #############################################################################
  11.  
  12. import-module ActiveDirectory #Se importa el modulo de Active Directory
  13.  
  14. #Se comprueba si existe carpeta temporal donde guardar el output. De lo contrario, se crea.
  15. if (!(Test-Path -path C:\FSO))
  16. {
  17. Write-host "------ Creando directorio temporal en C:\FSO ------"
  18. New-Item -ItemType directory -Path C:\FSO
  19. }
  20. else
  21. {
  22. Write-Host "------ El dicrectorio C:\FSO ya Existe ------"
  23. Write-Host "------ Comprobando contenido"
  24. if ((Test-Path c:\FSO\outcommand.txt) -eq $true)
  25. {
  26. Remove-Item c:\FSO\*.txt
  27. Write-Host ">>>>> Fichero temporal eliminado"
  28. }
  29. }
  30. write-host ""
  31.  
  32. "************ Escribiendo informacion de usuatios" >> c:\FSO\outcommand.txt
  33. $total_users = Get-ADUser -Filter * -SearchBase "DC=dominio,DC=com" | measure | ForEach-Object {$_.Count} #numero total de usuarios
  34. $total_computers = Get-ADComputer -Filter * -SearchBase "DC=dominio,DC=com" | measure | ForEach-Object {$_.Count} #numero total de maquinas
  35. $total_servers = Get-ADComputer -Filter {operatingsystem -like "*server*"} | measure | ForEach-Object {$_.Count} #numero total de servidores
  36. $total_admin = Get-ADGroupMember -Identity "Admins. del dominio" | measure | ForEach-Object {$_.Count} #numero total de administradores del dominio
  37.  
  38. "Usuarios totales en AD : " + $total_users >> c:\FSO\outcommand.txt
  39. "Computers totales en AD : " + $total_computers >> c:\FSO\outcommand.txt
  40. "Servers totales en AD : " + $total_servers >> c:\FSO\outcommand.txt
  41. "Admins. del Dominio en AD : " + $total_admin >> c:\FSO\outcommand.txt
  42.  
  43. " " >> c:\FSO\outcommand.txt
  44. " " >> c:\FSO\outcommand.txt
  45. #'Lista de GPOs
  46. $domain = "dominio" #Dominio del que extraer las políticas
  47.  
  48. "Listando politicas de " + $domain >> c:\FSO\outcommand.txt
  49. $gpm=New-Object -ComObject gpmgmt.gpm
  50. $constants = $gpm.GetConstants()
  51. $gpmDomain = $gpm.GetDomain($domain,$null,$constants.useanydc)
  52. $gpmSearchCriteria = $gpm.CreateSearchCriteria()
  53. $gpo=$gpmdomain.SearchGPOs($gpmSearchCriteria)
  54. if($verbose)
  55. {
  56. write-host $gpo
  57. }
  58. ELSE
  59. {
  60. foreach($ogpo in $gpo)
  61. {
  62. $hash += @{ $ogpo.ID = $ogpo.DisplayName } >> c:\FSO\outcommand.txt
  63. }
  64. format-table -inputobject $hash -autosize >> c:\FSO\outcommand.txt
  65. }
  66. exit
  67.  
  68. write-host ">>>>>> Finalizado"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement