Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
显示Intermedia HostPilot PowerShell的通讯组列表和成员_Powershell - Fatal编程技术网

显示Intermedia HostPilot PowerShell的通讯组列表和成员

显示Intermedia HostPilot PowerShell的通讯组列表和成员,powershell,Powershell,我仍在学习如何使用PowerShell,并尝试使用他们的Intermedia HostPilot PowerShell工具从Intermedia获取一些数据 首先,我将所有通讯组信息添加到我的$Groups数组中: $Groups = Get-DistributionGroup 我能够获得通讯组中用户的DisplayName和EmailAddress,但我无法分辨哪个用户在哪个组中: for ($i=0; $i -lt $Groups.length; $i++) { Get-Distribu

我仍在学习如何使用PowerShell,并尝试使用他们的Intermedia HostPilot PowerShell工具从Intermedia获取一些数据

首先,我将所有通讯组信息添加到我的$Groups数组中:

$Groups = Get-DistributionGroup
我能够获得通讯组中用户的DisplayName和EmailAddress,但我无法分辨哪个用户在哪个组中:

for ($i=0; $i -lt $Groups.length; $i++) 
{ Get-DistributionGroupMember -Identity $Groups[$i].DistinguishedName |
Select DisplayName, EmailAddress }
我在网上找到了下面的脚本(),这很有帮助,但在我的csv文件中仍然没有看到该组的成员,只有一个通讯组列表:

$Groups = Get-DistributionGroup
$Groups | ForEach-Object {
$group = $_.GUID
$members = ''
Get-DistributionGroupMember $group | ForEach-Object {
        If($members) {
              $members=$members + ";" + $_.GUID
           } Else {
              $members=$_.GUID
           }
  }
New-Object -TypeName PSObject -Property @{
      GroupName = $group
      Members = $members
     }
} | Export-CSV "C:\\Distribution-Group-Members.csv" -NoTypeInformation -Encoding UTF8
理想情况下,我希望有一个额外的列,显示每个用户的通讯组。大概是这样的:

DistributionGroupDisplayNameEmailAddress
会计罗伯·史密斯罗伯。smith@yahoo.com
会计约翰·昆西约翰。quincy@yahoo.com

这是我尝试过的一种变体:

for ($i=0; $i -lt $Groups.length; $i++) 
{ Get-DistributionGroupMember -Identity $Groups[$i].DistinguishedName | 
Select DisplayName, EmailAddress, $Groups[$i].DisplayName }
这只是给了我一个标题,上面有第一个通讯组的名称,如下所示:

DisplayNameEmailAddressAccounting


欢迎任何提示。谢谢

我真的不知道Intemedia HostPilot powershell命令是什么,但在普通powershell中,您可以使用类似的命令:

$DGroups = Get-ADGroup -Filter {(GroupCategory -eq "Distribution")} | select Name
Foreach ($Group in $DGroups) 
{
write-host""
write-host "Members of the >>> "$Group.Name" <<< are:"
write-host "--------"
$Users = Get-ADGroupMember $Group.Name | Select samaccountname | sort Samaccountname
Foreach ($user in $users) 
    {

    Get-ADUser -Identity $user.samaccountname -Properties * | select Name, Samaccountname, mail, displayname

    }

}
$DGroups=Get ADGroup-Filter{(GroupCategory-eq“Distribution”)}选择名称
Foreach($DGroups中的组)
{
写入主机“”

写入主机“>>”$Group.Name“的成员,$Result对象与您给出的所需格式示例相匹配,可以输出到控制台、通过管道输出到GridView或导出到CSV

$DGroups = Get-DistributionGroup
$Result = @()
foreach ( $DGroup in $DGroups ) {
    $DGroup | Get-DistributionGroupMember | Select-Object DisplayName, EmailAddress | ForEach-Object {
        $Result += [PSCustomObject]@{
            DistributionGroup = $DGroup.DisplayName
            DisplayName = $_.DisplayName
            EmailAddress = $_.EmailAddress
        }
    }
}
希望这有帮助