Hi
I have been tasked with obtaining all our Active Directory OU's that allow users access to our shared drives. These OU's have a user in the managedby field.
Im very new to Powershell so please bear with my coding which I did below. It does a job for me but please point out if I have done anything wrong or I could do better.
There are 2 things that I would like to add
1 - Get the script to loop through all OU's rather than name them at the top individually eg Shared Admin
2 - Use the Managedby email of the person who looks after the OU
*********************************************
Import-Module ActiveDirectory -Force
"Shared Admin" |
foreach {
$group = Get-ADGroup -Identity $_ -Properties ManagedBy
Get-ADGroupMember -Identity $_ |
select @{N='GroupName'; E={$group.Name}},
@{N='ManagedBy'; E={$group.ManagedBY}},
Name, samAccountName |
Export-Csv -NoTypeInformation -Path "$($group.Name).csv"
}
$file += "c:\AD\$($group.Name).csv"
Send-MailMessage -smtpServer emailserver.domain.local -to "Me <me@domain.co.uk>", "You <you@domain.co.uk>" -from "Admin <admin@domain.co.uk>" -subject "Shared Drive Information for $($group.Name)" -Attachments $file -body "Hi.
The attchment below shows you all the people who have access to the share you look after $($group.Name)
Regards
Server Admin Team"
*****************************************
Thanks in Advance
Martyn