Wednesday, December 17, 2014

PowerShell and Active Directory : Get the list of Active Directory Users created of a Specific Date.

 

If you are an I.T or System Administrator, then you must doing one thing for sure, getting the list of Active Directory users. Getting list of Active Directory users is very easy with PowerShell.

You just need to have “Active Directory PowerShell Module” and just shoot the Get-Aduser cmdlet. Simple!

A IT guy from Egypt ( Ahmad),  email me and ask me if he can get a list of Active Directory user that is created on a specific date? I said Yes, and then I think about to write this PowerShell Script function.

The usage of PowerShell function is very easy. Type the function name and in –Date parameter provide the Date on which you want to see if you have created any Active Directory user.

For example:

If you run the below code. It will give you list of all Active Directory User account those are created with-in 24 Hours of 17th December 2014.

 

Get-ADUserCreated -Date 12/17/2014 

 

1

Video : Video of the script usage and running.

Video of the script usage and running.

Script Download Link : https://gallery.technet.microsoft.com/Get-Active-Directory-Users-e720f7e5

Thanks for your time and reading the blog.

Regards.
Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.

Murky_ana

Monday, December 15, 2014

PowerShell Tips : Setting Requirements using #Requires.

 

This is a very cool PowerShell Tip and I am sure that you are going to love it.

There are few script which you want to Run as Administrator and you want to set dependency that the script should only works if the PowerShell console is running in a elevated /administrator mode, other wise  it should not run.

How you are going to  set this dependency? think think ... using a function? that will be complicated.. then ?

Ok!! the answer is , using #Requires

In the top of of your script, type :

#Requires -RunAsAdministrator

That's all. save the script and then try to run the script in admin mode and in normal mode and you can see the difference.

Let's see the example.

In the below script, I have added only two lines of code. , in first line we set the Dependency using #Require to execute the script only if it is running as admin.  and in the next line, we are just using the Write-Output cmdlet to write the text  "I am running as Administrator"

Let's save the script and run it.

12-12-2014 11-42-12 

I am running the script in normal windows  PowerShell console session,and you can see that it throw the error.

12-12-2014 11-40-45

Now, let's run the script in elevated mode, and you can see below, this time it run as expected, without throwing any error.

12-12-2014 11-41-29

 

12-12-2014 11-41-49

Video :  You can see the video of it.

Setting Requirements using #Requires.
There is lot's more which we can achieve using #Require. To know more about #Requires read the help
PS C:\> Get-Help About_Requires
15-12-2014 17-16-42
I have tested this in PowerShell V4.0.
Thanks for reading the blog and viewing the video.
Regards.
Aman Dhally
If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.

Murky_ana

Thursday, December 4, 2014

PowerShell Tips : Using CTRL + END Key Combination.

 

Picture1

Today’s a PowerShell Console TIP is to use the CTRL + END Key Combination. Actually these key Combinations works of DOS Console too. So these are kind of Console shortcuts.

We can use the CTRL + END key combination to remove the all text after the Cursor.

Cool! No? try it now.

Type any Long PowerShell command and bring the cursor in the middle of the text and press CTRL + END  and voila see the magic.

Please see the below video about it. Smile 

Using CRTL + END Key.

Thanks for viewing.

Aman Dhally

If you like, you can follow me on Twitter and Facebook. You can also check my “You Tube channel for PowerShell video tutorials. You can download all of my scripts from “Microsoft TechNet Gallery”.

 


Murky_ana