Powershell 列出组和组的成员

Powershell 列出组和组的成员,powershell,active-directory,remote-desktop,Powershell,Active Directory,Remote Desktop,我有以下代码。。。它做了我需要它做的事情,即显示特定组及其用户的列表,但显示错误。我得到“组名”,这部分显示很好,然后我得到用户名{user1,user2…},所有其他用户都丢失了,取而代之的是点 Import-Module ActiveDirectory $US = Get-ADUser -Filter "Enabled -eq '$true'" -Property Enabled $Groups = Get-ADGroup -Filter "Name -like '*RDS Users'

我有以下代码。。。它做了我需要它做的事情,即显示特定组及其用户的列表,但显示错误。我得到“组名”,这部分显示很好,然后我得到用户名{user1,user2…},所有其他用户都丢失了,取而代之的是点

Import-Module ActiveDirectory

$US = Get-ADUser -Filter "Enabled -eq '$true'" -Property Enabled

$Groups = Get-ADGroup -Filter "Name -like '*RDS Users' -and Name -ne 'RDS 
Users'" | Select-Object -ExpandProperty Name

$Table = Foreach ($Group in $Groups)
{
    $Arrayofmembers = Get-ADGroupMember -Identity $Group -ErrorAction Stop | Select-Object Name, SamAccountName

        $compare = Compare-Object -ReferenceObject $US -DifferenceObject $Arrayofmembers -ExcludeDifferent -IncludeEqual -PassThru -Property SamAccountName -ErrorAction Stop | Select-Object Name, SamAccountName

        [pscustomobject]@{

            "Group Name" = $Group
            "Name"       = $compare.Name
            "UserName"   = $compare.SamAccountName
        }
  }
  $table

$Compare
变量似乎包含一个集合,因此这意味着
$Compare.SamAccountName
也将包含一个集合。[咧嘴笑]你需要把它弄平。。。通常的方法类似于
$Compare.SamAccountName-join';'
为您提供分号指定的字符串。set
$formatenumerationlimit=-1
。然后,文件末尾的
$table | format table-auto
,而不仅仅是
$table
,会有所帮助。无论如何,显示为表都会有限制<代码>$table |格式列表将显示所有。如果您不想要集合格式(
{item 1,item 2,item 3}
),那么您可以按照Lee_Dailey所说的去做。
$Compare
变量似乎包含一个集合,这意味着
$Compare.SamAccountName
也将包含一个集合。[咧嘴笑]你需要把它弄平。。。通常的方法类似于
$Compare.SamAccountName-join';'
为您提供分号指定的字符串。set
$formatenumerationlimit=-1
。然后,文件末尾的
$table | format table-auto
,而不仅仅是
$table
,会有所帮助。无论如何,显示为表都会有限制<代码>$table |格式列表将显示所有。如果您不想要收集格式(
{item 1,item 2,item 3}
),那么您可以按照Lee_Dailey所说的做。