Showing posts with label Powershell v4. Show all posts
Showing posts with label Powershell v4. Show all posts

Tuesday, January 27, 2015

PowerShell : 3 Cool tips to learn PowerShell.

 

6:30 am in the morning and my phone starts ringing……

I picked up the phone and I heard the familiar voice, it is  “A Murky Ana!”

A Murky Ana : “Are you sleeping?”

Me : “Nope, was playing soccer, at 6:30 am. Come On! what peoples does at 6:30 am in the morning? They do sleep.”

A Murky Ana: “OOps, sorry to wake you up, I have a question.”

Me: “What!!!! Can’t you ask a question after 4 hours, so that I can complete my sleep ( yawning) ”

A Murky Ana: “No! answer me now!”

Me : “{… thinking.. W.T.Heck} ,  OK, give me 3 minutes, let me make Coffee first? Can I hung up the phone can call you back?

A Murky Ana: “No! I can hold “

Me : “OK, OK”

I started making coffee and after that we started the conversation again…

Me: “Ok, what is your question?”

A Murky Ana:After talking with you week before ,  I am interested in Learning PowerShell, I want to know the tips to learn PowerShell”

Me : “Ok, Pick a Pen and write  down the tricks which i am sharing with you now.”

A Murky Ana: “ Done”

Me : “ I am giving you 3 cool tips to learn PowerShell easily and quickly”

Tip 1 :  “Start using PowerShell Console, rather than “CMD”

 

You can run the native windows command on “PowerShell Console” too, PowerShell console do support most of the in-built native command, So start using the PowerShell console to get familiar with it, to know more about it’s look and feel. Stop using the CMD. You can do the same thing which you do on cmd, it's time to replace CMD with PoweShell console.

 

27-01-2015 18-27-44

TIP 2 : “Start using PowerShell Cmdlets rather than “native commands”

 

The more you use PowerShell cmdlets and the more you learn PowerShell. You can start using some basic PowerShell cmdlets and stop using the native ones. For example start using Test-Connection rather than using Ping.exe to below is the list of few command which you can use rather then the native ones.

 

Replace

With PowerShell Cmdlet

Ping

Test-Connection

Dir

Get-Childitem

Mkdir

New-Item

Cat

Get-Content

Tasklist.exe

Get-Process

Shutdown /r

Restart-Computer

net start

Start-Service

net stop

Stop-Service

 

 

 

Tip 3: “Make a new friend “Get-Help”

 

Start learning about PowerShell, the best way to learn is to start reading the ABOUT files. They have contain information about most of the PowerShell features and techniques.  Read a About file in a day and that make your PowerShell learning easy and fast.

PS C:\> Get-Help *about*

27-01-2015 19-07-59

A Murky Ana: “That’s Cool. Ok I give a try and let you know, Bye!!!!!!!”

She hung up the phone……………………………..

 

* All characters appearing in this work are fictitious (Apart from ME and the Author of the books and the online reference on the blogs). 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”.

Monday, April 21, 2014

Run your first "DSC" PowerShell Script.

 

1.       Introduction of Windows PowerShell “Desired State Configuration”

2.      Installing Windows PowerShell 4.0 [Windows Management Framework 4.0]

3.      Getting Started With Desired State Configuration: DSC Syntax

4.      Review of Desired State Configuration: The 3 easy steps.

5.      Write your First Desired State Configuration Script using ROLE Resource.

 

 

In my previous blog post we have written our first “DSC” script. 

Now it time to run that script.

Before running the script, let’s check manually if, “XPS-Viewer” and “PowerShell-ISE” are installed or not on our “Posh-Demo” server.

 

To check this, we can run Get-WindowsFeature -Name 'XPS-Viewer’, 'PowerShell-ISE’ to check if both of these applications are already installed or not.

 

You can see in the below screenshot, that these two features are not yet installed.

 

clip_image001

 

Ok, OK, you can check the “Start Menu” too for cross verification.

clip_image002

 

Happy? There are no “XPS Viewer” and “PowerShell-ISe”  installed.

 

Now, let’s back to our PowerShell ISe and run the script.

clip_image004

 

When we run the “DSC” script, it creates a folder in the Module folder (we have to change to the module folder manually, we did this in our previous blog post), and it create a MOF file for the server which we have mentioned in the NODE block inside that folder.

 The folder will be create same as the name of our Configuration file. and the MOF file created as the name of Node script block.

For example, if you have mentioned 3 nodes in the script block 'Server-1, DC-4 , File-Server', then DSC script will generate 3 files in under the same folder.

 

In our script code the name of the configuration is “myServerRoles and you can see, that script create a new folder exact as the name of the configuration NAME value.

 

16-04-2014 19-37-07

 

We can see the folder crated inside my Windows PowerShell modules folder,

 Let’s check what is inside it.

You will find the MOF file inside that folder. You should notice that, the name of the file is same as the Server name, which we provided in the NODE block.

.

16-04-2014 19-37-35

 

Cool!

Now, come back to our PowerShell-ISE again.

And run the Start-DscConfiguration cmdlet with the path to our configuration folder withwait and –verbose parameters to deploy this MOF file, this method is known and PUSH method.

 

Start-DscConfiguration .\myServerRoles -Wait -Verbose

 

16-04-2014 19-39-15

 

And you see, something is started.

16-04-2014 19-39-32

And

16-04-2014 19-39-46

It’s doing something.

16-04-2014 19-40-03

And it finishing done something.

16-04-2014 19-40-35

So, it’s finished, the script. And it’s time to verify that what Something has done?

 

I am Going to our server again and run the same command  of “Get-WindowsFeature -Name 'XPS-Viewer’, 'PowerShell-ISE’

And you can see a cute [X] in the front of “XPS Viewer” and “PowerShell ISe” J and both service are installed.

clip_image019

 

And let’s check our start menu too. And ha. It’s there, it’s there and it’s there J

 

clip_image020

 

Congratulations! We have successfully written, configured and deployed our first “DSC” Script J

 

Thanks for reading and your time, see you in my next blog posts.

 giphy

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