Powershell Tutorial For Beginners
Powershell Tutorial For Beginners
1. What is PowerShell?
Windows PowerShell is object-oriented automation engine and scripting language. It is
designed mainly for the system administrators. It helps IT, professionals, to control & automate
the administration of the Window OS and other applications.
It introduced some compelling new concepts that enable you to extend the knowledge you have
gained and the scripts that you have created within the Windows Command Prompt and
Windows Script Host environments.
It combines the flexibility of scripting, command-line speed, and the power of a GUI-based
admin tool. It allows you to solve problems efficiently by helping system admins to eliminate
future manual labor hours. We will go through all the important aspect which you should know to
learn PowerShell.
2. Why Use Powershell?
Here, are some important reason for using Powershell:
3. PowerShell History
PowerShell first version 1.0 was released in 2006. Today, PowerShell is at version 5.1. As the
year and version gone by, PowerShell's capabilities and hosting environments grew
significantly.
Let See Version wise History of Powershell:
1|Page
• PowerShell 5.0 was released as internal part of Windows management framework 5.
The feature offers in this version are remote debugging, class definitions, .NET
enumerations, , etc.
4. Features of Powershell
• PowerShell Remoting: PowerShell allows scripts and cmdlets to be invoked on a remote
machine.
• Background Jobs: It helps you to invoked script or pipeline asynchronously. You can run
your jobs either on the local machine or multiple remotely operated machines.
• Transactions: Enable cmdlet and allows developers to perform
• Evening: This command helps you to listen, forwarding, and acting on management and
system events.
• Network File Transfer: Powershell offers native support for prioritized, asynchronous,
throttled, transfer of files between machines using the Background Intelligent Transfer
Service (BITS) technology.
2|Page
6. PowerShell Cmdlet
A cmdlet which is also called Command let is a is a lightweight command used in the Window
base PowerShell environment. PowerShell invokes these cmdlets in the command prompt. You
can create and invoke cmdlets command using PowerShell APIS.
7. Cmdlet vs. Command:
Cmdlets are different from commands in other command-shell environments in the following
manners −
Cmdlets are .NET Framework class objects It can't be executed separately
Cmdlets can construct from as few as a dozen lines of code
Parsing, output formatting, and error presentation are not handled by cmdlets
Cmdlets process works on objects. So, text stream and objects can't be passed as output for
pipelining
Cmdlets are record-based as so it processes a single object at a time
Most of the PowerShell functionality comes from Cmdlet's which is always in verb-noun format
and not plural. Moreover, Cmdlet's return objects not text. A cmdlet is a series of commands,
which is more than one line, stored in a text file with a .ps1 extension.
A cmdlet always consists of a verb and a noun, separated with a hyphen. Some of the verbs
use for you to learn PowerShell is:
Get — To get something
Start — To run something
Out — To output something
Stop — To stop something that is running
Set — To define something
New — To create something
3|Page
8. PowerShell commands
Following is a list of important PowerShell Commands:
Get-Help: Help about PowerShell commands and topics
Example: Display help information about the command Format-Table
Get-Help Format-Table
4|Page
Get-Service: Finds all cmdlets with the word 'service' in it.
Example: Get all services that begin with "vm"
Get-Service "vm*"
Other Commands:
Get Module Shows packages of commands
Get Content This cmdlet can take a file and process its contents and do something with it
5|Page
Get- get Finds all cmdlets starting with the word 'get-
Example: Create a Folder
New-Item -Path 'X:\Guru99' -ItemType Directory
Output
6|Page
9. Powershell Data types:
$Error An array of error objects which display the most recent errors
$Profile Stores entire path of a user profile for the default shell
7|Page
$PID Stores the process identifier
Moreover, there is a policy which restricts script execution. You can see this policy by running
the Get-ExecutionPolicy command.
You will get one of the following output:
Restricted— No scripts are allowed. This is the default setting, so it will display first time when
you run the command.
AllSigned— You can run scripts signed by a trusted developer. With the help of this setting, a
script will ask for confirmation that you want to run it before executing.
RemoteSigned— You can run your or scripts signed by a trusted developer.
Unrestricted— You can run any script which you want to run
Steps to Change Execution Policy
Step 1) Open an elevated PowerShell prompt. Right Click on PowerShell and "Run as
Administrator"
8|Page
Step 2) Enter the Following commands
Get-ExecutionPolicy
Set-execution policy unrestricted
Enter Y in the prompt
Get-ExecutionPolicy
9|Page
13. What is PowerShell ISE?
The Windows PowerShell Integrated Scripting Environment(ISE) is the default editor for
Windows PowerShell. In this ISE, you can run commands, writer test, and debug scripts in an in
a window base GUI environment. You can do multiline editing, syntax coloring, tab completion,
selective execution and lots of other things.
Windows PowerShell ISE also allows you to run commands in a console pane. However, it also
supports panes that you can use to simultaneously view the source code of your script and
other tools which you can plug into the ISE.
You can even open up multiple script windows at the same time. This is specifically useful when
you are debugging a script which uses functions defined in other scripts or modules.
10 | P a g e
Sample 2:
The following code will give the Free Virtual Memory in your machine
Get-WmiObject -Class Win32_OperatingSystem –ComputerName localhost |
Select-Object -Property CSName,FreeVirtualMemory
11 | P a g e
14. PowerShell Concepts
Tells the cmdlet not to execute, but to tell you what would happen if the
What if
cmdlet were to run.
OutVariable Tells the cmdlet to use a specific variable to hold the output information
Instructs the cmdlet to hold the specific number of objects before calling
OutBuffer
the next cmdlet in the pipeline.
12 | P a g e
16. PowerShell Vs. Command Prompt
PowerShell considers them as objects. So the Command Prompt or even the *nix shell, the
output can be passed as an input to other output generated from a cmdlet is not just a
cmdlets through the pipeline. stream of text but a collection of objects.
13 | P a g e
Get, Start, Out, Stop, Set, New are important PowerShell commands
Boolean, Byte, Chat, Decimal, Decimal, Long are important Data Type of PowerShell
$Error. $Host, $Profile, $PID, $PSUICulture, $NULL are some special variable used in
PowerShell
The Windows PowerShell Integrated Scripting Environment(ISE) is the default editor for
PowerShell
PowerShell deeply integrates with the Windows OS whereas Command Prompt is a default
command line interface which provided by Microsoft
PowerShell has become an ideal choice for IT administrators as it eases management operation
and effort in large corporate networks
14 | P a g e