Windows PowerShell Scripting Primer

PowerShell Tutorial 6: PowerShell Scripting – Introduction to Script Writing


It’s time to take what we have learned and apply it to writing scripts. The plan is six new and exciting PowerShell tutorials to explain the fundamentals of the PowerShell scripting language. Here is what will be covered:

  • Variables, Constants, Arrays, and Hash Tables.
  • Using Conditional Logic.
  • Processing data with Loops.
  • Modular Scripting Using Functions.
  • Scripting using WMI Objects (Computers, Printers, Etc…).
  • Scripting using ADSI Objects (Active Directory Management).

Variables, Constants, Arrays, and Hash Tables

What’s in Tutorial 7:

  • String manipulation and concatenation.
  • Storing and Retrieving information using variables and Constants.
  • Operators and Expressions.
  • Creating, Modifying, and Combining Arrays and Hash Tables.

Conditional Logic

Tutorial 8. explains:

  • Testing conditions and running commands based on results.
  • Introduce and work with “if” and “Switch” statements.
  • Using Operators to test conditions.

Loops

Tutorial 9. gets loopy:

  • Applying “while,” “do while” and “do until” loop processing.
  • Applying “for” and “foreach” loop processing.

Modular and Dot Source Scripting using Functions

Clean up your act in Tutorial 10:

  • Organizing your code
  • Enlisting “Data Types”
  • Calling Functions from other scripts

PowerShell Scripting using WMI Objects

Tutorial 11. Oh my! WMI:

  • Concept of WMI namespaces.
  • The WMI Provider.
  • Navigating and using the WMI namespace.
  • WMI Classes.
  • Using the “Get-WmiObject” cmdlet.
  • Querying WMI.

PowerShell Scripting using ADSI Object (Active Directory Objects)

Tutorial 12. Administration without the GUI:

  • Concepts of Active Directory Objects.
  • The ADSI Provider.
  • The Active Directory namespace.
  • Creating and modifying Active Directory Objects (Users, Computers, OUs, Groups, etc…)
Email This Page To A Friend Email This Page To A Friend

Comments

By Mike Anderson on November 5th, 2007 at 5:56 am

Outstanding way of writing and explaining concepts.

Nice article. But is there a way to INCLUDE the source library files rather than pasting in the whole file each time? This would make it much easier if you wanted to make a change to a function that is called in many scripts.

Absolutely; read this article Simon, this is what you are looking for:
http://www.powershellpro.com/function-calling/144/

Jesse,

Man,if you ever write a book about PowerShell or anything IT related, I would definitely buy it. Your writing style is easy to read and follow. I can’t wait to get into the latter half of your tutorials.

Many, many thanks for putting up this site.

Rock on!

By Arlo Belshee on May 17th, 2008 at 10:57 am

Looking at your templates, it appears you don’t use source control. As you go to a modular scripting style, source control is a must. It makes deployment & file sharing easier, and it gives you full history and atomic recovery from errors.

Since this page is going to influence a lot of future IT admins, I think it’d be a good idea to mention some scm (Subversion comes to mind). And then you could remove the revision history section without losing any information. The computer tracks it all for you, and the reader doesn’t have to skip past it when he doesn’t want to see it.

By chris wood on May 28th, 2008 at 7:52 am

really good, cannot get enough. just like pie.

:-)

10/10

Is tutorial 6 still available? I only see a description of it, and the next 6 tutorials.

Thanks!

By Chandana on June 4th, 2009 at 1:15 am

Hi Jesse,

Thanks a lot to you for the content… It’s superb tutorial. I’m new to PowerShell and my basic was clear in just few hour, also the content is very interesting.. I didn’t feel bore even for a minute…

Thanks Again,
Chandana

Jesse,

Thanks for taking the time to put this stuff together. I use these tuts religiously for reference.

By Vishwas Setty on May 24th, 2010 at 9:52 am

WHERE IS THE TUTORIAL FOR THIS? NO LINKS AT ALL??

Thanks for doing this — these lessons are exactly what I needed. When people contribute useful content to the Great Library which is the internet, the world becomes a better place.

Thank you so much for these tutorials! I’m new to PowerShell, and all the hard work you’ve put into them is really contributing to my learning. Very much appreciated.

By Shantae Godboldt on March 5th, 2011 at 4:04 am

So many thanks to you for the tutorial. This is great tutorial. I am new to PowerShell and my knowledge was clear in just a couple hours, also the tutorial is very usefull.

Thoroughly enjoying playing around with Powershell thanks to your excellent tutorials. Damn fine job.

Excellent tutorial. Very much appreciated.

I’m looking at this page:

http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-scripting/

I see lots of descriptions about what’s in tutorials 7-12, but where are the tutorials themselves?

I got this error on page
http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-scripting/
————————————–
WordPress database error: [Table 'jessenha_wrdp3.wp_post2cat' doesn't exist]
SELECT cat_ID AS ID, MAX(post_modified) AS last_mod FROM `wp_posts` p LEFT JOIN `wp_post2cat` pc ON p.ID = pc.post_id LEFT JOIN `wp_categories` c ON pc.category_id = c.cat_ID WHERE post_status = ‘publish’ GROUP BY cat_ID

Warning: Cannot modify header information – headers already sent by (output started at /home1/jessenha/public_html/powershellpro/wp-includes/wp-db.php:615) in /home1/jessenha/public_html/powershellpro/wp-comments-post.php on line 88

Warning: Cannot modify header information – headers already sent by (output started at /home1/jessenha/public_html/powershellpro/wp-includes/wp-db.php:615) in /home1/jessenha/public_html/powershellpro/wp-comments-post.php on line 89

Warning: Cannot modify header information – headers already sent by (output started at /home1/jessenha/public_html/powershellpro/wp-includes/wp-db.php:615) in /home1/jessenha/public_html/powershellpro/wp-comments-post.php on line 90

Warning: Cannot modify header information – headers already sent by (output started at /home1/jessenha/public_html/powershellpro/wp-includes/wp-db.php:615) in /home1/jessenha/public_html/powershellpro/wp-includes/pluggable.php on line 868

How do I access the tutorials? All I see is this page http://www.powershellpro.com/powershell-tutorial-introduction/powershell-tutorial-scripting/
When I click on the links on the left it just takes me to a table of contents type page. Sheesh.

NOTE TO THOSE WHO ARE CONFUSED

Several people asked in the comments where tutorial 6 is, saying that they only see the table of contents.

The answer is that tutorial 6 *is* the table of contents for the scripting tutorials. As explained at the beginning, there are six scripting tutorials, numbered 7-12. The links are in the side bar in the upper right. Click on “Variables, Arrays, and Hash Tables” to begin the scripting tutorials.

Really great tutorials helping me a lot.
Thanks for sharing.

I’m also new to Powershell. I’ve followed a lot of tutorials on many subjects and this is by far one of the easiest to follow and learn from. I would rate it 10 out of 10!

By Vinay Jain on April 28th, 2013 at 11:53 pm

Simply awesome !! Thank you very much !!

By Maruti Hattarkal on May 4th, 2013 at 8:19 am

This one is the simple one.

Hi guys….I can see only the name of the tutorials..but where are they actually?? help plzzz..I can’t find the tutorials

If you go down to the tutorial 8 area and look to the left on a maximized browser
you will see power shell title bar look below that there are links there to the tutorials
http://www.powershellpro.com/powershell-tutorial-introduction/variables-arrays-hashes/

 

Leave a Comment