We help IT Professionals succeed at work.
Get Started

get-adgroupmember powershell multiple lines of code

Pau Lo
Pau Lo asked
Last Modified: 2015-03-11
Hi, somebody kindly provided a powershell script for listing all groups in AD, as shown below:

$Groups = get-adgroup -filter *
foreach ($Group in $Groups) {
Get-ADGroupMember -Identity $Group | select $group, name | out-file "c:\groupmembers.csv" -append

Open in new window

However, as I am not from a powershell/scripting background, I dont really get how you run this. Some of the other scripts I have seen are "one-liners", i.e. get-aduser, where I can just copy and paste them onto the powershell console and run then, but for cipts with a few lines of code, do you have to save it as a specific file, and then "run the file"? If I add all the above to a single line of text and try executing that i get errors.
Watch Question
Exchange Experts
This problem has been solved!
Unlock 3 Answers and 3 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE