PowerShell - Get all Active Directory Users with Powershell and export to CSV-File

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi thank you very much for taking your time to watch my video please before you continue to watch this video don't forget to hit the subscribe button by subscribing to my youtube channel so today i'll be discussing on how to find active directory users using power shell so let's say you have a lot of users in your active directory and you are someone who um actually love using powershell to find users so how do you find you all your active users so how do you find users in a specific organization units if for example let me just show you an example here's my active directory so here you can see i have um different organization you need to have one called kelvin i have users i have i'm admin users so how do you actually find your user users or you want to actually export these users to a csv file to an excel file so how do you find a specific group of users and export them to um to excel file to a csv file so first of all what you need to do you need to start a partial i've started powershell as an administrator so just go to your start menu here and here you can see i have the power um shell and the is e what what you need to do is to write right click on it and then go to more and then run as administrator so i prefer to actually run this as administrator because it gives me more privilege to actually use the windows power shell so first of all to actually find all users in your active directory we need to use the command which is called the get a day user so as we know type you can see that it's giving me some options which i'm just going to go for the get at the users so we're going to filter and we're going to use the filter option to filter all our users so let me just use this still and again we're going to actually go for the properties this so i'm going to go for the stairs so when i just run this command so you can see it's giving me all the users in my environment but here you can see let me just let me pause this let me stop this you can see it's giving me a lot of information actually which is of course i have the account expiration date so here you can see a lot of information and this information comes actually from your um from your properties your attributes in active directory so let me just look for a user let me use noradjancy as an example and i go to properties and here you can see the attribute here so when i remove just so here you can see all this information i can search for the um i can filter actually on all this information here displayed in the properties so if for example one actually filter the user let me just select all install specific properties so i don't get a bunch list of different attributes that i don't need so i'm going to just pipe this and enter the select property so i just want to get the given name of the user the given name and i want the surname as well and i want the display name display name so when i let me just clean my screen and let me just make this a little more so you can see more of what i'm doing so hit the wrong button again here you can see we have more information but right now i'm i'm giving the given name the song name and the display name so this is actually when you want to find all users in your um active directory which of course if you work in a company and you have like a thousand thousand users so all the users actually will be displayed here so what about if you want to as well let's search for just let me say i want to search for users in in this organizational units called active directory user so what i need to do is i will need to actually just use the get added user but i'm going to actually use the search base command where the search base so it's so you're going to ask me where am i going to search from so i'm going to search from this organizational unit so let me just go to the properties to get go to the attributes and here i'm going to get the discrete the distinguished name of the organizational unit so i'm going to copy this and then go back to my powershell here and paste it here so don't forget to actually um let me just bracket this as well and then clean here you can see i'm only getting the information based on the set base i just entered which is this organization unit so let's see um if i go back to my organizational units i just selected here you can see indeed i have um astin i have i have kelvin i have levy lotte i have test moses as well so you can see these are these are the information i actually got so but we can as well do the following i can decided to say that um i want to actually just create a different variable i want to look at a different variable and put my search base here let me just put let me just enter something like sauce i'm going to enter this let me just see if i still have the organization unit there so i'm going to make sure enter this this so my search base is going to be actually my source as well so to make this a little bit cleaner so let me just show you what i'm doing here you can see i have to get active directory users which is my search base is i've created a variable which i input this variable here so my search base is going to be my source so if i click my screen and i type it again you can see i'm still getting the same results so right now i okay i've been i have been asked by my manager to actually um send him a list of the users which are in this specific organization unit so you don't want to just copy this all this information from your screen here and send it to your manager so what you need to do is you're going to actually let me just create a variable here again i've got this user's user and and here if i enter run the script again you can see right now i'm not getting any information because this information the problem this information has been imputed into this variable called users so to actually get my information what i need to do is i'm going to run the users and here you see i get the information i need as well so to actually export this info to an um to csv file so what you need to do is you need to first of all you i will need to actually go display my variable here let me clear my screen if i run this you can see that the last command i will be run is this variable so what i need to do is right now i need to export i'm going to type pipe and then esports csv file csv file so why do i want to save the file so let me see let me go to my let me just where should i save the file i'm going to save it to my m drive i'm going to save it here so i'm going to call it let me just call it users dot cs csv and then i'm going to pull throughout my information will be displayed no type of information so uh let me just click my screen again i run the script here you can see that now i'm not getting any information because the file has been exported to this to my m drive so if i go to my m drive here you can see i have an information called users a file called user csv file so right now i don't have office installed on this windows server but if i let me just right click on edit as you can see i'm gonna have this it can be open in notepad as well you can see i have the information on the given name the s name the display name and have all the users their display name as well but we can as well let me just let me cancel this and so we can as well actually uh display more information if for example i want to display the mail of the user and see which user has an email email address and which user does not have an email address i can as well just run this and here you can see we have we can see that i'm so used some users don't have email address why some users have email address so if i want to display i want to display actually a property of a user let me just show you how you can do that quickly so what you need to do is let me just go to the property of lotte and go to properties and here we have the attributes so i want to display only attribute that has information you can see we have a lot of attributes here but not all attributes have information so i'm going to go to my filter i'm going to show only attributes that have values and here you can see my attribute has been reduced to only attribute that has value so if for example um i want to display the preferred language okay let me just see i want to display the preferred language i need to do is i will need to actually see okay the preferred language let me just type the preferred language in my um property and you can you see i'm going to get the preferred language of lotte so let me just type the preferred language let me just type that see comma then preferred things is one double arrow and then language so let me try to run this again clear my screen run and here you can see we have the preferred language which is being displayed we can see that the preferred language of lotto which is the um the nylons the nln which is dot language so it is how you can actually display the proper properties or attributes of a given user or if you want to display the attribute of all the users in the organization unit so i hope this um script can actually help you you can actually go further to actually expand this script if you want to have to get more information but for now i'm going to leave it this way and please if this video has been of any help to you don't forget to subscribe to my youtube channel for taking my time to create this video and also try and like my video to encourage me to create more video so you can as well send me an email i'll reply to you as quick as possible i'm going to leave my email in this um video link below so you can also always contact me by sending me a private email thank you very much and see you next time bye
Info
Channel: KELVGLOBAL ICT
Views: 24,765
Rating: undefined out of 5
Keywords: PowerShell - Find all Active Directory Users with Powershell and export to CSV-File., Azure Active Directory, Microsoft Intune, Microsoft office 365, Microsoft Outlook, Windows 10, powershell training, powershell lessons, Creating AD Users from CSV with Powershell | ServerAcademy.com, Powershell for Active Directory - Quering AD Data, Get ADUser information using PowerShell, Using PowerShell - Get all AD users list with created date, last changed and last login date, Get ad users
Id: 03iEweX8GA8
Channel Id: undefined
Length: 10min 52sec (652 seconds)
Published: Wed Sep 30 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.