You are on page 1of 46

Introduction

to PowerShell
The Basics

1
• Interactive shell environment
• Rich scripting environment/language
What is
PowerShell? This combination of features extends the
capabilities of the interactive user, the script
writer, and the system administrator.

PowerShell is a task-based command-line shell and scripting language built on .NET.


PowerShell helps system administrators and power-users rapidly automate tasks
that manage operating systems (Linux, macOS, and Windows) and processes.
PowerShell commands let you manage computers from the command line.
PowerShell providers let you access data stores, such as the registry and certificate
store, as easily as you access the file system. PowerShell includes a rich expression
parser and a fully developed scripting language.
Interactive and scripting environments
The Windows Command Prompt provides an interactive shell with access to command-line
tools and basic scripting. Windows Script Host (WSH) has scriptable command-line tools
and COM automation objects, but doesn't provide an interactive shell.
PowerShell combines an interactive shell and a scripting environment. PowerShell can
access command-line tools, COM objects, and .NET class libraries. This combination of
features extends the capabilities of the interactive user, the script writer, and the system
administrator.

2
• The single most important skill a Windows
Why do we Administrator will need in the coming years
• A requirement for Microsoft certification
need to learn • Microsoft is already making servers with no GUI
PowerShell? (desktop experience)

10 reasons why you should learn to use PowerShell


1: It's not going away any time soon
Microsoft has made it clear that PowerShell is here to stay. In fact, PowerShell
version 2 is not only included in Windows Server 2008 R2 and in Windows 7, it is
enabled by default. Part of the reason why Microsoft has done this is that going
forward, many add-on products will be based on PowerShell.
2: Most Microsoft products will eventually use it
Virtually all of the server products Microsoft is producing right now can be managed
through PowerShell. From an administrative standpoint, this means that if you
become proficient in PowerShell, you will have the skill set necessary for managing
most of Microsoft's newer products. The basic built-in PowerShell commands are
used in every product that supports PowerShell. However, some server products
extend PowerShell to include additional cmdlets.
3: You can't do everything from the GUI any more
2007, it designed the GUI so that it could be used only for the most common
administrative functions. Any obscure functions or anything potentially destructive
has to be performed using PowerShell. I expect this design philosophy to carry over
to other Microsoft products.

3
4: It can make your life easier
Believe it or not, using the command line can make your life easier. Suppose for a
moment that you need to update an Active Directory attribute for a thousand users.
Performing the task manually would likely take hours to complete. Using PowerShell,
though, you can complete the task using a single line of code.
5: Many GUIs are PowerShell front ends
Many of the GUI interfaces that Microsoft has been designing for its various products
are actually front end interfaces to PowerShell. Probably the best known example of
this is the Exchange Management Console. Although this utility looks like a standard
management tool, it is built entirely on top of PowerShell. Any function you perform
through the GUI actually generates PowerShell code that completes the requested
task. In many cases, the console even shows you the PowerShell command that was
used at the completion of the task.
6: Microsoft certification exams contain PowerShell questions
Microsoft has been adding PowerShell-specific questions to many of its new
certification exams. My experience with these exams has been that you don't
necessarily have to know the full command syntax, but you do need to know which
command you should be using in a given situation.
7: You can use PowerShell commands to manage your domains
If you have domain controllers running Windows Server 2003 with Service Pack 2 or
higher, you can install the Active Directory Web Services on at least one domain
controller. After doing so, you will be able to use the Windows 7 RSAT Suite to
manage Windows 2003 and Windows 2008 domains.
8: It enables interactivity between products
PowerShell is the common thread between all the new server products Microsoft is
creating, so I expect to start seeing PowerShell used as a mechanism for providing
interactivity between server products. I have yet to see a real world example of this
interactivity, but eventually I would expect to be able to use a PowerShell script to
work seamlessly between products such as IIS, SQL Server, and Exchange.
9: Microsoft says it's important
Just because someone at Microsoft says that something is important, that doesn't
mean I take it as gospel. However, In the October 2009 issue of TechNet Magazine,
Microsoft says, "It's safe to say that the single most important skill a Windows
administrator will need in the coming years is proficiency with Windows PowerShell."
Such a bold statement is hard to ignore. This is especially true given the fact that this
statement mirrors what I've been hearing from various people at Microsoft every
time I have made a trip to Redmond lately.
10: If you don't learn it, someone else will
As we all know, the economy is in a slump, and many companies are downsizing.
Needless to say, there is a lot of competition for the few IT jobs that are available.
Therefore, if you suddenly find yourself looking for another job, your odds of finding

3
one may be better if you can list PowerShell among your skill set.
https://www.techrepublic.com/blog/10-things/10-reasons-why-you-should-learn-to-
use-powershell/

3
Is PowerShell just another Command Prompt?

cmd.exe PowerShell
• command shell based on the MS-DOS • a more modern and powerful command-
operating system line environment to manage Windows
• provides an environment to run • PowerShell commands, or cmdlets, help
applications and various utilities; output you manage your Windows infrastructure
is displayed in the same window • enable a user to access the registry, the
• Allows access to the file system, but not file system and Windows Management
parts of Windows, like the Registry Instrumentation (WMI) space on systems
• create and edit scripts and save them to remotely
batch files to solve automation tasks in • enables you to create complex scripts
one-system with multiple conditions
• never intended for remote system
administration

The Windows Cmd / Command-Line shell is NOT being removed from Windows in
the near or distant future!

The Cmd shell remains an essential part of Windows, and is used daily by millions of
businesses, developers, and IT Pro’s around the world.
In fact:
Much of the automated system that builds and tests Windows itself is a collection
of many Cmd scripts that have been created over many years, without which we
couldn’t build Windows itself!
Cmd is one of the most frequently run executables on Windows with a similar
number of daily launches as File Explorer, Edge and Internet Explorer!
Many of our customers and partners are totally dependent on Cmd, and all it’s
quirks, for their companies’ existence!
In short: Cmd is an absolutely vital feature of Windows and, until there’s almost
nobody running Cmd scripts or tools, Cmd will remain within Windows.
https://devblogs.microsoft.com/commandline/rumors-of-cmds-death-have-been-greatly-
exaggerated/

4
Command Prompt vs PowerShell

5
• Systems are more complex
• You can’t do everything from the GUI
anymore
• Too much work for humans to click on GUIs on
Why do we multiple servers in multiple locations to
accomplish a task
NEED • Large-scale fast management is needed
(same task done on 100 servers in multiple
PowerShell? locations)
• Automates redundant tasks
• Using scripts to automate tasks reduces
human error and saves time

6
PowerShell – Interactive Shell Environment

Unlike most shells, which accept and return text, Windows PowerShell is built on
top of the .NET Framework common language runtime (CLR) and the .NET
Framework, and accepts and returns .NET Framework objects. This fundamental
change in the environment brings entirely new tools and methods to the
management and configuration of Windows.

Like many shells, Windows PowerShell gives you access to the file system on the
computer. In addition, Windows PowerShell providers enable you to access other
data stores, such as the registry and the digital signature certificate stores, as easily
as you access the file system.

7
PowerShell – Scripting Language/Environment

• Scripts are text files that contain a


collection of commands
• Save with a .PS1 extension
• Commands are executed in
sequence
• Can perform one or more actions
• PowerShell cmdlets are single
function scripts

The screen you see in the slide is Windows PowerShell ISE.


The Windows PowerShell ISE

The Windows PowerShell Integrated Scripting Environment (ISE) is a host


application for Windows PowerShell. In the ISE, you can run commands and write,
test, and debug scripts in a single Windows-based graphic user interface. The ISE
provides multiline editing, tab completion, syntax coloring, selective execution,
context-sensitive help, and support for right-to-left languages. Menu items and
keyboard shortcuts are mapped to many of the same tasks that you would do in the
Windows PowerShell console. For example, when you debug a script in the ISE, you
can right-click on a line of code in the edit pane to set a breakpoint.

Scripts
A script is just a collection of commands saved into a text file (using the .ps1
extension) that PowerShell can understand and execute in sequence to perform one
or multiple actions. Scripts can be written in plain text using a text editor, like
NotePad.

8
What do we
mean by
“Object-
Oriented”?
• What is an “object”?
• An object is a single element, and all of the information related to
that element, including properties, data and code.
• Command prompt output is text-based while output in PowerShell is an
object.
• Why is this powerful?
• the output of a PowerShell command (the object) can be piped into
another command without additional programming

The basic difference, traditional command prompt output is text-based while output in
PowerShell is not. It looks like text but it is actually an object. Why is this powerful?
Because the output of a PowerShell command (the object) can be piped into another
command without additional programming. With traditional scripting, if you wanted to use
the output of one command in another, additional programming would be required to
manipulate the data in a format the second command could understand.

What is an object?
In Windows, Active Directory stores data as objects. An object is a single element, such as a
user, group, application or device, such as a printer. Objects are normally defined as either
resources -- such as printers or computers -- or security principals -- such as users or
groups.
Active Directory categorizes objects by name and attributes. For example, the name of a
user might include the name string, along with information associated with the user, such
as passwords and Secure Shell (SSH) keys.

With PowerShell we can interact with these objects to enumerate information (object-
properties) and/or create, modify, or delete objects and/or object-properties (object-
methods).

9
https://en.wikipedia.org/wiki/Object_(computer_science)
In computer science, an object can be a variable, a data structure, a function, or a method,
and as such, is a value in memory referenced by an identifier. In the class-based object-
oriented programming paradigm, object refers to a particular instance of a class, where the
object can be a combination of variables, functions, and data structures. In relational
database management, an object can be a table or column, or an association between data
and a database entity (such as relating a person's age to a specific person).

Object (computer science)


From Wikipedia, the free encyclopedia
Jump to navigation Jump to search In Object-oriented programming, an object is an instance
of a Class. Objects are an abstraction. They hold both data, and ways to manipulate the data.
The data is usually not visible outside the object. It can only be changed by using a well-
specified mechanism (usually called interface).
Suppose there is a bank account; this bank account has a current balance, but it also has a
history of things that were done. These fields are however not directly accessible. There are
methods like deposit() and withdraw() and checkBalance(). Most applications (and other
objects) only change this object through this interface.
Banks usually impose a credit limit. Suppose, there are 1000 dollars on the account. If the
client does not have a special agreement with the bank, he cannot take out more money
than there is on the account; so he can withdraw() a maximum of 1000 dollars. He might
have an agreement with the bank, so he can borrow money from the bank (but has to pay a
fee). In that case, he might be able to withdraw 1500 dollars (or 2000 dollars). So the
withdraw method has to do a lot of checks as described above. The account manager might
see the account differently, she might have methods to set the maximum amount that can
be taken out of the account, or to set the fee or interest rate that the customer has to be pay
for the money borrowed.
As an object is an instance of a class; it has certain things from that class. It can perhaps be
compared to other objects of that class. Two apples, one red and bigger, the other green and
smaller. On the other hand: It is not that easy to compare different objects. A green apple
does not have much in common with a steel wrench.

9
What is the .NET Framework?
• .NET is a programming framework
created by Microsoft that
developers can use to create
applications more easily
• Contains pieces of code that
developers can use to include
common functions in their
applications, leaving them to focus
on what is unique in their
application
• Helps applications have a standard
look and feel

The .NET Framework, Explained


The name “.NET Framework” itself is a bit of a misnomer. A framework (in
programming terms) is really a collection of Application Programming Interfaces
(APIs) and a shared library of code that developers can call when developing
applications, so that they don’t have to write the code from scratch. In the .NET
Framework, that library of shared code is named the Framework Class Library (FCL).
The bits of code in the shared library can perform all kinds of different functions.
Say, for example, a developer needed their application to be able to ping another IP
address on the network. Instead of writing that code themselves, and then writing
all the little bits and pieces that have to interpret what the ping results mean, they
can use code from the library that performs that function.
And that’s just one tiny example. The .NET Framework contains tens of thousands of
pieces of shared code. This shared code makes the lives of developers much easier
because they don’t have to reinvent the wheel every time their applications need to
perform some common function. Instead, they can focus on the code that’s unique
to their applications and the user interface that ties it all together. Using a
framework of shared code like this also helps provide some standards between
applications. Other developers can make sense of what a program is doing more

10
easily and users of the applications can count on things like Open and Save As dialog
boxes working the same in different applications.
https://www.howtogeek.com/253588/what-is-the-microsoft-net-framework-and-
why-is-it-installed-on-my-pc/

10
Windows PowerShell 5.1
PowerShell
Version
1.0 For use with Windows XP SP2, Vista and Windows Server 2003 SP1, optional for Server 2008
2.0 Windows 7 and Windows Server 2008
3.0 Windows 8 and Windows Server 2012
4.0 Windows 8.1 and Windows Server 2012 R2
5.0 Windows Management Framework (WMF) 5.0
5.1 Released with Windows 10 Anniversary Update and Windows Server 2016 (WMF 5.1)
6.0 PowerShell Core – multi-platform support (Windows,Linux, MacOS) .NET Core Framework
6.1 Compatible with 1900+ existing cmdlets in Windows 10 and Windows Server 2019
6.2 Performance enhancements and updates
7.0 Planned as a replacement for Windows PowerShell 5.1 and all PowerShell 6
*became generally available for download on March 4, 2020

Windows PowerShell 5.1 includes significant new features that extend its use,
improve its usability, and allow you to control and manage Windows-based
environments more easily and comprehensively.
Windows PowerShell 5.1 is backward-compatible. Cmdlets, providers, modules,
snap-ins, scripts, functions, and profiles that were designed for Windows
PowerShell 4.0, Windows PowerShell 3.0, and Windows PowerShell 2.0 generally
work in Windows PowerShell 5.1 without changes.

Windows PowerShell 5.1 is installed by default on Windows Server 2016 and


Windows 10. To install Windows PowerShell 5.1 on Windows Server 2012 R2,
Windows 8.1 Enterprise, or Windows 8.1 Pro, see Install and Configure WMF 5.1. Be
sure to read the download details, and meet all system requirements, before you
install Windows Management Framework 5.1.

PowerShell 5.1 is the last supported Windows PowerShell version.


As of March 4, 2020:
https://devblogs.microsoft.com/powershell/announcing-powershell-7-0/

11
PowerShell 5.1

12
Upgrading to PowerShell 5.1
• Windows 10 Anniversary Update (May 2019) and Windows Server
2016 (or later OSs) will already have Windows PowerShell 5.1
• Download and install the .NET Framework 4.8 and Windows
Management Framework 5.1 from the Microsoft Download Center.
• Windows Management Framework 5.1
• an installation package that includes Windows PowerShell 5.1 and Windows
Remote Management (WinRM) 3.0

https://dotnet.microsoft.com/
https://www.microsoft.com/en-us/download/details.aspx?id=54616

https://docs.microsoft.com/en-us/dotnet/framework/install/on-windows-8-1
https://docs.microsoft.com/en-us/skypeforbusiness/set-up-your-computer-for-windows-
powershell/download-and-install-windows-powershell-5-1

https://docs.microsoft.com/en-us/powershell/wmf/overview

13
What is PowerShell Core?
(PowerShell 6)
• Open-source, sanctioned by Microsoft
• Currently missing many Windows-specific
cmdlets and modules
• Microsoft is going to keep working on
PowerShell Core and one day its
capabilities will meet or exceed those of
Windows PowerShell
• Only the most recent release of PowerShell
6 is supported
• PowerShell Core is multiplatform
• Windows, MacOS, and Linux
• Based on the .NET Core Runtime

PowerShell Core 6.0[edit]


PowerShell Core 6.0 was first announced on 18 August 2016, when Microsoft
unveiled PowerShell Core and its decision to make the product cross-platform,
independent of Windows, free and open source.[5] It achieved general availability on
10 January 2018 for Windows, macOS and Linux.[85] It has its own support lifecycle
and adheres to the Microsoft lifecycle policy that is introduced with Windows 10:
Only the latest version of PowerShell Core is supported. Microsoft expects to
release one minor version for PowerShell Core 6.0 every six months.[86]
The most significant change in this version of PowerShell is the expansion to the
other platforms. For Windows administrators, this version of PowerShell is devoid of
any major new features. In an interview with the community on 11 January 2018,
the PowerShell team was asked to list the top 10 most exciting things that would
happen for a Windows IT professional who would migrate from Windows
PowerShell 5.1 to PowerShell Core 6.0; in response, Angel Calvo of Microsoft could
only name two: cross-platform and open-source.[87]
PowerShell Core 6.1[edit]
Compatibility with 1900+ existing cmdlets in Windows 10 and Windows Server
2019[88]

14
Built on top of .NET Core 2.1
Support for the latest versions of Windows, macOS, and Linux
Significant performance improvements
Markdown cmdlets
Experimental feature flags
PowerShell Core 6.2[edit]
The PowerShell Core 6.2 release is focused primarily on performance improvements,
bug fixes, and smaller cmdlet/language enhancements that improve the quality of life
for users.[89]
https://en.wikipedia.org/wiki/PowerShell

If you are interested in the PowerShell Core open source community, see:
https://github.com/PowerShell/PowerShell

14
Customize Your PowerShell Experience

Customize PowerShell to your liking.


Adjusting the Font and size, colours and layout, can make your PowerShell experience
easier and more enjoyable.
Select a font, font size, and colour that allows you to see all characters and symbols clearly.
Under “Layout”, ensure your Screen Buffer Size width and Window Size are the same to
ensure lines of output are not being truncated.

https://docs.microsoft.com/en-us/powershell/scripting/samples/appendix-2---creating-a-
custom-powershell-shortcut?view=powershell-5.1
Appendix 2 - Creating a Custom PowerShell Shortcut
06/04/2017
2 minutes to read
Contributors
The following procedure describes how to create a shortcut to Windows PowerShell that
has several convenient options customized.
Create a shortcut that points to Powershell.exe.
Right-click the shortcut, and then click Properties.
Click the Options tab.
In the Edit Options section, select the QuickEdit check box.
This setting lets you select text in the Windows PowerShell console window by dragging the

15
left mouse button, and it lets you copy text to the clipboard by pressing ENTER or by right-
clicking the mouse.
In the Edit Options section, select the Insert Mode check box. This setting lets you right-click
in the console window to automatically paste text from the clipboard.
In the Command History section, type or select a number between 1 and 999 in the Buffer
Size box. This sets the number of typed commands that will be kept in the console buffer.
In the Command History section, select the Discard Old Duplicates check box to eliminate
repeated commands from the console buffer.
Click the Layout tab.
In the Screen Buffer section, type a number between 1 and 9999 in the Height box. The
height represents the number of lines of output that are buffered. This is the maximum
number of lines retained for viewing when you scroll through the console window. If this
number is lower than the height shown in the Window size section, the window size height
will automatically be reduced to the same value.
In the Window Size section, type a number between 1 and 9999 for the width. This
represents the number of characters that are displayed across the console window. The
default width is 80, and Windows PowerShell's output formatting is designed for this width.
If you want to place the console at a particular point on the desktop when it is opened, clear
the Let system position window check box in the Window position section, and then
change the values in the Left and Top boxes in the Window position section.
Click OK.

https://www.lynda.com/PowerShell-tutorials/Customizing-PowerShell-
comfort/189402/369662-4.html

15
How to run
PowerShell:

PowerShell can be run as a regular user (non-administrator), but typically we would Run as
Administrator.
Do not use any of the (x86) options as they are 32 bit and we are using 64 bit versions of
Windows.
Windows PowerShell ISE is the Integrated Scripting Environment, used for writing and
running scripts.

You can right+click on any option and choose to Pin it to the start menu or taskbar

16
Cmdlets -pronounced “command-lets”
• PowerShell commands
• A script that performs a single function
• consist of two words — a verb and a noun
• Makes commands easier to learn by using English-like language
For example, “Get-Help” cmdlet displays help about Windows PowerShell
cmdlets and concepts
• Cmdlets can be grouped and used for writing advanced scripts

Cmdlets are specialized commands in the PowerShell environment that implement


specific functions. These are the native commands in the PowerShell stack. Cmdlets
follow a Verb-Noun naming pattern, such as Get-ChildItem, helping to make them
self-descriptive.[25] Cmdlets output their results as objects and can also receive
objects as input.
https://en.wikipedia.org/wiki/PowerShell

17
PowerShell is Case INSensitive
Get-ChildItem = get-childitem = geT-childiteM
• Capitalization is for readability only
• There are a few exceptions that you might encounter, mostly in more
complex commands or scripts

PowerShell is case insensitive, unless it matters. There are some instances where case will
matter. For example: if you are comparing strings of text, and a few Windows variables are
case sensitive. We are very unlikely to come across case sensitivity in the material being
covered in IOS110.

18
Cmdlet Verb-Noun Structure

VERB NOUN
-express specific actions in -describe specific types of objects
PowerShell that are important in system
administration
Get - Process
Stop - Process
Get - Date
Stop - Computer

Cmdlets use verb-noun names to reduce command memorization


PowerShell uses a "verb-noun" naming system. Each cmdlet name consists of a
standard verb hyphenated with a specific noun. PowerShell verbs are not always
English verbs, but they express specific actions in PowerShell. Nouns are very much
like nouns in any language. They describe specific types of objects that are
important in system administration. It's easy to demonstrate how these two-part
names reduce learning effort by looking at a few examples.
PowerShell has a recommended set of standard verbs. Nouns are less restricted, but
always describe what the verb acts upon. PowerShell has commands such as Get-
Process, Stop-Process, Get-Service, and Stop-Service.
For this example of two nouns and verbs, consistency does not simplify learning
that much. Extend that list to a standardized set of 10 verbs and 10 nouns. Now you
only have 20 words to understand. But those words can be combined to form 100
distinct command names.
It's easy to understand what a PowerShell command does by reading its name. The
command to shut down a computer is Stop-Computer. The command to list all
computers on a network is Get-Computer. The command to get the system date
is Get-Date.

19
https://docs.microsoft.com/en-us/powershell/scripting/learn/learning-powershell-
names?view=powershell-5.1

19
Get a list of VERBS

This slide shows us the command to list all of the available VERBS that can be used in
cmdlets.

20
Common Cmdlet Verbs
VERB DESCRIPTION VERB DESCRIPTION
Adds a resource to a container, or
attaches an element to another
Add element. Move Moves a resource.
Removes all elements from a
Clear container. New Creates a new resource.
Copies a resource to another name or
Copy container. Push Puts an item onto the top of a stack.
Get Retrieves data. Pop Removes an item from the top of a stack.
Hide Makes a display not visible. Remove Removes a resource from a container.
Join Joins a resource. Rename Gives a resource a new name.
Finds a resource (or summary information
Lock Locks a resource. Search about that ...

21
Use Get-Command to list all cmdlets

22
Use Verb parameter to get a list of commands
for verb Add

In this slide we are seeing all of the cmdlets that start with the verb “Add”.

23
Use the Noun parameter to see a list of commands
that affect the same type of object.

In this slide we are seeing all cmdlet that relate to the computer object.

24
Getting started with familiar commands:
Aliases
• A tool that allows users to bridge
the gap from previous languages
to PowerShell
• Built-in aliases are available for
Linux and Windows Command
Prompt users to allow them to
get started quickly
• We can create our own aliases to
simplify cmdlets

Using familiar command names

PowerShell supports aliases to refer to commands by alternate names. Aliasing


allows users with experience in other shells to use common command names that
they already know for similar operations in PowerShell.
Aliasing associates a new name with another command. For example, PowerShell
has an internal function named Clear-Host that clears the output window. You can
type either the cls or clear alias at a command prompt. PowerShell interprets these
aliases and runs the Clear-Host function.
This feature helps users to learn PowerShell. First, most cmd.exe and Unix users
have a large repertoire of commands that users already know by name. The
PowerShell equivalents may not produce identical results. However, the results are
close enough that users can do work without knowing the PowerShell command
name. "Finger memory" is another major source of frustration when learning a new
command shell. If you have used cmd.exe for years, you might reflexively type
the cls command to clear the screen. Without the alias for Clear-Host, you receive
an error message and won't know what to do to clear the output.
https://docs.microsoft.com/en-us/powershell/scripting/learn/using-familiar-command-

25
names?view=powershell-5.1

25
Windows Command Prompt and Unix
commands that you can use in PowerShell:
cat dir mount rm

cd echo move rmdir

chdir erase popd sleep

clear h ps sort

cls history pushd tee

copy kill pwd type

del lp r write

diff ls ren

26
What cmdlet am I really using?

This command will show you which PowerShell command you are actually running when
you type the Alias.

27
Cmdlet name Alias
Get-Item gi
Common Set-Item si
Built-in Get-Location gl
PowerShell
Aliases Set-Location sl

Get-Command gcm

Get-Alias gal

These aliases are not related to Windows Command Prompt or Linux commands, but are
actually aliases created to simplify the use (reduce typing) of commonly used cmdlets.

Although the aliases are available and reduce typing, it is highly recommended that while
you are learning the PowerShell cmdlets, you use the full commands until you become
proficient.

28
How do I find existing Aliases for a cmdlet?

29
Make your own aliases:
You can create your own aliases using the Set-Alias command. The
following statements create the aliases from the previous screen:

Set-Alias -Name gi -Value Get-Item


Set-Alias -Name si -Value Set-Item
Set-Alias -Name gl -Value Get-Location
Set-Alias -Name sl -Value Set-Location
Set-Alias -Name gcm -Value Get-Command

30
How do I save my custom aliases?
• Aliases that you create are only available in your current session
• If you close your PowerShell window, all of your custom aliases will be
deleted
• To have your customizations available every time we open
PowerShell, we can store them in a profile
• The profile path is stored in a variable called $Profile
• Edit $Profile and enter the Set-Alias commands for your custom
aliases

Students will create a profile in the PowerShell lab

31
Using a Profile script to customize PowerShell

https://docs.microsoft.com/en-
us/powershell/module/microsoft.powershell.core/about/about_profiles?view=powershell-
5.1

32
PowerShell Help

https://docs.microsoft.com/en-us/powershell/scripting/learn/getting-detailed-help-
information?view=powershell-5.1

33
Updating Help
• When you first run Get-Help, you may be asked to update the help
files on your computer

34
Getting Help for an Alias or cmdlet

35
Using Help Online

36
What did we learn?
• PowerShell is an Interactive Command Interface and a Scripting
Language
• Two current versions: Windows PowerShell and PowerShell Core
(multi-OS)
• PowerShell uses cmdlets that have a verb-noun command structure
• Aliases allow you to use alternate commands to run cmdlets. Some
are built in to allow Windows and Linux users to get started with
PowerShell easily, using familiar commands. We can also create
custom aliases.
• PowerShell has a extensive help system, both within PowerShell and
online

37
Works Cited:
• https://docs.microsoft.com/en-us/powershell/scripting/overview?view=powershell-5.1
• https://en.wikipedia.org/wiki/PowerShell
• https://www.techrepublic.com/blog/10-things/10-reasons-why-you-should-learn-to-use-
powershell/

38

You might also like