VMware Cloud Community
Azarou
Enthusiast
Enthusiast

Script to display members of groups

Hi There,

Want to know if there is a script to display all group members of a all group of a vcenter. spent all my day finding a way with no result.

already tried this one from Lucd but no member are displayed...  My vcenter and powercli are 5.1

Get-VIPermission |
Select
@{N="VIObject";E={$_.Entity.Name}},
Role,
Principal,
@{N="Members";E={
 
if($_.IsGroup){
   
$group = Get-QADGroup $_.Principal
    $names = $group.AllMembers | %{Get-QADObject $_ | Select -ExpandProperty Name}
    [
string]::Join(',',$names)
  }}}
|
export-csv C:\processes.csv -UseCulture -NoTypeInformation

Anyone can help ?

Thx

0 Kudos
11 Replies
LucD
Leadership
Leadership

Do you have the Quest Powershell for Active Directory module installed ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Azarou
Enthusiast
Enthusiast

Yes already installed.

No members output...

0 Kudos
Azarou
Enthusiast
Enthusiast

i am asking myself.

I am admin of my vcenter but the Ad is about another team.

To execute QADcmlet does Admin right for the AD are mandatory ?

0 Kudos
LucD
Leadership
Leadership

Do you have the Get-AdUser cmdlet ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
LucD
Leadership
Leadership

If yes, try like this

Get-VIPermission |

Select @{N="VIObject";E={$_.Entity.Name}},

Role,

Principal,

@{N="Members";E={

  if($_.IsGroup){

    $group = Get-ADGroup $_.Principal.Split('\')[1] -Properties Members

    $names = $group.Members | %{Get-ADObject $_ | Select -ExpandProperty Name}

    [string]::Join(',',$names)

  }}} |

export-csv C:\processes.csv -UseCulture -NoTypeInformation


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Azarou
Enthusiast
Enthusiast

Hi,

Thanks for replies,

I have the get-aduser, but stlll the same output with the new script

Vi object role and principal  column are ok but still no members for the last...

0 Kudos
LucD
Leadership
Leadership

Just to make sure, your Principals are AD groups, not users


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Azarou
Enthusiast
Enthusiast

Yes principal column are Ad group.

Members is empty

is there another way to extrac members with powercli ?

0 Kudos
LucD
Leadership
Leadership

How do the principals look like ? domain<username ?

You will have to use an AD cmdlet to get the info from AD, no PowerCLI cmdlets for that afaik.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Azarou
Enthusiast
Enthusiast

principals looks like domaine\groups.

Ok thanks for your help

0 Kudos
LucD
Leadership
Leadership

Can you check if for a Principal like domain\groupname, the following returns the object ?

Get-ADGroup groupname


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos