Exporting Users From AD Security Groups and listing variables

I’m a newbie to PowerShell and have no idea as to where and start in regards to the following task I’ve been asked to get a solution for audit purposes.

I need to export multiple security groups with its group members that must contain the following parameters

Name, User name, Email, Role, First name, Last name, Creation date

Then piping it out into a .csv format

I have no idea as to where to start with the correct cmdlets to achieve this. So any guidance will be greatly appreciated.

Many Thanks

Andrew,

Weclome to the forums.

What you’re asking for is a very common tasks and has been asked a thousand times already. And has been answered a thousand times already. :wink:

Please use your favorite search engine to search for examples for tasks like this. I’m sure you will find more than enough to get you started. Some good sources for inspiration would be either this forum here or StackOverflow or maybe the PowerShell Gallery.

If you have a particular piece of code you wrote yourself and have problems with it you’re very welcome to post this here along with a description what problem you have with it and we will be happy to try to help you.

1 Like

Hello Olaf,

Thank you for welcoming me to the forums.

Well, i have phrased this in Google and i don’t seem to comprehend or get the result i want. I also have a learning difficulty, so trying my best too in comprehending this what may be a simple task to most people :frowning:

Any leads to examples of what i wish to achieve is greatly appreciated.

That sounds like you already tried something and you’ve got some results at least. Even if it’s not exactly what you want you should start playing around with it to figure out how to use the commands you found.

You should rather start with learning the very basics of PowerShell first before you move on to some more advanced tasks. That will save you from a lot of wasted time and frustration. It’s impossible to learn a complex technology like a scripting language by guessing or by piecing together some arbitrary snippets of code you found on the internet. And you will not learn it when we write the code for you.

And … as I already wrote … if you have some self written code you’ve got stuck with you should post this code here (formatted as code please) and we will try to help you. :wink: :wink:

In all honesty, the syntax I can review and understand somewhat but it’s the cmdlets and getting them to function to work.

I assumed I would get some help of some sort.

Unfortunately, it’s like sort of tough love :frowning:

I’m trying to do my best but not getting the right parameters and not knowing the cmdlets is tiresome in itself.

Andrew,
I found the answer when I did the following google search.

Name, User name, Email, Role, First name, Last name, Creation date powershell script

The team here does a great job of providing support. They don’t do a great job of doing your job. It doesn’t pay enough.

If you will be dependent on Powershell may I recommend the following video…PowerShell For Beginners Full Course | PowerShell Beginner tutorial Full Course - YouTube

It’s long, but then again it’s a full day training. It’s not stodgy and I think it gives a great introduction to using PS.

That’s what some of us are here for. But we do not deliver ready to use code or solutions on request. You’re expected to do the basic research on your own and come up with AT LEAST A FEW LINES OF CODE!!! … when you post code please format it as code using the “preformatted text” icon ( </> )

To get you started you can read the help for the following cmdlets:

You should always read the help completely including the examples to learn how to use them.

2 Likes

Hi Dperkerson,

I’ve done a further Google Search and I am not to find this script you’d typed of as an example or where I can perhaps make a few modifications to it in order to get it to work.

As I said, I have learning difficulties and I find it very tiresome in trying new things and still not getting a result I desire.

Can you please provide the URL to this script and I can then try from there in perhaps making changes to it to achieve my output

Sure Andrew. I’ll take a look but it will be later tonight before I can give it more than 10 minutes.

I greatly appreciate this DPerkerson

That’s the same for all of us. Nevertheless you have to keep trying. That’s how we all do it.

There’s is little to no chance for you to find something perfectly fitting for your requirements. So you take something what provides you with a result some kind of near to what you’re looking for and start to tweak it. If you get stuck in this process PLEASE POST YOUR CODE and I’m sure we will be able to help you.

1 Like

Hello Olaf,

I understand good practice is always the ideal recipe.

In all honesty, I don’t find this method to be greatly encouraging at times. In fact I find it off-putting. As I’m wasting time in trying to get an output that can only be changed completely to what I started with and then still not getting the syntax and parameters used in what I need to achieve.

What other method would you prefer? At the moment you did not show any effort at all. You asked for others to do your job. I posted the basic cmdlets you need to accomplish this task. Start with reading the help. There are examples included you can use to start to play with in your environment.

As I already said, there is no easy way to learn a complex technology like PowerShell. The process of learning the basics will teach you how to find the right cmdlet and how to find and how to read the help as well.

1 Like

I have read the articles and it still doesn’t make any sense to me in how to piece together the output I want.

I will try tomorrow in giving some example of code.

And yes!!! Powershell is complex

My process of learning is seeing an existing example and then understanding the logic to where I think I can achieve my output.

Great. Thanks.

Cool. I’m honestly looking forward to it.

I totally agree. That’s why it takes a little effort in the beginning. It will get easier in the future … I promise. :wink:

So the examples included in every help topic should be your friends. :wink:

1 Like

Unfortunately the examples given still don’t make any sense to me in where or how to apply multiple OUs in one go and how to pipe out the parameters I want from them too.

I’m sorry this is very prolonged and very unnecessary in what you consider is help / guidance.

I have searched and tried but I still can’t grasp in making the syntax work

This is what I have come up with. I welcome feedback and improvements from anyone.

First, some warnings, this command could be dangerous to the performance of your AD environment. It could run amok. I don’t warranty this code but I do strongly believe in it’s abilities. If run in a large corporate environment it could take quite a while and bog down the availability of domain authentication resources. There are additions that could be made to this command to send it only to one server (if you have a dedicated DC that does that kind of thing) or to limit it by the members in a group. As written, it will export every user in the domain that is logged into when executed.

get-aduser -filter * -properties cn, samaccountname, mail, title, givenname, sn, whencreated | select cn, samaccountname, mail, title, givenname, sn, whencreated | export-csv users.csv

The command will retrieve all of the users in the active domain, return the specified properties (in addition to the normal ones), filters down to only the desired properties and then exports the list to a CSV named users.csv.

The properties selected were what I believe to be the best matches based on your request. There are more options. I found a list at this page. You would need to use the names from the column on the right to replace or add to what was provided above if you want to change any of them out.

My bill - Please watch the video I recommended above if you need to use PS as part of your career. I understand that you learn best by example, this video is just example after example. It will get you moving in the right direction and then give you the ability to show up here asking why your specific code doesn’t do what you want. :wink: :smiley:

Hello DPerkerson,

You are indeed correct, it is best to learn by example and to practice.

However i have to call the following multiple groups from one OU:

FUNC-X-CLOUD-3RDPARTY-RIPPLE-ROCK-Team
FUNC-X-CLOUD-TechDev-AgileTestLeads
FUNC-X-CLOUD-TechDev-Build-Team
FUNC-X-CLOUD-TechDev-CASCDevelopers-Team
FUNC-X-CLOUD-TechDev-DBAOps-Team
FUNC-X-CLOUD-TechDev-FAE-Admins
FUNC-X-CLOUD-TechDev-FAE-Team
FUNC-X-CLOUD-TechDev-FTPProductOwners
FUNC-X-CLOUD-TechDev-Helix-Admins
FUNC-X-CLOUD-TechDev-Helix-Team
FUNC-X-CLOUD-TechDev-IPP-Team
FUNC-X-CLOUD-TechDev-MCaaS-Team
FUNC-X-CLOUD-TechDev-OyBO-Admins
FUNC-X-CLOUD-TechDev-OyBODevelopers-Team
FUNC-X-CLOUD-TechDev-ScrumMasters-Team
FUNC-X-CLOUD-TSO-Monitoring-Team

that needs to be audited and requested the following information in this format.

Name, User name, Email, Role, First name, Last name, Creation date.

The format you’ve given is in the right direction and this is where i’m having problems in how to piece everything together :frowning: