bobbai 发表于 2018-9-1 12:40:39

PowerShell 递归查询组成员

function get-member  
{
  
   
  
   
  
    )]
  
    Param
  
    (
  
      # Param1 help description
  
      [Parameter(Mandatory=$true,
  
                   ValueFromPipelineByPropertyName=$true,
  
                   ValueFromPipeline=$true,
  
                   Position=0)]
  
      
  
      $name
  
    )
  
    Begin
  
    {
  
    }
  
    Process
  
    {
  
      $a=Get-DistributionGroupMember $name -ErrorAction SilentlyContinue
  
      if($a -eq $null){
  
            return
  
      }
  
      foreach($b in $a){
  
            if (($b.Recipienttype -eq'Usermailbox') -or ($b.Recipienttype -eq 'MailContact') -or ($b.Recipienttype -eq 'User')){
  
                write-host $b.name -ForegroundColor DarkYellow
  
            }
  
            else{
  
                if($b.primarysmtpaddress -eq ""){
  
                  write-host $b.name -ForegroundColor red
  

  
                }
  
                else{
  
                  write-host $b.name -ForegroundColor Cyan
  
                  get-member $b.name
  

  
                }
  
            }
  

  
      }
  
    }
  
    End
  
    {
  
    }
  
}


页: [1]
查看完整版本: PowerShell 递归查询组成员