Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #------------------------------+
- # Build data foundation |
- # should only include relevant |
- # OU's, to speed up process |
- #------------------------------+
- $groups = Get-ADGroup -Filter *
- $GrpObjects = @()
- foreach ($grp in $groups)
- {
- $pro = @{
- 'Group' = $grp.Name
- 'Members' = Get-ADGroupMember -Identity $grp.Name
- }
- $obj = New-Object -TypeName Psobject -Property $pro
- $GrpObjects += $obj
- }
- #--------------------------------------------------+
- # This function find the grps a users is member of |
- # possible to expand this to include more stuff |
- #--------------------------------------------------+
- function find-users-grp
- {
- PARAM
- (
- [string[]]$SamAccountName
- )
- $check = @()
- foreach ($user in $SamAccountName)
- {
- try
- {
- $check += Get-ADUser -Identity $user -ErrorAction stop
- } catch{}
- }
- if ($check.Count -eq 0)
- {
- Write-Host -f Red "Users doesnt exist in AD"
- break;
- }
- foreach ($users in $SamAccountName)
- {
- $out = $GrpObjects | where {$_.Members.SamAccountName -eq $users}
- Write-Host -ForegroundColor Yellow "$users is member of"
- foreach ($item in $out)
- {
- Write-Host $item.Group
- }
- Write-Host ""
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement