none
For-Each Get-ADPrincipalGroupMembership - Get Computer Name to Export-CSV RRS feed

  • Question

  • How would i to get the AD security group name and the computer name for each on my spreadsheet. 

    Right now I am only getting the group. Need the Computer Name. 

    $Get2008s = "TEXTFILEPATHHERE"

     Get-Content $Get2008s | ForEach-Object { 

        Get-ADPrincipalGroupMembership (Get-ADComputer $_) | select name | Where-Object {$_.name -like '*SCCM*' } | Sort Name

        } | 
    Export-Csv "FILEPATHHERE" -NoTypeInformation -UseCulture

    Tuesday, August 20, 2019 9:58 PM

Answers

  • You can also just do this:

    Get-Content $Get2008s |
        Get-ADComputer -pv comp |
        Get-ADPrincipalGroupMembership |
        Where-Object {$_.name -like '*SCCM*'} |
    Select-Object Name, @{n = 'Computer'; e = {$comp.Name}}


    \_(ツ)_/


    Tuesday, August 20, 2019 10:52 PM
    Moderator

All replies

  • Get-Content $Get2008s | 
        ForEach-Object{
            Get-ADPrincipalGroupMembership "$_$"
        } |
        Where-Object {$_.name -like '*SCCM*'} |
    Select Name, SamAccountName


    \_(ツ)_/


    Tuesday, August 20, 2019 10:37 PM
    Moderator
  • Get-Content $Get2008s | 
        ForEach-Object{
            Get-ADPrincipalGroupMembership "$_$"
        } |
        Where-Object {$_.name -like '*SCCM*'} |
    Select Name, SamAccountName


    \_(ツ)_/


    Thanks for the reply. The SamAccount Name column is displaying the security group name. 

    I need the Computer name in one column and the security group in another

    • Edited by Chris480602 Tuesday, August 20, 2019 10:45 PM
    Tuesday, August 20, 2019 10:43 PM
  • If you want the computer name then do this:

    Get-Content $Get2008s | 
        ForEach-Object{
            $cname = $_
            Get-ADPrincipalGroupMembership "$cname$"
        } |
        Where-Object {$_.name -like '*SCCM*'} |
        Select Name, @{n='Computer';e={$cname}}
    
    


    \_(ツ)_/

    Tuesday, August 20, 2019 10:47 PM
    Moderator
  • You can also just do this:

    Get-Content $Get2008s |
        Get-ADComputer -pv comp |
        Get-ADPrincipalGroupMembership |
        Where-Object {$_.name -like '*SCCM*'} |
    Select-Object Name, @{n = 'Computer'; e = {$comp.Name}}


    \_(ツ)_/


    Tuesday, August 20, 2019 10:52 PM
    Moderator
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    Wednesday, August 21, 2019 3:08 AM
    Moderator
  • Hi,

    Was your issue resolved?

    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.

    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.

    If no, please reply and tell us the current situation in order to provide further help.

    Best Regards,

    Lee


    Just do it.

    yes. this was resolved.
    Thursday, August 22, 2019 11:22 PM