locked
getting all user in groups starting with :"SAS*" using pwershell RRS feed

  • Question

  • I have some powershell

    Get-ADGroup -Filter {name -like "SAS*"} -Properties Description | Select Name

    that list all groups starting with SAS I was hoping to pipe this to a command like 

    get-adgroupmember "SAS_ENGINEERING" -recursive to list all the samAccountnames in tyhose groups so i have a list like

    user1,group1

    user1,group2

    user1,group2

    user4,group2

    any suggestions?

    I was hoping the below would work 

    Get-ADGroup -Filter {name -like "SAS*"} -Properties Description | Select Name | get-adgroupmember $_.  -recursive

    • Edited by robMerritt Monday, July 24, 2017 7:41 PM
    Monday, July 24, 2017 7:40 PM

Answers

  • got an answer at 

    http://community.idera.com/

    • Marked as answer by robMerritt Tuesday, July 25, 2017 2:38 PM
    Tuesday, July 25, 2017 2:38 PM
  • Csv file can easily be uploaded to a database.


    \_(ツ)_/

    • Marked as answer by robMerritt Tuesday, July 25, 2017 5:18 PM
    Tuesday, July 25, 2017 4:25 PM

All replies

  • Get-ADGroup -Filter {name -like 'SAS*'} | get-adgroupmember  -recursive

    You need to learn basic PowerShell.  Your guesses are not even close.

    Look in the Gallery for scripts that do what you are asking. 


    \_(ツ)_/


    • Edited by jrv Monday, July 24, 2017 7:48 PM
    Monday, July 24, 2017 7:47 PM
  • Hey thanks , how would I get the group name the the samaccountname is from in output?

    Get-ADGroup -Filter {name -like 'SAS*'} | get-adgroupmember  -recursive |select SamAccountName

    Monday, July 24, 2017 8:22 PM
  • Please see and read all of my last  response.

    \_(ツ)_/

    Monday, July 24, 2017 8:24 PM
  • I did ....what gallery?
    Monday, July 24, 2017 8:25 PM
  • http://gallery.technet.microsoft.com

    This is the repository for all user contributed scripts.


    \_(ツ)_/

    Monday, July 24, 2017 8:27 PM
  • this sort of does what i want 

    Get-ADGroup -Filter {name -like 'SAS_*'} |
    ForEach-Object {
    echo $_
    get-adgroupmember $_|select SamAccountName }|select Name,SamAccountName

    it gives

     

     sas_vido                                                                              sas_vido                                                    
                                                                                                iii073                                                        
                                                                                                iii860                                                                                                                                                         iii361        

    what i am wanting is

    sas_vido                                                                   iii073                                                               
    sas_vido                                                                   iii860                                                                      
    sas_vido                                                                   iii361                                               

                                                        

    Monday, July 24, 2017 8:39 PM
  • got an answer at 

    http://community.idera.com/

    • Marked as answer by robMerritt Tuesday, July 25, 2017 2:38 PM
    Tuesday, July 25, 2017 2:38 PM
  • Much easier to do it with PowerShell.

    Get-Process C:\scripts> Get-ADGroup -Filter { name -like 'SAS_*' } -PipelineVariable grp | 
    	Get-AdGroupMember -recursive | 
    	Select-Object @{n='Group';e={$grp.Name}},samaccountname |
    	Export-Csv grroups.csv -NoType
    All in one line of code.


    \_(ツ)_/



    • Edited by jrv Tuesday, July 25, 2017 3:49 PM
    Tuesday, July 25, 2017 3:48 PM
  • I would agree but , my end goal was to write this to SQL full script including the writing to SQL posted at 

    http://community.idera.com/powershell/using_powershell/f/77/p/24881/49262#49262

    Tuesday, July 25, 2017 4:23 PM
  • Csv file can easily be uploaded to a database.


    \_(ツ)_/

    • Marked as answer by robMerritt Tuesday, July 25, 2017 5:18 PM
    Tuesday, July 25, 2017 4:25 PM
  • hmmm you are right 
    Tuesday, July 25, 2017 5:18 PM