Showing posts with label Export-CSV. Show all posts
Showing posts with label Export-CSV. Show all posts

Thursday, August 16, 2012

Powershell & active directory : Find all AD users account those are created between predefined period of time.

Hi,

Reporting,Monitoring and the Documentation are few of the major tasks which most of the IT admin does like me. If you know how to do scripting it saves lots of time. For all IT guys those primarily works on Windows Platform for them i think learning of Powershell is must, because if you know Powershell you can automate or script most of the daily to daily tasks. 

Powershell is like  Swiss Army knife.

My todays task was to create a list of all active directory users account those are created within a week. It is easy but worth sharing.

Make sure you have RSAT tools installed before running the Active Directory based cmdlets.

Today is 16 August and i want to find a users those are create within a week so if we minus 7 days we got 9 August, so we want to know how many users created with-in the time period of 9th - 16 August.

Lets Start.

First we need to import Active Directory module.

Import-Module -Name ActiveDirectory 

300420122321033


Now we need to define date. The date will be sever days earlier, this is easy we just need to minus 7 days from the current date. Get-Date support a method .AddDays by which you can add or minus days.

$week = (Get-Date).AddDays(-7)

when you run the $week variable we can get a 7 days earlier date.


16-08-2012 18-58-11


Good. Now our next step is to find users. Now we are going to use Get-ADUser , and then using -Filter * to search and find all users, and we are using -Properties * so that it expand all properties of the user, and then we are piping the output to where cmdlet and then are are choosing only those users from the output who’s $_.whenCreated property is greater then or Equal to $week.

Get-ADUser -Filter * -Properties * | where { $_.whenCreated -ge $week }


We have the output now., but lets format a more little bit.


16-08-2012 19-02-03


let add more one more pipe to the command, pipe it to select Cmdlet and choose to show only, Name and When Created Property.

Get-ADUser -Filter * -Properties * | where { $_.whenCreated -ge $week } | select Name,whenCreated

Not is looks nice isn’t ?


16-08-2012 19-15-39


Powershell Script for this.



To make this task more easy , i have create a powershell script which can do this task, and the script with export all the users Name, When created to a CSV file and save that on your Desktop.


You can download the script from this link : https://dl.dropbox.com/u/17858935/AD_Users_Created_WithIn_Predifined_Perios.zip 


Thanks

Aman Dhally

join aman on facebook Join aman on Linkedin follow aman on Twitter

Thursday, August 9, 2012

Powershell & Active Directory : “Find all users Email ID’s in Active Directory Using Powershell”.

Hi,

My todays task was to create a list of our all of our “Active Directory” users email Id’s. Normally you can do this easily using download your global address list of exchange server and export in to the file.

But remember Powershell is all about automation. Now imagine, your manager told you that every fortnightly he want’s a list of all users email id so that he can use it for sending some company wise “News”. I know you don’t want to so this manually after every 15 days. So why not to automate is and save some manual task, so that we can steal some time to spend on “Facebook”  ;o).

Okies, lets start , before running any cmdlets make sure you have RSAT tools installed.

The task is simple we can use Get-Aduser and and use –Filter * to find all users, and in –Properties choose Email Address to show and then pipe output to Select-Object cmdlet and choose to display Name and Email Address in the output.

Get-ADUser -Filter *  -Properties EmailAddress  | Select Name,EmailAddress 

Okies, we got what we want,,,,But wait,,, there are few users who don’t have any Email Address and i don’t want them in to my output file, let’s filter it more.


09-08-2012 19-30-52


I have added a one more cmdlet to the command , which is Where-Object , before Selecting the object we choose to show only those users whose Email Address files in not null.

Get-ADUser -Filter *  -Properties EmailAddress  | where { $_.EmailAddress -ne  $null }  | sort  | Select Name,EmailAddress

Now we can add Export-CSV cmdlet in to the End so that we have a output stored in to a .CSV file.

Get-ADUser -Filter *  -Properties EmailAddress  | where { $_.EmailAddress -ne  $null }  | sort  | Select Name,EmailAddress | Export-Csv D:\email_ID.txt

and the output file should be look perfect like this.


09-08-2012 19-38-59


Task finished….


and have a nice day and


Happy Janmashtami Everyone :o)


krishna_animated


Thanks


Aman Dhally


join aman on facebook Join aman on Linkedin follow aman on Twitter

Monday, November 21, 2011

Find the List of Installed software using WMI and PowerShell.

 

Hi,

how you find the which software is installed on your computer, most of users answered  in “Control Panel” , yes it is right . but, if you are creating an Inventory of which system have which software then it’s not so useful for admins.

lets use WMI to retrieve the list of Install list of Softwares:

Cmdlet used: Get-WmiObject, Select-Object, Sort-Object, Export-CSV

Command is:

   1: Get-WmiObject win32_Product  | Select Name,Version,PackageName,Installdate,Vendor | Sort InstallDate -Descending

using Get-WmiObject cmdlet we query the win32_Product class which have the information of list of all software installations. Then we piped the command to Select cmdlet and we are selecting Name, Version, PackageName and installation date of the softwares and then pipe the command to Sort-Object cmdlet and sorting the result to descending order which mean latest first.


Software-1


let export the result to CSV for future reference using Export-CSV cmdlet.



   1: Get-WmiObject win32_Product  | Select Name,Version,PackageName,Installdate,Vendor | Sort InstallDate -Descending| Export-Csv d:\report.csv

 


all command is same but we piped the command further to Export-CSV cmdlet and saving the file to D:\ with name of Report.CSV


Software-2 





let see if this created a csv file .


Software-3


yes, file is created lets open it!!!


Done !!! seems good isn’t.


Software-4


 



Thanks for viewing


Aman Dhally