none
Previous object in a pipe

    Question

  • Hi,

    is it possible to get the name of the group in the table:

    Get-DistributionGroup | get-distributiongroupmember |ft alias, @{label='Test1';expression={$_.($_.name)}}

    THX and best regards

    Christian

    Thursday, June 23, 2011 6:46 AM

Answers

  • My fault.  Try this:

    foreach ($group in Get-DistributionGroup) {
    get-distributiongroupmember $group | 
     ft alias, @{label='Test1';expression={$group.name)}}
    }



    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Thursday, June 23, 2011 11:51 AM

All replies

  • The proble is that the current object in the calculated property refers to the group member and not to the group. Here's how you can do it:

     

    Hi,

    is it possible to get the name of the group in the table:

    Get-DistributionGroup | Foreach-Object{  
       $group = $_
       get-distributiongroupmember |select-object alias, @{name='Group';expression={$group.name}}

    }


    Shay Levy [MVP]
    PowerShay.com
    PowerShell Toolbar
    Thursday, June 23, 2011 7:08 AM
    Moderator
  • THX for your fast response!

    I still tested with foreach but did not get it. Also at your recommandation is one error..."unexpected token at get-distributiongroupmember"

    Get-DistributionGroup | Foreach-Object{ $group = $_ >>>> is here sth missing? <<<< get-distributiongroupmember |select-object alias, @{name='Group';expression={$group.name}}}

    Please can you check one more time?

    Christian

    Thursday, June 23, 2011 8:15 AM
  • I usually approach that problem like this:

    foreach ($group in Get-DistributionGroup) {
    get-distributiongroupmember $group |
     {ft alias, @{label='Test1';expression={$group.name)}}
    }


    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Thursday, June 23, 2011 10:33 AM
  • I get "Expressions are only permitted as the first element of a pipeline." and dont see why...

    THX

    Thursday, June 23, 2011 11:17 AM
  • My fault.  Try this:

    foreach ($group in Get-DistributionGroup) {
    get-distributiongroupmember $group | 
     ft alias, @{label='Test1';expression={$group.name)}}
    }



    [string](0..33|%{[char][int](46+("686552495351636652556262185355647068516270555358646562655775 0645570").substring(($_*2),2))})-replace " "
    Thursday, June 23, 2011 11:51 AM
  • Grrr, I also tried to change this! ...the last mistake I found myself! ;-)  ...wrong clamp at the end...

    THX to all

    Christian

    Thursday, June 23, 2011 11:56 AM
  • Hi Christian,

    I'm just getting to grips with PowerShell, and have made some modifications to the script about, but I am having trouble exporting it to csv, it says the pipeline is empty when i append | export-csv at the end.

    foreach ($group in Get-DistributionGroup) { get-distributiongroupmember $group | ft @{expression={$_.displayname};Label="$group"}}

    Any suggestions would be most welcome!

    Thanks,

    Carl

    http://OxfordSBSguy.com

    Wednesday, March 19, 2014 7:09 PM
  • Hi Carl,

    Replace Format-Table with Select-Object. If you have additional questions, you should start your own thread rather than replying to an old thread.


    Don't retire TechNet! - (Don't give up yet - 12,700+ strong and growing)

    Wednesday, March 19, 2014 7:15 PM
    Moderator
  • Thanks Mike, noted.

    I ended up using the Out-File Cmdlet. I couldn't get the Select-Object Cmdlet to return anything useful, I suspect because of the foreach Cmdlet.

    foreach ($group in Get-DistributionGroup) { get-distributiongroupmember $group | ft @{expression={$_.displayname};Label="$group"} | Out-File c:\temp\DistributionListMembers.txt -append}

    Cheers,

    Carl

    http://OxfordSBSguy.com


    Sunday, March 23, 2014 3:53 PM