Professional Documents
Culture Documents
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.
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)
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
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).
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
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.
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
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
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
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
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
25
names?view=powershell-5.1
25
Windows Command Prompt and Unix
commands that you can use in PowerShell:
cat dir mount rm
clear h ps sort
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:
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
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