Advertisement
Guest User

Untitled

a guest
Oct 18th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. PROCESS #This is where the script executes
  2. {
  3. $CSVReportPath= "."
  4. $path = Split-Path -parent "$CSVReportPath\*.*"
  5. $pathexist = Test-Path -Path $path
  6. $ADServer = "[REMOVED]"
  7. $SearchLoc = "[REMOVED]"
  8. If ($pathexist -eq $false)
  9. {New-Item -type directory -Path $path}
  10.  
  11. $reportdate = Get-Date -Format ssddmmyyyy
  12.  
  13. $csvreportfile = $path + "\ALLADGroups.csv"
  14. $csvreportfilemembers = $path + "\AllGroupMembers.csv"
  15.  
  16. #import the ActiveDirectory Module
  17. Import-Module ActiveDirectory
  18.  
  19. #Perform AD search. The quotes "" used in $SearchLoc is essential
  20. #Without it, Export-ADComputer returned error
  21. Get-ADGroup -server $ADServer -searchbase "$SearchLoc" -Properties * -Filter * |
  22. Select-Object @{Label = "Common Name";Expression = {$_.CN}},
  23. @{Label = "Creation Date";Expression = {$_.Created}},
  24. @{Label = "Description";Expression = {$_.Description}},
  25. @{Label = "DN";Expression = {$_.DistinguishedName}},
  26. @{Label = "Last Modified";Expression = {$_.Modified}},
  27. @{Label = "Type";Expression = {$_.ObjectClass}},
  28. @{Label = "Last Changed";Expression = {$_.WhenChanged}} |
  29.  
  30. #Export CSV report
  31. Export-Csv -Path $csvreportfile -NoTypeInformation
  32.  
  33. #Perform AD search again and export group members
  34. Get-ADGroup -server $ADServer -searchbase "$SearchLoc" -Filter * |
  35. Get-ADGroupMember |
  36. Select-Object @{Label = "Group Name";Expression = {$_.Name}},
  37. @{Label = "Member Type";Expression = {$member.objectClass}}
  38. @{Label = "Member Name";Expression = {$member.name}} |
  39.  
  40. #Export CSV report
  41. Export-Csv -NoTypeInformation -Path $csvreportfilemembers
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement