Powershell today is one of the most powerfull tool for IT Pro,System Admins for lot of tasks. One of tasks that has help me a lot is a quick reports that can export from my enviroment in CSV Files and use it to easy found what i want ot give it to my Manager for any kind of Review.
Today i will focus in Export any info from Active Directory like Computers , Users, Contacts and any attributes of them like Name, Operating System , emailaddresses and save it in Csv for further use.
So let's start
- If you use Powershell Version prior to 3 you must install manual the Module of Active Directory. From version 3 and after the module autload when run the cmdlets
Import-Module ActiveDirectory
I will use the following scenarions to export Reports from Active Directory in Csv file or only print in Screen . I have in Bold the commands that you must change.
- We need to find how many contacts has in Active Directory with Name,Address and X500 Address.
Get-ADObject -LDAPFilter "(objectClass=person)" -SearchBase "OU=Contacts,DC=askme4tech,dc=local" -properties name,mail | select name,mail | export-csv "c:\powershell-reports\contacts.csv"
- We need to find the total numbers of PC'S and What Operating System Use
Get-ADObject -Filter { OperatingSystem -NotLike 'Windows Server*' } -properties name,operatingsystem |select name,operatingsystem | export-csv "c:\powershell-reports\workstations.csv"
- We need to found the Service Pack of every WorkStation
Get-ADObject -Filter { OperatingSystem -Like 'Windows Server*' } -properties name,operatingsystem,operatingsystemservicepack |select name,operatingsystem,operatingsystemservicepack | export-csv "c:\powershell-reports\Servers-Servicepack.csv"
- We need to find how many Servers we have and What Operating System Use
Get-ADObject -Filter { OperatingSystem -Like 'Windows Server*' } -properties name,operatingsystem | select name,operatingsystem | export-csv "c:\powershell-reports\workstations.csv"
- We need to found how many users have and which Organization Unit located
Get-ADUser -SearchBase "DC=askme4tech,dc=local" -Filter * -properties name,distinguishedName | select name,distinguishedName | export-csv "c:\powershell-reports\users.csv"
- We need to found the Service Pack of every Windows Server
Get-ADObject -Filter { OperatingSystem -NotLike 'Windows Server*' } -properties name,operatingsystem,operatingsystemservicepack | select name,operatingsystem,operatingsystemservicepack | export-csv "c:\powershell-reports\workstations-ServicePack.csv"
These commands are very usefull when you want something quick and up to date. Also for IT Pro and System Admins that are in new job without has any documentation from Previous IT can help a lot to take am image of Active Directory enviroment.
Now it's your turn to share what you know and how can export your Reports that you need from Active Diretory quick and up to date. Share it in our Commented System and discuss it with other IT Pro.
Have a nice weekend !!