Book Image

Active Directory with PowerShell

By : Pamarthi Venkata Sitaram, YELLAPRAGADA U PADMAVATHI
5 (1)
Book Image

Active Directory with PowerShell

5 (1)
By: Pamarthi Venkata Sitaram, YELLAPRAGADA U PADMAVATHI

Overview of this book

Table of Contents (16 chapters)
Active Directory with PowerShell
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Getting membership of a user, computer, and group


The function used in this section will help in finding out the group membership of users, computers, or groups. The output of this function is the same as what you will see in the MemberOf tab in the object properties. This function takes two types of input. The first one is the Name parameter and it takes a list of objects for which you want to query the membership details. The second one is the Type parameter, which indicates the class of the objects that you supplied to the Name parameter:

Function Get-ADobjectMembership {
[CmdletBinding()]
param(
  [Parameter(Mandatory=$true,Position=0)]
  [string[]]$Name,
  [Parameter(Mandatory=$true,Position=1)]
  [ValidateSet("User","Group","Computer")]
  [string]$Type
)
Foreach($ObjName in $Name) {
    try {
        $MemberOf = @(Get-ADObject -Filter { Name -eq $ObjName -and ObjectClass -eq $Type} -Properties MemberOf -EA Stop | select -ExpandProperty MemberOf)
        if(!$MemberOf) {
           ...