Monday, October 29, 2012

Script to send HTML Formatted email of Newly Created Active Directory Users and Groups using Powershell.

Hi,

Sometime i love to run scripts manually and sometime  i like to schedule them.

 In our company we have lots of new joiners every week, and we also creates and use AD groups. In our IT team not everyone known about which users has just joined the company recently.

To ensure everyone in IT team knows about a new joiner in the company i have written a Tiny-Miny powershell script which is scheduled to run on every monday.

This script send a HTML formatted email containing the list of New AD Users and New AD groups those are created within a 7 days,.

You can download the script from this link : http://gallery.technet.microsoft.com/scriptcenter/Find-Active-Directory-26b71b73

Screenshot of the Output Email:
29-10-2012 16-54-31
You can download the script from this link : http://gallery.technet.microsoft.com/scriptcenter/Find-Active-Directory-26b71b73

Thanks
Aman Dhally
join aman on facebook Join aman on Linkedin follow aman on Twitter

Thursday, October 25, 2012

I am father Now!!!

 

Hi,

I do believe in that Life is about sharing happiness with other.

Last week on 16th October 2012  god has blessed me and my wife with a beautiful Princess.

 

IMG-20121016-00006

We haven’t decided the name yet for her, just for now we are calling her as “Princess”

Thanks

Aman Dhally

Monday, October 15, 2012

Powershell “Quotes” : Quote 1

 

Learn One Cmdlet in a Day, Keeps the IT problems away... 

Copyrighted … TM..

Open-mouthed smile

Thanks

Aman Dhally

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

Let’s select the String using Select-String in Powershell.

Hi,

In my previous post i have write a little article on how to view to see the contents of files.

As you know that i like Text files and my most of the day spent on PowerShell console so i love to do different different examples with cmdlets and command.

On my laptop i have a simple test file name as “Seen Movies.txt”, i this i mainly put the name of all movies which i have seen on my laptop and whose video files i do have stored on my NAS drive. SO when i need to get any movie i check this file to know that if i already have that movie or not. In case i have a movies entry in the file then i don’t get or purchase that Movies and if i don’t have entry of that movie then i can think of buying it if i am interested to watch that movie.

So what’s special ? “we can do the same by open the file in notepad and then we can search for that movie”.

Yes agreed but remember there are lots of way to do one thing, Smile

To check that i have that movie or not i just run a simple command.

Get-Content FILE_NAME | Select-String “Movie Name”

Using Get-content we are getting the content of the files and the we are piping the output to Select-String Cmdlet and then selecting to show the string “Avenger”

12-10-2012 00-16-01

The above command showed me that i have “The Avengers” movies in my database.

ok but what is the real use?

The real use is that you can search for specific words in log files.

Get-Content C:\Windows\Logs\CBS\CBS.log | Select-String "error"

In above command i am getting the content of C:\Windows\Logs\CBS\CBS.log  and piped them to the Select-String cmdlet and asking it match everything which contain the word “Error”

12-10-2012 00-35-39

If you want to do a search on case sensitive words then you can use -CaseSensitive parameter with Select-String cmdlet

12-10-2012 00-39-39

Simple isn’t Smile  and this is very handy and useful cmdlet Smile .

 

Thanks

Aman Dhally

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

Wednesday, October 10, 2012

View & Read File Contents Using Powershell.

Hi,

I am very busy in October and November Sad smile so you may not see much posts from me  in this time period.

We love files especially if they have TEXT,Config,XML,HTML or any other kind of files those contain Text or raw text in source.

I like Text files to store simple data, the text file are small in size and they don’t need any special program to open.

As you know i do spent a lots of time on PowerShell console and some time when i need to read any text file i have use Get-Content cmdlet.

Get-Content can read txt,inf,html,csv, xml, PS1 and lots more.

Usage of Get-content is simple.

Get-Content FILE_NAME

10-10-2012 23-23-31

and you can also read and see Powershell Script in the console using Get-Content.

10-10-2012 23-28-25

Simple Isn't Smile 

Thanks

Aman Dhally

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

Thursday, October 4, 2012

PowerShell Script to Get Static IP Address or Public IP Address of internet connection.

Hi,

In my office we have multiple internet connections.  The Alerting and monitoring already set when any of connection went down.

But sometime i need to know which Internet connection is currently working. to check which internet connection is currently working we can go to some IPCHECK sites and check the Static/Public IP Address of the Internet Connection but i want to write a simple script which can get an Static/Pubic IP Address if the internet for me.

The use of this script, you can use this in any GUI so show the current static address in any in-house WPF Powershell based custom tool.

You can incorporate it in to a any user end client script and much more.

Download Link : http://gallery.technet.microsoft.com/scriptcenter/Get-StaticPublic-IP-09d7695c

Screenshot:
04-10-2012 00-04-21
I have added the comments in the script so the script source file is quite self explanatory.

Download Link : http://gallery.technet.microsoft.com/scriptcenter/Get-StaticPublic-IP-09d7695cc

Thanks
Aman Dhally
join aman on facebook Join aman on Linkedin follow aman on Twitter

Wednesday, October 3, 2012

let’s use Get-Counter in PowerShell.

Hi,

Perfmon is one the favourites tools of all IT admins. Every IT admin love this tool and we love Powershell too.

As a Powershell users most of my time is spent on powershell tool and sometime there is a need arrive when you want to check few performance counters. and as you know i am quite lazy is doing stuffs and I think that laziness is a  path to automation

I don’t want to to pent RunBox and then type PerfMon and then click on OK and then add the performance counter which i needed.

03-10-2012 12-28-21

In performance counters i don't care about Graphs , i do care about values.

03-10-2012 12-31-20

Powershell give us a very nice and clean cmdlet to get the values of Performance counters. As i mentioned above I don’t care about the graph i do care about values and in powershell console every thing is Text and we love that texts.

To get the values of performance counter we need to use the cmdlet Get-Counter .

Lets Start.

To list all the performance counters sets use the command.

Get-Counter -ListSet *

 

This will show you the list and path of all Counter sets.

03-10-2012 12-35-29 

If you want to know what kind of Counter sets you do have in your system just piped the above command to the Select CounterSetName cmdlet

Get-Counter -ListSet * | select CounterSetName

03-10-2012 12-39-03

we can also use wildcards in -ListSet parameter. I am looking for all disk related counter sets, to search all conter sets  those have disk word in it i can use *Disk* argument in -ListSet parameter

Get-Counter -ListSet *disk*

03-10-2012 12-39-55

I am interested in counter set Logical Disk. and i can piped the above command to show me the LogicalDisk counter set only using where-Object cmdlet.

Get-Counter -ListSet *disk* | where {$_.CounterSetName -eq "LogicalDisk" }

03-10-2012 12-47-02

So now there is a little problem arise. if you want to see the detail list of counters and Paths, some how you can’t see the complete output. The whole output is truncated using … ,

03-10-2012 12-44-55

We need a list of counter to use them ,the best workaround of the above problem is to save the above command in to a variable.

$DiskCounter =  Get-Counter -ListSet *disk* | where {$_.CounterSetName -eq "LogicalDisk" }

we are saving the output of above command in to a $DiskCounter variable.

03-10-2012 12-51-37

So now if you want to see the Logical Disk Performance counter paths we can use Dot Notation now.

$DiskCounter.Paths

03-10-2012 12-54-35

if you want see the Logical Disk Counters only.

 $DiskCounter.Counter

03-10-2012 12-55-15

Of if you want to see the Logical Disk Performance Counter paths with instances with counters use.

$DiskCounter..PathsWithInstances

03-10-2012 12-56-22 

Okies Now.

I am interested in my C drive Disk Queue Length. and using $DiskCounter.PathsWithInstances i know that i have to use "\LogicalDisk(C:)\Avg. Disk Queue Length" counter.

Get-Counter -Counter "\LogicalDisk(C:)\Avg. Disk Queue Length" -SampleInterval 10

In above command we are using counter "\LogicalDisk(C:)\Avg. Disk Queue Length" to monitor the disk queue length of our C drive and using -SampleInterval  parameter we are telling to get-Counter cmdlet to collect the data for 10 seconds.

03-10-2012 13-02-37

if you want to see or monitor the counters you can use the -Continuous parameter.

Get-Counter -Counter "\LogicalDisk(C:)\Avg. Disk Queue Length" -Continuous

03-10-2012 13-05-04

That’s all for now ,, and i think now have an idea how to use it Smile 

Thanks

Aman Dhally

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