PowerShell

PowerShell for Beginners (Part 1): The Console and the First Command

Some time ago I dug deep inside myself and thought about which area is my strongest. I came to the conclusion that explaining complex things in a very simple way is one of my qualities. I’ve heard that a lot from my students. Explaining complex things in a simple way is what beginners need.

What the lecturer needs is talent, empathy and skill. Empathy is the most important thing. You need to be able to put yourself in the learner’s shoes, you need to remember how you dealt with the subject for the first time and what problems you encountered. Remember that most of the time, your students will encounter the same problems. And you need to focus on these. All these gave me the idea to write a series: PowerShell for Beginners. And this is the first part. Let’s dive in. We’ll start at the very beginning …

Why PowerShell?

When I started to notice that there is a new command line or something like that, I asked myself: Why? Why learn a new command structure now and what the hell is it for? There are many reasons:

  • IT is focusing more and more on automation
  • The significance of the graphical user interface for IT-Pros is decreasing
  • Server Core is out
  • Nano Server is out
  • IOT is coming

These things are not quite there yet. They’re coming up. You don’t really believe that administrators of the future will waste their time with creating new users graphically in an onboarding process? You won’t believe that Microsoft will consider a 12 GB operating system with a fully graphical user interface as the future? In the future, everything will revolve around automation and small and secure operating systems. This are the topics for the next years. And it affects IT-Pros as well as Developers.

That’s what I believe.

You can think of it as a natural law: The less software installed on the system, the fewer updates are needed, the fewer errors occur because less software is installed. With a graphical user interface, this is hardly feasible.

If you are satisfied with being like most of the other administrators (creating users graphically, buying a small tool for each new project) then this series is not the right one for you. If you want to be different, be more future-oriented and help your colleagues out of their dilemma ;-), stay tuned. It’s starting right now. What have we learned in this section (ok, the hint was something hidden):


PowerShell is a professional automation scripting language for Windows and  (coming up soon) Linux. Automation is the future. Therefore PowerShell is the right tool for Windows Administrators. 


Enough said. Now it’s time to come to the main part. PowerShell itsself. Let’s snuck in.

Where do I find the “new” PowerShell Console?

First of all I would like to mention that PowerShell is by no means new. But this is another thing, and there’s no room for this here. For my readers PowerShell is new and that’s what counts.

All you need is a Windows system. Later on Linux 😉 Best Windows 10 or Windows Server 2016. Why? Because PowerShell has been updated regularly in the last few years. And in this series it makes sense to use PowerShell 5.0, because I also use it. But it’s not a broken leg if you use Windows 7 or Windows 8. I try to be backwards compatible.

Windows 7 | 8 | 10

In Windows 7,8 and 10 PowerShell is something hidden and one way to find it is the built-in Windows search.

1.PNG

Open the best match and you’re in!

2.PNG

Unbenannt.PNG

Don’t worry if your screen deviates a little from mine. I’ve prepared PowerShell a little bit for my purpose. Your screen should look like this:

Unbenannt.PNG

That’s the normal behavior. When PowerShell starts the starting point is set to the user’s profile.

I recommend to pin PowerShell to your taskbar. Right click Best Match and select Pin to taskbar.

Unbenannt.PNG

Windows Server operating systems

Usually PowerShell is already stored in the taskbar of most server operating systems. If not, follow the procedure above.

Are there differences between the Server and the Client?

Yes, there are differences. When it comes to services and software Windows Server operating systems offer more PowerShell commmands. For example you can install Active Directory Domain Services only on server systems. Active Directory brings in it’s own PowerShell commands. The fact that you cannot install AD on a client operating system means that you have a greater variety of commands on Windows Servers. But there’s a little workaround which is called Remote Server Administration Tools (RSAT). Maybe we will discuss this at a later post of this series.

For my readers it is more important to know that for this part it doesn’t matter whether you are using a Windows client or a Windows server.

What have we learned so far?


PowerShell can be found by using the Windows Search. On most Windows Server operating systems PowerShell is already pinned to the taskbar. There are slight differences between PowerShell on Servers and Clients.


Customizing the console

I have decided not to write too much about this topic. There are many ways to customize the console. One way is to open PowerShell and right-click on the small upper part of the window. Select Properties. As you can see, I use enlarged fonts. This is quite helpful for the screenshots of my blog.

Unbenannt.PNG

More information can be found here:

https://technet.microsoft.com/en-us/library/ff678294.aspx

Your first command

As the headline promises, we are now going to enter and execute our first command in this first part of the series. All of you have already shut down a computer. I hope so. Well, PowerShell follows a philosophy. This philosophy will be the subject of the next contribution to the series. For now all we need to know is that there’s a verb and a noun.

For shutting down your computer the verb is stop and the noun is computer. You want to shut down your computer, which means you want to stop your computer. So the command is Stop-Computer.

And to make sure you don’t actually shut down the computer, we’ll add the parameter whatif. This ensures that the computer does not shut down, otherwise you will not be able to read this article to the end 😉

Open Windows PowerShell with administrative privileges (If you’ve followed the proposal above you’ll find PowerShell in your taskbar).

Unbenannt.PNG

Type


Stop-Computer -WhatIf

Hit Enter.

1.PNG

As you can see nothing has happend. PowerShell tells you what will happen if you shut down the computer. It will perform Stop-Computer on the localhost. By the way: The Parameter whatif is available for all commands.

What have we learned so far?


Each PowerShell command consists of a verb and a noun. Stop-Computer shuts down the computer. If you use the parameter WhatIf then the computer don’t actually shut down. WhatIf is available for all commands.


Shutting down the computer

Promise me one thing: Today when you shut down your computer, you will do it in PowerShell.


Stop-Computer -Force

The Force Parameter instructs the command to shut down the computer even other people are logged on.

Code of Practice

I already have a code of practice for my series. I will repeat this code again and again. It’s called:


Do it yourself. Anything you don’t do yourself will soon be forgotten. 


Which brings me to the next part. It’s about doing it yourself.

Exercise

The exercise up to the next part is:

Find out the parameter to ask for confirmation before shutting down the computer.

(Tip: Type Stop-Computer and then press TAB). The solution can be found in the next article, but I think you will find it out yourself 😉 Remember the code of practice!

See you next time at the article “PowerShell for Beginners (Part 2): The Philosophy Verb and Noun.


Patrick Gruenauer, MVP PowerShell

Categories: PowerShell

Tagged as: ,

17 replies »

  1. Great guides. Any chance of these in a PDF file? They would make great reading for the commute when I don’t have internet access.

    Like

  2. I want to thank you for making this and encourage you to continue the whole series. My goals which is ironic after reading your article; Is to get the same certifications as you. I have my A+, Security+ (Perfect Score) ,Net+ and have taken Unix, Linux, Novell, and Cisco in college while getting my Associate Degree in Network Engineering. I Love interacting with People and all parts Networking, but I am at a crossroads in my career where I have also seen and think there is going to be a huge change in the Network Admins by no GUI and I would love to get your Suggestions on which certifications I should get in NOW where I can stay ahead of the Curve. That is a little bit about myself if you can help with the suggestions great if not Great and Thanks again for this Free Help.
    BTW I have no more money for college just enough for online learning and books.

    Liked by 1 person

  3. Very well written guide, easy to understand and enjoyable to read. Thank you for taking the time to write this guide for beginners. Moving on the Part 2.

    Liked by 1 person

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.