Soldato
Lesson 1 - Basics
This is going to be very basic indeed, but I need to get some ground rules down. This lesson will cover the different ways that PowerShell can be used, and getting to grips with some of the discovery elements.
Introduction
Welcome to the School of PowerShell.
In this forum thread I will attempt to explain some basics of PowerShell. This will be aimed at users who hold sysadmin positions, and perhaps have dabbled with VBScript or Batch in the past, but want to progress to PowerShell.
PowerShell is being integrated with all major Microsoft products these days. Some more than others, for example it's very well integrated with Exchange.
I can see this trend continuing, and if you know some PowerShell, it will almost certainly make your life easier if you are working in Microsoft land.
PowerShell is very much about understanding certain principles, and also how to bend it to your will (which you will sometimes need to do!). There is usually more than one way to achieve something in PowerShell.
Opening PowerShell
Can't use if if you can't open it right?
There are a few ways to open PowerShell:
I strongly recommend number 3 as it fundamentally changes the way that the shell responds.
Shortcut pinned to the task bar looks like this:
Versions of PowerShell
PowerShell has had 3 different versions now. V1, V2, and most recently V3. I will generally cover V2 as that's the one I've used the most. V2 comes with default Windows 7 installations, which most people will be using.
You can find out what version you are running by typing $Host.version into the PowerShell window. The number under Major is your version.
If you don't have PowerShell installed you can download it from here:
http://support.microsoft.com/kb/968929
Using PowerShell
There are two ways of using PowerShell:
I will generally cover Interactive use - that is using PowerShell directly via the window. PS1 scripts have their place though. Especially if you want to configure scheduled tasks.
Tabbed completion
I'm not going to go into too much detail here, but PowerShell supports tabbed completion. That means you can begin typing a Command, Function name, File name etc and PowerShell will complete it for you.
This is great as you can discover new commands, ensure correct spelling, and also save time!
A basic command, and one I may refer to throughout these lessons, is Get-Service. This command gets the statuses of running services on the local machine.
If you begin typing the command and then hit tab, it will attempt to autocomplete the command for you.
For example typing this, then hitting tab:
Get-Ser
Autocompletes the entry for me:
Copy/Pasta
Copying and Pasting text in PowerShell is simple, but does depend on how you loaded PowerShell a little.
If you converted a CMD prompt window to PowerShell.exe then yours will work more like copying/pasting in CMD prompt.
If yours looks like mine, then it's different again. I will only cover copying/pasting in one that looks like my screenshots in this thread for now.
To copy text just left click once in the window, this starts highlighting, then drag the highlight over the text you want to copy using the mouse.
Copying text:
To complete the copy process, just Right click once, this stops the highlighting process. The text will now be copied to the clipboard.
Pasting text is as simple as Right clicking within the PowerShell Window.
In short:
Left click Copies
Right click Pastes.
Self-Help
PowerShell has an excellent self help system. I learnt just about everything I know by using the in-built help commands, or Googling to be honest.
To get help on a command simply prefix the command you want more info on with Get-Help. I normally add the -Detailed switch on the end for more detail as well.
For example this will return help info on the Get-Service command:
Get-Help Get-Service -Detailed
Running previous commands
One of the simplest, yet most useful things in PowerShell, is to be able to go back through command history and run previous commands.
You can do this in PowerShell in the same way you can with Command Prompt, by using the Up and Down arrows to cycle through commands you've run in the same session.
I'll leave it here for this lesson. Some very basic things so far, but I don't want to pile too much one one go.
This is going to be very basic indeed, but I need to get some ground rules down. This lesson will cover the different ways that PowerShell can be used, and getting to grips with some of the discovery elements.
Introduction
Welcome to the School of PowerShell.
In this forum thread I will attempt to explain some basics of PowerShell. This will be aimed at users who hold sysadmin positions, and perhaps have dabbled with VBScript or Batch in the past, but want to progress to PowerShell.
PowerShell is being integrated with all major Microsoft products these days. Some more than others, for example it's very well integrated with Exchange.
I can see this trend continuing, and if you know some PowerShell, it will almost certainly make your life easier if you are working in Microsoft land.
PowerShell is very much about understanding certain principles, and also how to bend it to your will (which you will sometimes need to do!). There is usually more than one way to achieve something in PowerShell.
Opening PowerShell
Can't use if if you can't open it right?
There are a few ways to open PowerShell:
- You can go into a normal CMD prompt and type PowerShell.exe, this will convert your CMD prompt window into a PowerShell window.
- Hit Windows Key-R to open the Run window, then type PowerShell.exe, this also opens PowerShell.
[*]My favourite one is just to bind the shortcut to my taskbar/start menu and run from there every time. You can find the shortcuts under Start Menu\Programs\Accessories\Windows PowerShell.
I strongly recommend number 3 as it fundamentally changes the way that the shell responds.
Shortcut pinned to the task bar looks like this:
Versions of PowerShell
PowerShell has had 3 different versions now. V1, V2, and most recently V3. I will generally cover V2 as that's the one I've used the most. V2 comes with default Windows 7 installations, which most people will be using.
You can find out what version you are running by typing $Host.version into the PowerShell window. The number under Major is your version.
If you don't have PowerShell installed you can download it from here:
http://support.microsoft.com/kb/968929
Using PowerShell
There are two ways of using PowerShell:
- Interactively
- Via .PS1 Scripts
I will generally cover Interactive use - that is using PowerShell directly via the window. PS1 scripts have their place though. Especially if you want to configure scheduled tasks.
Tabbed completion
I'm not going to go into too much detail here, but PowerShell supports tabbed completion. That means you can begin typing a Command, Function name, File name etc and PowerShell will complete it for you.
This is great as you can discover new commands, ensure correct spelling, and also save time!
A basic command, and one I may refer to throughout these lessons, is Get-Service. This command gets the statuses of running services on the local machine.
If you begin typing the command and then hit tab, it will attempt to autocomplete the command for you.
For example typing this, then hitting tab:
Get-Ser
Autocompletes the entry for me:
Copy/Pasta
Copying and Pasting text in PowerShell is simple, but does depend on how you loaded PowerShell a little.
If you converted a CMD prompt window to PowerShell.exe then yours will work more like copying/pasting in CMD prompt.
If yours looks like mine, then it's different again. I will only cover copying/pasting in one that looks like my screenshots in this thread for now.
To copy text just left click once in the window, this starts highlighting, then drag the highlight over the text you want to copy using the mouse.
Copying text:
To complete the copy process, just Right click once, this stops the highlighting process. The text will now be copied to the clipboard.
Pasting text is as simple as Right clicking within the PowerShell Window.
In short:
Left click Copies
Right click Pastes.
Self-Help
PowerShell has an excellent self help system. I learnt just about everything I know by using the in-built help commands, or Googling to be honest.
To get help on a command simply prefix the command you want more info on with Get-Help. I normally add the -Detailed switch on the end for more detail as well.
For example this will return help info on the Get-Service command:
Get-Help Get-Service -Detailed
Running previous commands
One of the simplest, yet most useful things in PowerShell, is to be able to go back through command history and run previous commands.
You can do this in PowerShell in the same way you can with Command Prompt, by using the Up and Down arrows to cycle through commands you've run in the same session.
I'll leave it here for this lesson. Some very basic things so far, but I don't want to pile too much one one go.
Last edited: