Tuesday, April 14, 2015

Generate the list of IP-Addresses using PowerShell Range operator.

 

main

PowerShell Range Operator.

I was busy in writing my book on "Automating Microsoft Azure with PowerShell" that's why was not able to write blogs in previous months. I am hoping that you guys missed me ;o) . In-case if you didn't missed me, that's fine too..

Yesterday our own  "A! Murky Ana" call me late night ( she called me after a long time, and not sure where she was been, anyway...) and asked me that if it s feasible to generate  a list of address using PowerShell.

I said , YES, it is feasible, it is just a single line of code to achieve that task. You need to use the "PowerShell Range Operator". PowerShell range operator is mentioned by double dots (..)

The syntax is simple, write the range in which you want to start, this should be integer and then type two dots and the end of the range integer.

For example, if you want to create a range of numbers from 1 to 10, then you just need to type 1..10 and it will generate the list of numbers started from 1 till 10.

1

Now, let's talk about generating IP-Addresses using PowerShell. To generate a range of PowerShell IP-Addresses, we need to use two commands, one the is the range operator, and second is the Foreach-Object , and off course the pipe too, to join both commands.

1..250 | ForEach-Object {"192.168.1.$_"}

 

RangeOperator

 

In above command, we are first generating a list of range of numbers from 1-to-250 , and the we are piping the output to the Foreach-Object cmdlet, and in for each script block we are looping through every number, and then Concatenation to 192.168.1.$_ , the $_ variable is replacing by the value of the integer.

 

Simple... ;o) . No? by using a  single line of code, we have generated a list of Ip-Addresses.

 

 

Check the video of PowerShell Range Operator

 

 

tumblr_njiml4gOlY1rku136o1_500

 

* All characters appearing in this work are fictitious Any resemblance to real persons, living or dead, is purely coincidental.

 

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”.

Sunday, April 12, 2015

I am an Author now : Automating Microsoft Azure with PowerShell

 

B03747_Automating Microsoft Azure with Powershell_cov

URL : https://www.packtpub.com/virtualization-and-cloud/automating-microsoft-azure-powershell 

Life is full of surprises, and it amazes us on every step of it. Sometime it make us cry and sometime it make us laugh and sometime it let's us confused that either to laugh or to cry.

Since I have started my career, I always dream of publishing a book, I never know when it is going to happen, but i was sure that it is going to happen one day. That one day , come early as i never expected, on second week of March 2015, my first book which i written with my friend John has been published and  it's available to purchase as a print and eBook version both. When I saw this book printed, I was too happy and too sad at the same time.

This book is on managing Microsoft Azure by using PowerShell. We put lot's of effort to make this book simple and easy to understand and i am hoping  you guys are going to love it. It is available online to purchase Smile 

Please wish me all the best for the book Smile .

I would like to thanks to all the PowerShell community and my follows MVP friends those encouragements and my lovely daughter Manya Kaur, which is an inspiration and motivation for me helps me keep going and achieve this movement of proud. 

MKS

Keep dreaming guys, they do come true : A! Murky Ana.

URL : https://www.packtpub.com/virtualization-and-cloud/automating-microsoft-azure-powershell 

youre_serious_futurama

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”.

Wednesday, February 11, 2015

Microsoft Azure & PowerShell : Export the list of all "Azure VM DISK Images" list to CSV or HTML using PowerShell script.

 

How can I get a list of all “Microsoft Azure VM OS Image lists”, She asked me over the Phone.

Who? Who else! Our own “A! Murky Ana.”

I said: Yes, you can, you just need to use “Get-AzureVMImage” cmdlet , to use it just  install a “Azure PowerShell Module, and run the above cmdlet and that’s all you need to do.

A! Murky Ana. : Can we export the list of Azure VM OS DISK Images  to HTML format or in a .CSV format?

Me: Yes you can.

A! Murky Ana. : How?

Me: You just need to write a small function / script  to do that & a few tiny scripting techniques to do data manipulation.

A! Murky Ana. : Can you do it for me?

Me: No! it’s your quest, you have to deal with this.

A! Murky Ana. : Ok, let's make a deal, You show me once only , the first and the last time  to teach me how to do that, I won’t ask you again, I want to see if that kind of script we can write.

Me.: Ok, First and the last time.

I hang up the phone.

After one day, I call her and told her, did you saw the movie “Galaxy of the Guardian”?

A! Murky Ana. : No?

Me: Go a Get a DVD of it, it’s so cool movie.!

A! Murky Ana. : Don’t you suppose to show me something? A script to Export a Azure Virtual Image list to .CSV file?

Me. Yes, I know, I am sending you the screen sharing link by using http://join.me ,  See it and I will walk through a script which I have written. Please download it from the below link

https://gallery.technet.microsoft.com/Azure-Get-the-List-of-all-520816af

This is a script function, you can run the function simply by using  Export-AzureVMImageList ” than this will generate a list of all Azure Virtual Image list those are available in to a HTML page and the page will open automatically.

 

To know more about PowerShell Function, visit this link : https://technet.microsoft.com/en-us/library/hh847829.aspx  

 

1

 

 

If you want to export the Azure VM image list to the .CSV format, then just use the –CSV “Export-AzureVMImageList -CSV ” switch with the function and it will generate a .CSV file containing the same information.

 

2

Exporting the list either to .CSV or HTML is quite handy, so that you can search the name and DISK image of the OS easily which you want to create, after having a list, it’s a matter of sec milliseconds, copy and paste.,

Remember the download link: https://gallery.technet.microsoft.com/Azure-Get-the-List-of-all-520816af

This script by default export all files  in the user’s temp directory.

You can know about your temp directory by using $env:TEMP variable in the PowerShell console.

 

temp

 

Just for your knowledge, there is three main part of the this current scripts.

1.    The Switch Parameter

2.    IF Else Statement

3.    The ForEach loop

 

The Switch Parameter

 

switch

 

This works like a ON/Off switch. If you use the –CSV parameter with the function, the script set it ON ( $true) and export the Output in the CSV format.  Else it keep it in the OFF state ( $false).

 

To know more about Parameters visit this link : https://technet.microsoft.com/en-us/library/hh847743.aspx

 

The IF-ELSE  Statement

 

true-false

 

The IF block checks if the –CSV is ON or OFF, if the –CSV is present in function, then it will run the   IF block code to export the file to .CSV format, otherwise the ELSE block will run and export the file in the HTML format.

 

The ForEach loop.

 

3

By using For-Each loop , we are manipulation with data and saving it as a single line to a  variable $body1

 

That’s it J , you know the trick, Now download the script and play with it. Try to change the default path. Try to change the File Name, or try to add some new parameters.

 

Check the video below on "How you can run the script".

 

Export-AzureVmList

 

 

Me: Happy?

 

A! Murky Ana. :  Yes,

 

Me. : Go and now learn more about "Microsoft Azure and PowerShell"

 

and she hung up the phone!!!

 

HOW RUDE............

 

* All characters appearing in this work are fictitious Any resemblance to real persons, living or dead, is purely coincidental.

 z1

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”.