Export separate domain dumps

I want to take the loop of security groups and export them according to domain.
this is what i have which gives me the list of all groups that meet the criteria however i want an export per domain such as

domain1.com.csv, domain2.com.csv and so on

$Doms = @(  
'Domain1.com'
'Domain2.com'
'Domain3.com'
'Domain4.com'
'Domain5.com'
)  
  


$Doms |%{get-qadgroup * -service $_ -groupscope 'global' -sizelimit 0 | Select-Object `
  @{n='Domain';e={ $_.Domain }},
  @{n='SamAccountName';e={ $_.samaccountname }},  
  @{n='GroupScope';e={ $_.GroupScope }},  
  @{n='GroupType';e={ $_.GroupType }},  
  @{n='Creation Date';e={ $_.WhenCreated }},  
  @{n='DN';e={ $_.DN }}  
 
  
  } | export-csv ".\GlobalExport_$Doms.csv" -notypeinformation

Open in new window

LVL 1
ntr2defAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

footechCommented:
In that case, move the Export-CSV command inside the ForEach loop.
$Doms = @(  
'Domain1.com'
'Domain2.com'
'Domain3.com'
'Domain4.com'
'Domain5.com'
)

$Doms |%{ $Dom = $_
  get-qadgroup * -service $_ -groupscope 'global' -sizelimit 0 | Select-Object `
  @{n='Domain';e={ $_.Domain }},
  @{n='SamAccountName';e={ $_.samaccountname }},  
  @{n='GroupScope';e={ $_.GroupScope }},  
  @{n='GroupType';e={ $_.GroupType }},  
  @{n='Creation Date';e={ $_.WhenCreated }},  
  @{n='DN';e={ $_.DN }}  | export-csv "$Dom.csv" -notypeinformation 
  }

Open in new window


EDIT:  However, I'm not familiar with the Quest commands, so I don't know what the -service parameter is for Get-QADGroup.  What I mentioned will only work if the Get-QADGroup command in each loop returns just the groups from the domain submitted for that loop.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ntr2defAuthor Commented:
the -service parameter tells the cmdlet which domain to look through, which in this case is the 5 different domains. moving the } to the end will cause an error:

At F:\GroupConversion\GetGroups_AllDomainsv2.ps1:31 char:4
+    | export-csv ".\$Dom.csv" -notypeinformation
+    ~
An empty pipe element is not allowed.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : EmptyPipeElement
footechCommented:
Good to know.

moving the } to the end will cause an error:
Not with the code I posted.  The pipe character has to be on the same line as the end of the Select-Object statement, or you have to use a line continuation character (`).  Standard syntax rules apply here.
ntr2defAuthor Commented:
you know what i totally overlooked that, moved it to the same line and done deal.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.