0% found this document useful (0 votes)
291 views26 pages

PowerShell Pillar PDFdownload

The document provides an overview of PowerShell, a scripting language and command-line shell developed by Microsoft. It discusses how PowerShell can be used to automate system tasks and manage configurations. Key features highlighted include discoverability of commands, help capabilities, ability to run commands remotely, and linking commands through piping. The document also notes PowerShell's role in replacing the Command Prompt and Microsoft making it the default CLI for Windows 10.

Uploaded by

Carlos Murta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
291 views26 pages

PowerShell Pillar PDFdownload

The document provides an overview of PowerShell, a scripting language and command-line shell developed by Microsoft. It discusses how PowerShell can be used to automate system tasks and manage configurations. Key features highlighted include discoverability of commands, help capabilities, ability to run commands remotely, and linking commands through piping. The document also notes PowerShell's role in replacing the Command Prompt and Microsoft making it the default CLI for Windows 10.

Uploaded by

Carlos Murta
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 26

What is PowerShell and how to use it:

The ultimate tutorial

May 2023
In this guide:

What does PowerShell


do?
PowerShell has for years helped IT admins configure entire fleets of systems, troubleshoot
Why use PowerShell? critical problems and automate complex data center activities. This comprehensive guide
details this vital tool’s many features, offers clear steps on how to get started using it and
Key PowerShell features explains how it may evolve in the future.
History of PowerShell

How do I start learning


PowerShell?

How to launch PowerShell

How to create and run


PowerShell scripts

Future of PowerShell

1 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:

What does PowerShell


What is PowerShell and how to use it: The ultimate tutorial
do?
STEPHEN BIGELOW, SENIOR TECHNOLOGY EDITOR

Why use PowerShell?


PowerShell is an object-oriented automation engine and scripting language with an
Key PowerShell features
interactive command-line shell that Microsoft developed to help IT professionals configure
History of PowerShell systems and automate administrative tasks.

How do I start learning


PowerShell? Built on the .NET framework, PowerShell works with objects, whereas most command-line
shells are based on text. PowerShell is a mature and well-proven automation tool for system
How to launch PowerShell
administrators employed in both IT departments and external entities, such as managed
How to create and run service providers, because of its scripting capabilities.
PowerShell scripts

Future of PowerShell PowerShell originated as a proprietary offering that was only available on Windows. Today,
PowerShell is available by default on most recent Windows systems; simply type
"powershell" into the Windows search bar to locate the PowerShell app. In 2016, Microsoft
open sourced PowerShell and made it available on Linux and macOS.

2 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
WHAT DOES POWERSHELL DO?
What does PowerShell
do?
Microsoft designed PowerShell to automate system tasks, such as batch processing, and to
Why use PowerShell? create system management tools for commonly implemented processes. The PowerShell
language, similar to Perl, offers several ways to automate tasks:
Key PowerShell features

History of PowerShell • With cmdlets, which are very small .NET classes that appear as system commands.
• With scripts, which are combinations of cmdlets and associated logic.
How do I start learning
• With executables, which are standalone tools.
PowerShell?
• With the instantiation of standard .NET classes.
How to launch PowerShell
Admins can use PowerShell to handle a wide range of activities. It can extract information on
How to create and run OSes, such as the specific version and service pack levels. "PowerShell providers" are
PowerShell scripts
programs that make data contained in specialized data stores accessible at the command
Future of PowerShell line. Those data stores include file system drives and Windows registries.

PowerShell also serves as the replacement for Microsoft's Command Prompt, which dates
back to DOS. Microsoft, for example, made PowerShell the default command-line interface
(CLI) for Windows 10 as of build 14791. PowerShell's role as a command-line shell is how
most users become acquainted with the technology.

3 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
WHY USE POWERSHELL?
What does PowerShell
do?
The most appealing reason to use any kind of CLI is the potential for precise and repeatable
Why use PowerShell? control over a desired action or task flow that is difficult, or even impossible, to replicate
with a traditional GUI.
Key PowerShell features

History of PowerShell Consider using a GUI to perform an intricate task. It can involve clicking buttons, moving
How do I start learning
sliders, selecting files from multilayered menus and other actions. GUIs were designed to be
PowerShell? comfortable for humans to use, but they can be time-consuming, cumbersome and error-
prone -- especially when a task must be repeated hundreds or thousands of times.
How to launch PowerShell

How to create and run In contrast, PowerShell offers a CLI with a mature and detailed scripting language that
PowerShell scripts
enables a user with rudimentary programming skills to craft a detailed set of specific
Future of PowerShell instructions, or a script, for a desired task. The task can be just about anything, from finding
a desired file to describing a desired state configuration for the system or other systems.
Once the script is created, it can be saved as a file and executed with a click, enabling the
same task to be repeated exactly the same way for any number of repetitions. Different
scripts can also be chained together to create complex and highly detailed tasks.

These simple-sounding characteristics are absolutely essential for automation and scalability
-- letting the computer do the work as much as is needed for the environment. Thus,

4 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
PowerShell can help system administrators perform complex and highly repetitive tasks with
What does PowerShell
a high level of automation and accuracy that a GUI simply can't replicate.
do?

Why use PowerShell?


KEY POWERSHELL FEATURES
Key PowerShell features
Microsoft incorporates updates and new features with each PowerShell version, but the
History of PowerShell
following is a list of the primary features and characteristics.
How do I start learning
PowerShell?
Discoverability. Users can discover PowerShell's features using cmdlets, such as Get-
How to launch PowerShell Command, which creates a list of all the commands -- including cmdlets and functions --
available on a given computer. Parameters can be used to narrow the scope of the search.
How to create and run
PowerShell scripts
Help capabilities. Users can learn more about PowerShell principles and particular
Future of PowerShell
components, such as cmdlets, through the Get-Help cmdlet. The -online parameter provides
access to help articles on the web if available for a particular topic.

Remote commands. Admins can perform remote operations on one or multiple computers,
taking advantage of technologies such as Windows Management Instrumentation and WS-
Management. The WS-Management protocol, for example, lets users run PowerShell
commands and scripts on remote computers.

5 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
Pipelining. With PowerShell, commands can be linked together through the pipe operator,
What does PowerShell
symbolized as |. This approach lets the output from a given command become the input for
do?
the next command in the pipeline sequence. The PowerShell pipeline lets objects, rather
Why use PowerShell? than text strings, flow from one cmdlet to another. This powerful capability is important for
Key PowerShell features complex and detailed automation scripts.

History of PowerShell
Details on additional features can be found in the following sections.
How do I start learning
PowerShell? DESIRED STATE CONFIGURATION
With PowerShell 4.0, Microsoft introduced a configuration management platform called
How to launch PowerShell
Desired State Configuration (DSC), which admins can use to set a specific configuration for a
How to create and run server. After the admin defines the server settings, PowerShell ensures the target nodes
PowerShell scripts
retain that desired state. DSC has two modes of operation: push mode and pull mode.
Future of PowerShell
In push mode, a server sends notifications to the nodes. It's a one-way communication,
where the admin sends notifications from a workstation. Setup costs are less because
management runs from a device, but a notification can get lost if the device isn't connected
to the network.

In pull mode, the IT department creates a pull server with the configuration details of each
node using a Managed Object Format file. Each node contacts the pull server to check for a
new configuration. If the new configuration is available, the pull server sends the

6 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
configuration to the node. Admins can manage all devices regardless of their network
What does PowerShell
connection. When a device connects to the network, it automatically contacts the pull server
do?
to check for a new configuration.
Why use PowerShell?
DSC RESOURCES
Key PowerShell features
DSC resources are the components of a desired state configuration script. Admins can check
History of PowerShell the available DSC resources on a machine with the Get-DscResource command.
How do I start learning
PowerShell?

How to launch PowerShell

How to create and run


PowerShell scripts

Future of PowerShell

Admins use these resources to configure components, such as registry keys and Windows
services, or to create and manage local users through a configuration script. For instance, the
File resource manages files and folders, the Environment resource manages environment
variables and the Registry resource manages the registry keys of a node. Windows default,
or built-in, DSC resources include the following:

7 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
• Archive resource.
What does PowerShell • Environment resource.
do? • File resource.
• Group resource.
Why use PowerShell?
• GroupSet resource.
Key PowerShell features • Log resource.
• Package resource.
History of PowerShell • ProcessSet resource.
• Registry resource.
How do I start learning
• Script resource.
PowerShell?
• Service resource.
How to launch PowerShell • ServiceSet resource.
• User resource.
How to create and run • WindowsFeature resource.
PowerShell scripts • WindowsFeatureSet resource.
• WindowsOptionalFeature resource.
Future of PowerShell
• WindowsOptionalFeatureSet resource.
• WindowsPackageCabresource resource.
• WindowsProcess resource.

Additional resources are available for cross-node dependency, package management and Linux
resources.

8 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
POWERSHELL INTEGRATED SCRIPTING ENVIRONMENT
What does PowerShell PowerShell Integrated Scripting Environment (ISE), introduced by Microsoft in PowerShell
do?
version 2.0, is a PowerShell host application used to write, test and debug scripts or write
Why use PowerShell? commands in a Windows GUI. To access the ISE, click Start, select Windows PowerShell and

Key PowerShell features


choose Windows PowerShell ISE. As an alternative, simply type powershell_ise.exe
in the command shell or Windows Run box.
History of PowerShell

How do I start learning PowerShell ISE comes with multiple features, such as language help, syntax coloring,
PowerShell? multiline editing, context-sensitive help and tab completion.
How to launch PowerShell

How to create and run


PowerShell scripts

Future of PowerShell

9 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
PowerShell ISE has sophisticated features that are familiar to Windows users. For instance, a
What does PowerShell
user can highlight and copy a portion of a PowerShell command with a mouse or with the
do?
Shift + Arrow hot-key combination. The user can also paste the content anywhere in the
Why use PowerShell? editor window.
Key PowerShell features
Another useful feature is the ability to keep different versions of a command in the editor
History of PowerShell
and run commands you need in the PowerShell ISE.
How do I start learning
PowerShell? The F5 key launches a command directly from the editor. To execute a particular line, select
How to launch PowerShell it and press F8. The context-sensitive help displays matching cmdlets when the user starts to
enter a command. A command add-on shows a list of cmdlets to select.
How to create and run
PowerShell scripts
PowerShell ISE provides tabs to enable work on multiple administrative tasks. PowerShell ISE
Future of PowerShell enables quick switching from the CLI to scripting mode.

POWERSHELL MODULES
PowerShell modules enable admins to reuse a script to automate a task. A PowerShell
module can be defined as a set of PowerShell elements -- such as cmdlets, providers,
functions, workflows, variables and aliases -- that are grouped to manage all the aspects of a
particular area. PowerShell modules enable admins to reference, load, persist and share
code. The simplest way to create a PowerShell module is to save the script as a PSM1 file.

10 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
A PowerShell module contains four essential elements:
What does PowerShell
do?
• A PSM file, which is the module.
Why use PowerShell? • Help files or scripts needed by the module.
• A manifest file that describes the module.
Key PowerShell features • A directory that stores the content.
History of PowerShell A PowerShell module can be one of four types:
How do I start learning
PowerShell? • Script module. A PSM1 file that contains various functions to enable admins to
perform import, export and management functions.
How to launch PowerShell • Binary module. A .NET framework assembly (DLL file) that contains compiled code.
Developers typically use a binary module to create cmdlets with powerful features not
How to create and run easily done with a PowerShell script.
PowerShell scripts
• Manifest module. A manifest module is a module (PSM1) file with an associated
Future of PowerShell manifest (PSD1 file).
• Dynamic module. A dynamic module is created dynamically on demand by a script. It
isn't stored or loaded to persistent storage.

POWERSHELL CMDLETS
A cmdlet is a single basic command used within PowerShell. A cmdlet can be invoked as part
of a PowerShell script -- an important element of automation -- or invoked programmatically
through PowerShell APIs. A cmdlet typically performs a specific action and then returns a
.NET object to PowerShell that can be used by a subsequent command. PowerShell cmdlets
are often created -- meaning coded by developers -- to handle specific operations.

11 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
There are myriad cmdlets for PowerShell. For example, running the Get-Service cmdlet
What does PowerShell
returns a list of services currently running on the computer.
do?

Why use PowerShell? All cmdlets require an attribute needed to declare the code to be a cmdlet. Cmdlets also
Key PowerShell features possess a variety of parameters, such as required, named, positional and switch parameters.
Parameters can be used as a set, and some parameters can also be dynamically added at
History of PowerShell
runtime. PowerShell cmdlets can be created to prompt user feedback before the cmdlet
How do I start learning acts, effectively creating interactive cmdlets.
PowerShell?
CMDLETS VS. COMMANDS
How to launch PowerShell
The terms cmdlet and command are sometimes used interchangeably. Commands and
How to create and run cmdlets can both tell PowerShell -- and the computer -- to do something specific. However,
PowerShell scripts
cmdlets differ from commands in several ways:
Future of PowerShell
• A command is often a small, standalone executable file, such as the ipconfig
command used at the console command line, but cmdlets are instanced .NET classes.
• Cmdlets are typically small and can be created from just several dozen lines of code.
• Commands can often perform parsing, error handling and output formatting. Cmdlets
can't, and such functionality is handled by the PowerShell platform.
• Commands generally don't participate in a pipeline because data isn't passed to or
used by subsequent commands. Cmdlets are designed to use input objects from the
pipeline and then deliver output objects to the pipeline.
• Cmdlets typically process a single object at a time.

12 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
POWERSHELL FUNCTIONS
What does PowerShell A PowerShell function is similar to a PowerShell cmdlet, with several slight differences. In
do?
simplest terms, a function involves a list of PowerShell statements organized under a single
Why use PowerShell? function name or label. The function is invoked by simply typing the function name, and the

Key PowerShell features


list of statements is executed as if an administrator typed them at the command prompt. A
function can be as simple as one-line command with parameters or as complex as a full
History of PowerShell
cmdlet or application.
How do I start learning
PowerShell? Cmdlets are written in a compiled .NET language, such as C#, while functions are written in
How to launch PowerShell PowerShell and aren't compiled. For developers and independent software vendors, it's
easier to package and deploy a PowerShell cmdlet compared to packaging libraries of
How to create and run
functions. Cmdlets and advanced functions support powerful parameter bindings.
PowerShell scripts

Future of PowerShell As with cmdlets, functions can use parameters and return values that can be passed to other
functions or cmdlets. By describing a parameter to the shell, admins can use any type of
PowerShell parameters, such as named parameters, mandatory parameters and positional
PowerShell parameters.

The following is an example of a PowerShell function:

function Set-Something {
[CmdletBinding()]
param (

13 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
[Parameter()]
[string]$Thing
What does PowerShell )
do? Write-Host $Thing
}
Why use PowerShell?
A function contains one or more option parameters inside of a parameter block and a body.
Key PowerShell features
LANGUAGE CONSTRUCTS
History of PowerShell
As a scripting language, PowerShell offers several language constructs that control the flow
How do I start learning of scripts, while making decisions as to what should be done. Some of the language
PowerShell?
constructs include conditionals, switches, loops and variables.
How to launch PowerShell

How to create and run


Conditionals. The language construct if is used to evaluate a conditional expression. When
PowerShell scripts the conditional expression is true, a script block is executed. If the conditional expression is
other than true -- noted as something else -- then alternative commands, functions and
Future of PowerShell
cmdlets can be executed.

if ($i -eq 1)
{
## Do something
}
else
{
## Do something else
}

14 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
Switch. The switch statement is used when there is a long list of conditional statements to
What does PowerShell
test. Switch is commonly used in place of many if/else constructs.
do?

Why use PowerShell? switch ($i) {


0
{
Key PowerShell features Write-Host "I is 0"
}
History of PowerShell 1
{
Write-Host "I is 1"
How do I start learning }
PowerShell? Default
{
Write-Host "I is not 0 or 1" >
How to launch PowerShell }
}
How to create and run
PowerShell scripts Loops. Loops provide powerful means of evaluating and repeating complex tasks based on
Future of PowerShell the state of parameters or variables. There are several different types of loops. The while
statement repeats code as long as the following conditional expression is true:

while ($i -eq 0) {


## Do something >
}

The do loop is similar to the while loop. The only difference is PowerShell executes the do
loop at the end of the loop:

15 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
do {
## do something
What does PowerShell } while ($i -lt 0)
do?
When you use a foreach loop, PowerShell repeats the code for each item mentioned in
Why use PowerShell?
the script:
Key PowerShell features
$array = ('item1','item2','item3')
History of PowerShell foreach ($item in $array) {
$item
How do I start learning }
PowerShell?
Use a for loop to execute statements repeatedly until a condition is met:
How to launch PowerShell
for ($i = 0; $i -lt 5; $i++)
How to create and run {
PowerShell scripts $i
}
Future of PowerShell
VARIABLES
Variables store data, but PowerShell variables are more powerful because they can be
mapped to underlying classes in the .NET framework. PowerShell treats variables as .NET
objects, which means they can store data and manipulate data in multiple ways.

Variable names in PowerShell start with a dollar sign and contain a mix of numbers, letters,
symbols and spaces. For instance, $var="HELLO" stores the string HELLO in the $var
variable. As another example, the previous code instance uses the variable $i to hold the

16 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
value evaluated within the for loop. Variables can also have different scopes, such as
What does PowerShell
global, local, script, private and numbered scopes.
do?

Why use PowerShell? ARRAYS


A PowerShell array is a component that enables the storage of more than one item in a
Key PowerShell features
variable or a field. For instance, to assign multiple values to a variable, use the script
History of PowerShell $a=1,2,3.
How do I start learning
PowerShell? PowerShell treats each item in an array as a separate element. To address each item in an
array, PowerShell offers index numbers. The first element in the array is indexed as 0 by
How to launch PowerShell
default. The biggest advantage of PowerShell is that it automatically handles array insertions,
How to create and run so arrays don't have to be manually destroyed or created when adding or removing
PowerShell scripts
elements.
Future of PowerShell
HASH TABLES
Hash tables are data structures similar to arrays. A PowerShell array stores multiple single
items, but with a hash table each item or value is stored using a key or value pair. An array
can't store multiple values under each element, while a hash table can.

Below is an example comparing an array with a hash table:

$array = @('Joe','Susie','Donnie')
$hashtable = @{FirstName = 'Joe'; FirstName = 'Susie'; FirstName = 'Donnie'}

17 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
HELP AND COMMENTS
What does PowerShell PowerShell enables the addition of help topics for modules, scripts and individual
do?
commands. To view all the help topics, use the Get-Help command.
Why use PowerShell?
When importing a module into a session, PowerShell automatically imports the help topics
Key PowerShell features
for that module. If there are no help topics for a module, the Get-Help command displays
History of PowerShell autogenerated help. Three types of help content exist in PowerShell: comment-based help,
How do I start learning external help and updatable help.
PowerShell?
Comment-based help refers to comments included with a script or command for Get-Help
How to launch PowerShell
to read. External help enables the author to define help content in an external XML file
How to create and run written in XAML. Updatable help uses external help but enables users to download the latest
PowerShell scripts
help content with the Update-Help command.
Future of PowerShell
EXECUTABLE PROGRAMS
PowerShell is also a Command Prompt replacement that runs an executable program in
multiple ways through the Start-Process command, the ampersand and the Invoke-
Expression command. This can be a convenient way for PowerShell to run commands
and other executables. Using ping.exe as an example, here's how a user can run an
executable program using PowerShell:

18 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
Start-Process -FilePath 'ping.exe' -ArgumentList 'google.com' -Wait -NoNewWindow
& 'ping.exe' google.com
What does PowerShell ping google.com
do? Invoke-Expression -Command 'ping.exe google.com'

Why use PowerShell?


HISTORY OF POWERSHELL
Key PowerShell features

History of PowerShell PowerShell was first demonstrated in 2003 and initially released in 2006. Since then, it has
significantly expanded through numerous major releases, each still supported and providing
How do I start learning
PowerShell?
backward compatibility with prior versions. The following are some of the major release
versions and dates:
How to launch PowerShell

How to create and run • Windows PowerShell 1.0. Released in 2006 for Windows XP SP2, Windows Server
PowerShell scripts 2003 SP1, Windows Vista and Windows Server 2008.
• Windows PowerShell 2.0. Released in 2009 and integrated with Windows 7, Windows
Future of PowerShell Server 2008 R2, Windows XP SP3, Windows Server 2003 SP2 and Windows Vista SP1.
The release included Windows PowerShell ISE v2.0.
• Windows PowerShell 3.0. Released in 2012 and integrated with Windows 8 and
Windows Server 2012. It was also released for Windows 7 SP1, Windows Server 2008
SP1 and Windows Server 2008 R2 SP1.
• Windows PowerShell 4.0. Released in 2013 and integrated with Windows 8.1 and
Windows Server 2012 R2. It was also released for Windows 7 SP1, Windows Server
2008 R2 SP1 and Windows Server 2012.
• Windows PowerShell 5.0. Released and updated to version 5.1 in 2016 to support
Windows Server 2016. Version 5.1 was also released in 2017 for Windows 7, Windows

19 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
Server 2008, Windows Server 2008 R2, Windows Server 2012 and Windows Server
What does PowerShell 2012 R2.
do? • PowerShell Core 6. Released in 2018 as the first free and open source iteration of
PowerShell for cross-platform deployment on Windows, macOS and Linux platforms.
Why use PowerShell?
Versions 6.1 and 6.2 subsequently appeared to fix bugs, enhance performance and
Key PowerShell features improve compatibility with existing cmdlets and support Windows 10 and Windows
Server 2019.
History of PowerShell • PowerShell 7. Released in 2020 and currently serves many Windows versions,
including Windows 7 SP1, Windows 8.1, Windows 10, Windows 11, Windows Server
How do I start learning
2008 R2 SP1, Windows Server 2012, Windows Server 2012 R2, Windows Server 2019
PowerShell?
and Windows Server 2022. Subsequent versions 7.2 -- there was no 7.1 -- and 7.3
How to launch PowerShell address improvements in cross-platform installation and fixes.

How to create and run


PowerShell scripts HOW DO I START LEARNING POWERSHELL?

Future of PowerShell
PowerShell is a complex and comprehensive platform that can perform a vast array of
functions and support sophisticated enterprise-class tasks -- many of which can be
automated through scripts and custom cmdlet creation, or programming. Consequently,
most system administrators must eventually be proficient in PowerShell to effectively
perform their regular day-to-day duties.

However, there is no single pathway to learning PowerShell. Learning options are available
to almost any level of PowerShell user, but the following are some common approaches:

20 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
• Tinker. PowerShell is free and already installed on virtually every Windows computer;
What does PowerShell simply search for and run the PowerShell app. PowerShell enthusiasts can try new
do? commands and experiment with new cmdlets to gain comfort with PowerShell
interface and behavioral basics.
Why use PowerShell?
• Take self-paced training. Microsoft provides free and extensive learning content for
Key PowerShell features PowerShell, including a self-paced introduction.
• Study Microsoft documentation. Microsoft provides free and comprehensive
History of PowerShell documentation for all aspects of PowerShell, including commands and cmdlets.
Students and professionals alike can refer to documentation to expand their
How do I start learning
PowerShell knowledge.
PowerShell?
• Read books. There are countless books published to bolster PowerShell expertise in
How to launch PowerShell varied learning and use case environments. Several recent titles include Learn
PowerShell in a Month of Lunches, Fourth Edition (Travis Plunk, James Petty, Tyler
How to create and run Leonhardt: April 26, 2022) and Windows Server Automation with PowerShell
PowerShell scripts Cookbook, Fourth Edition (Thomas Lee, Jeffrey Snover: July 30, 2021). Commented [BH1]: BLH update using info in Script

• Take classes. Finally, PowerShell users can find a wide range of self-study and guided
Future of PowerShell
courses focused on various aspects and use cases for PowerShell. As an example,
Udemy promotes a range of PowerShell courses, including "Learning Windows
PowerShell," "Master Microsoft PowerShell" and "PowerShell for Active Directory
Administrators." Local colleges and adult education centers might also offer
instructor-led coursework for PowerShell users.

These options are not mutually exclusive. Varied learning options can be used in any
combination to accelerate PowerShell adoption and proficiency.

21 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
HOW TO LAUNCH POWERSHELL
What does PowerShell
do?
Any computer running Windows 10 or later already has PowerShell installed by default.
Why use PowerShell? PowerShell can be invoked simply by typing "powershell" into the Search bar and selecting
the PowerShell app from the resulting search list. Similarly, PowerShell can be invoked by
Key PowerShell features
entering powershell.exe in the Run dialog.
History of PowerShell

How do I start learning PowerShell 7 also supports cross-platform installation on many Linux distributions and can
PowerShell? be launched by typing pwsh at the Linux command prompt. The launch process is similar

How to launch PowerShell


under macOS. Once PowerShell is installed, simply open a Terminal window and type the
pwsh command.
How to create and run
PowerShell scripts
HOW TO CREATE AND RUN POWERSHELL SCRIPTS
Future of PowerShell

PowerShell is primarily an execution platform, so developers generally create scripts in a


different tool and then run those scripts through PowerShell.

There are countless options for creating a script, including almost any ordinary text editor,
the PowerShell ISE, Microsoft Visual Studio Code or even legacy Notepad. Users can embrace
almost any editor that meets the organization's development needs. Consider the basic
steps to create a simple one-command script using Notepad on Windows 11:

22 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
• Search for and select Notepad to launch the application.
What does PowerShell • In Notepad, write the command line Write-Host "This is your first
do? script…Great job!"
• Click File and select the Save As option.
Why use PowerShell?
• Enter a useful name for the script, such as script.ps1.
Key PowerShell features • Click the Save button.

History of PowerShell Now that the script is created and saved as a PS1 file, be sure to change the execution policy
on the system so that scripts will run, as scripts are blocked by default. To change the
How do I start learning
PowerShell? execution policy on Windows 11, follow these steps:

How to launch PowerShell • Click Start and search for PowerShell.


• Right-click the PowerShell app in the list and select Run as administrator.
How to create and run
PowerShell scripts
• PowerShell starts. Now type the command Set-ExecutionPolicy
RemoteSigned.
Future of PowerShell • This tells PowerShell to change the execution policy. Select the Yes to All option by
typing A and pressing Enter.

Finally, the new script can be executed using the & command, the path to the script and the
name of the PS1 file created, such as &
C:\Users\steve\OneDrive\Documents\script.ps1.

The text created in the example script is written to the host device -- in this case, the
monitor.

23 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:

What does PowerShell


do?

Why use PowerShell?

Key PowerShell features

History of PowerShell

How do I start learning This is just one simple example. PowerShell scripts are typically far more detailed and
PowerShell?
complex. When creating script files, it's a good idea to provide a well-known folder path for
How to launch PowerShell holding script files. It's often a sound practice to include version control or other version
management techniques as well, such as adding a version designation to the PS1 file name.
How to create and run
PowerShell scripts For example, rather than simply naming the file script.ps1, it might be more meaningful to
name the file script_020123_v1_0.ps1 to indicate that file version 1.0 was created on Feb. 1,
Future of PowerShell
2023.

FUTURE OF POWERSHELL

Even though PowerShell has been consigned to the open source community, Microsoft
continues to actively participate and contribute to open source PowerShell development.
After two decades, PowerShell has developed a ubiquitous presence and achieved broad --
almost irreplaceable -- adoption in enterprise environments.

24 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023
In this guide:
Users shouldn't expect groundbreaking new features and functionality, but PowerShell will
What does PowerShell
continue to be updated and maintained to meet the changing capabilities of Windows, Linux
do?
and macOS well into the foreseeable future. In addition, there are several developments on
Why use PowerShell? the horizon, including better and simplified automation, as well as improved configuration
Key PowerShell features and remote operation.

History of PowerShell

How do I start learning


PowerShell?

How to launch PowerShell ▼ CONTINUED READING

How to create and run


PowerShell scripts
25 basic PowerShell commands for Windows administrators
Future of PowerShell
Build a PowerShell logging function for troubleshooting

10 PowerShell courses to help you hone your skills

25 WHAT IS POWERSHELL AND HOW TO USE IT: THE ULTIMATE TUTORIAL MAY 2023

You might also like