Link to home
Start Free TrialLog in
Avatar of Pau Lo
Pau Lo

asked on

get-adgroupmember powershell multiple lines of code

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.
ASKER CERTIFIED SOLUTION
Avatar of Hariom
Hariom
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of footech
footech
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial