0% found this document useful (0 votes)
3 views

Starting with Windows PowerShell Cheatsheet

Uploaded by

hbwhypw
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Starting with Windows PowerShell Cheatsheet

Uploaded by

hbwhypw
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

STARTING WITH WINDOWS

POWERSHELL

Starting with Windows


PowerShell
TABLE OF CONTENTS

Preface 1
Introduction 1
Purpose and Benefits of PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Versions of PowerShell. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
System Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Installing PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Architecture 1
Command Line Interface vs Graphical User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Cmdlets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Objects and Pipelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Scripts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Remoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
The Language 9
Syntax and Grammar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Variables and Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Wildcards . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Conditional Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Data Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Regular Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Error Handling. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Debugging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
1 POWERSHELL

PREFACE
PREFACE SYSTEM REQUIREMENTS

This cheatsheet provides an overview of the most The system requirements for PowerShell vary
commonly used PowerShell commands, grouped by depending on the version and operating system
category. Whether you’re new to PowerShell or an being used. However, PowerShell 7.1 can run on
experienced user, this cheatsheet will serve as a Windows, macOS, and Linux systems.
handy reference guide for common tasks and
commands.
INSTALLING POWERSHELL

From basic file management to advanced system PowerShell is installed by default on most modern
administration, PowerShell can help you get things Windows operating systems. However, if it’s not
done more efficiently and effectively. This cheat installed, it can be downloaded and installed from
sheet is designed to help you quickly find the right the Microsoft website.
command for the job, so you can spend less time
searching for information and more time getting
KEY FEATURES
things done.
• PowerShell is a powerful scripting language
We hope this cheatsheet helps you become more
that allows administrators to automate tasks
productive with PowerShell. Happy scripting!
and create custom scripts.

• It provides a rich set of built-in cmdlets for


INTRODUCTION
INTRODUCTION performing common administrative tasks such
as managing users, groups, and system settings.
PowerShell is a command-line shell and scripting
language developed by Microsoft for task • PowerShell supports remote administration of
automation and configuration management. It is Windows systems, allowing administrators to
built on the .NET Framework and offers a powerful manage multiple systems from a single console.
set of cmdlets and tools for managing Windows
• PowerShell provides advanced error handling
systems and applications.
and debugging capabilities, making it easier to
troubleshoot and resolve issues.
PowerShell has become the preferred tool for IT
professionals who manage large-scale Windows • PowerShell can be extended with third-party
environments, as it provides a standardized modules and tools, allowing administrators to
approach for managing systems and automating customize and enhance its capabilities.
tasks.

ARCHITECTURE
ARCHITECTURE
PURPOSE AND BENEFITS OF
POWERSHELL COMMAND LINE INTERFACE VS
GRAPHICAL USER INTERFACE
PowerShell is designed to simplify and automate
administrative tasks in Windows environments. It The CLI interface provides users with greater
allows administrators to manage Windows systems flexibility, control, and automation capabilities,
more efficiently and effectively by providing a making it easier to perform repetitive
powerful, flexible, and scriptable command-line administrative tasks. With PowerShell,
interface. Some benefits of using PowerShell administrators can automate tasks such as
include improved productivity, reduced errors, and managing users and groups, configuring network
increased scalability. settings, and managing virtual machines.

VERSIONS OF POWERSHELL The GUI interface, on the other hand, provides a


more intuitive and visual interface for managing
PowerShell has several versions, including systems. The GUI can be useful for tasks that
PowerShell 1.0, 2.0, 3.0, 4.0, 5.0, 5.1, and 7.0, with require visual confirmation or interaction, such as
the latest being PowerShell 7.1 at the time of configuring system settings, creating and
writing. configuring user accounts, and working with file

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
2 POWERSHELL

explorer. Core cmdlets

However, for advanced administrative tasks, These are the basic cmdlets that are included in
PowerShell’s CLI is the preferred method, as it PowerShell by default. They provide core
provides more control and automation capabilities. functionality for working with files, directories,
The GUI interface can be a helpful tool for basic processes, and more.
system management tasks, but it can be time-
consuming for complex and repetitive tasks. Cmdlet Description

Get-ChildItem Lists files and folders in


CMDLETS a directory

Cmdlets, or "command-lets," are the fundamental Set-Location Changes the current


building blocks of PowerShell. Cmdlets are small, directory
specialized commands that perform a specific task, Get-Process Lists running processes
such as retrieving information, modifying settings,
Stop-Process Stops a running process
or managing resources.
Get-Service Lists services on the
Here are some key things to know about cmdlets in system
PowerShell:
Start-Service Starts a stopped service
• Cmdlets are designed to be used in pipelines, Stop-Service Stops a running service
allowing the output of one cmdlet to be used as
Get-Content Displays the contents of
input to another.
a file
• Cmdlets follow a consistent naming convention,
Set-Content Sets the contents of a file
with a verb-noun structure. For example, Get-
Process is a cmdlet that retrieves information New-Item Creates a new item, such
about running processes, and Set-Item is a as a file or folder
cmdlet that modifies the properties of a file or
Remove-Item Deletes an item
registry key.

• PowerShell includes a large number of built-in


Active Directory cmdlets
cmdlets, covering a wide range of system
administration tasks. These cmdlets are used for managing Active
• You can view a list of all available cmdlets Directory objects, such as users, groups, and
using the Get-Command cmdlet. computers.

• Cmdlets are designed to be easy to use and


Cmdlet Description
require minimal input from the user. They
often include default values for parameters and Get-ADUser Lists user objects in
support for aliases, allowing users to use Active Directory
familiar syntax and shortcuts.
New-ADUser Creates a new user
• PowerShell also allows users to create custom object
cmdlets using PowerShell scripts or compiled
Set-ADUser Modifies a user object
code. This allows users to extend the
functionality of PowerShell and create Remove-ADUser Deletes a user object
specialized cmdlets tailored to their specific Get-ADGroup Lists group objects in
needs. Active Directory
• Cmdlets can be run on remote computers using New-ADGroup Creates a new group
PowerShell’s remoting capabilities. This allows object
administrators to manage multiple systems
from a central location, without needing to Set-ADGroup Modifies a group object
physically access each system. Remove-ADGroup Deletes a group object

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
3 POWERSHELL

Cmdlet Description Cmdlet Description

Add-ADGroupMember Adds a member to a Get-SPWeb Lists SharePoint webs


group
New-SPWeb Creates a new
Remove- Removes a member SharePoint web
ADGroupMember from a group
Set-SPWeb Modifies a SharePoint
web
Exchange Server cmdlets
Remove-SPWeb Deletes a SharePoint
These cmdlets are used for managing Exchange web
Server objects, such as mailboxes, contacts, and
distribution groups. SQL Server cmdlets

Cmdlet Description These cmdlets are used for managing SQL Server
objects, such as databases, tables, and views.
Get-Mailbox Lists mailboxes in
Exchange Server
Cmdlet Description
New-Mailbox Creates a new mailbox
Get-SqlDatabase Lists SQL Server
Set-Mailbox Modifies a mailbox databases

Remove-Mailbox Deletes a mailbox New-SqlDatabase Creates a new SQL


Server database
Get-DistributionGroup Lists distribution groups
Set-SqlDatabase Modifies a SQL Server
New-DistributionGroup Creates a new
database
distribution group
Remove-SqlDatabase Deletes a SQL Server
Set-DistributionGroup Modifies a distribution
database
group
Get-SqlTable Lists SQL Server tables
Remove- Deletes a distribution
DistributionGroup group New-SqlTable Creates a new SQL
Server table
Add- Adds a member to a
DistributionGroupMemb distribution group Set-SqlTable Modifies a SQL Server
er table

Remove- Removes a member Remove-SqlTable Deletes a SQL Server


DistributionGroupMemb from a distribution table
er group

Networking cmdlets
SharePoint Server cmdlets
These cmdlets are used for working with network
These cmdlets are used for managing SharePoint settings, such as IP addresses, DNS servers, and
Server objects, such as sites, lists, and libraries. network adapters.

Cmdlet Description Cmdlet Description

Get-SPSite Lists SharePoint sites Test-Connection Sends ICMP echo


requests to a remote
New-SPSite Creates a new
computer to test its
SharePoint site
availability.
Set-SPSite Modifies a SharePoint
site

Remove-SPSite Deletes a SharePoint site

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
4 POWERSHELL

Cmdlet Description Cmdlet Description

Test-NetConnection Tests the connection to a Test-NetConnection Tests a network


remote network connection to a specified
resource by establishing destination.
a connection to a
Set-ExecutionPolicy Sets the script execution
specified TCP port.
policy for the current
Get-NetAdapter Retrieves a list of all user or computer.
network adapters
installed on the
Storage cmdlets
computer.

Get-NetIPAddress Retrieves IP address These cmdlets are used for working with storage
configuration devices and settings, such as disks, volumes, and
information for all IP file systems.
addresses assigned to
network adapters on the Cmdlet Description
computer. New-PSDrive Creates a PowerShell
Get-NetTCPConnection Retrieves a list of all drive that is connected
active TCP connections to a network resource or
on the computer. a storage device.

New-NetFirewallRule Creates a new firewall Get-PSDrive Gets the drives available


rule for inbound or in the current session.
outbound traffic. Get-Volume Retrieves information
about the volumes on
Security cmdlets the system.

New-Item Creates a new item (file,


These cmdlets are used for working with security
directory, registry key,
settings, such as user accounts, permissions, and
etc.) at the specified
certificates.
location.

Cmdlet Description Remove-Item Deletes the specified


item.
Get-Acl Gets the access control
list (ACL) for a resource. Set-Item Sets the value of a
property of the specified
Set-Acl Changes the access
item.
control list (ACL) for a
resource. Get-Item Gets the properties of
the specified item.
Get-PfxCertificate Retrieves a certificate
from a Personal Test-Path Determines whether the
Information Exchange specified path exists.
(PFX) file. Rename-Item Renames the specified
New- Creates a new self- item.
SelfSignedCertificate signed certificate. Get-ChildItem Retrieves the items in
Export-Certificate Exports a certificate one or more specified
from a certificate store locations.
to a file. Copy-Item Copies an item from one
Import-Certificate Imports a certificate location to another.
from a file to a Move-Item Moves an item from one
certificate store. location to another.

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
5 POWERSHELL

Web cmdlets cmdlets and scripting capabilities.

• PowerShell includes several built-in providers,


These cmdlets are used for working with web-
including the FileSystem provider for working
related technologies, such as HTTP requests, REST
with files and directories, the Registry provider
APIs, and HTML parsing.
for working with the Windows registry, and the
Certificate provider for working with digital
Cmdlet Description
certificates.
Invoke-WebRequest Sends an HTTP or
• Providers are accessed using a PSDrive, which
HTTPS request to a web
is a virtual drive that represents the data store.
page and returns the
PSDrives are created using the New-PSDrive
response.
cmdlet and can be assigned a letter, a name, or
Invoke-RestMethod Sends an HTTP or any other unique identifier.
HTTPS request to a
• Once a PSDrive is created, it can be accessed
RESTful web service and
like a regular drive using PowerShell’s built-in
returns the response.
cmdlets and scripting capabilities. For example,
ConvertTo-Json Converts a PowerShell the Get-ChildItem cmdlet can be used to
object to a JSON- retrieve a list of files and directories in the
formatted string. PSDrive.

ConvertFrom-Json Converts a JSON- • PowerShell also allows users to create custom


formatted string to a providers using PowerShell scripts or compiled
PowerShell object. code. This allows users to extend the
functionality of PowerShell and create
Test-NetConnection Tests the availability of a
specialized providers tailored to their specific
network connection by
needs.
performing a ping or a
port test. • Providers can be used in pipelines along with
cmdlets, allowing complex operations to be
Resolve-DnsName Resolves a DNS name to
performed on data stores. For example, a script
an IP address.
could retrieve a list of files using the FileSystem
provider, filter the list using the Where-Object
Note that these categories are not exhaustive and
cmdlet, and then modify the files using the Set-
there may be some overlap between them. Also, not
Item cmdlet.
all categories may be relevant to your particular
use case.
OBJECTS AND PIPELINES
PROVIDERS In PowerShell, everything is an object. This means
that all data types, including numbers, strings, and
Providers in PowerShell are a way of accessing data
even commands, are represented as objects in
stores in a hierarchical format, such as a file
PowerShell. Objects in PowerShell have properties,
system, registry, or certificate store. Providers are
methods, and events, which can be manipulated
similar to cmdlets in that they can be used in
and accessed using PowerShell’s built-in cmdlets
pipelines and follow a consistent naming
and scripting capabilities.
convention, but they are specialized for working
with specific data stores.
Here are some key things to know about objects
and pipelines in PowerShell:
Here are some key things to know about providers
in PowerShell:
• Objects are created by cmdlets and returned as
output to the pipeline. Each object has a set of
• Providers are used to representing data stores
properties, which can be retrieved using the
in a way that is consistent with PowerShell’s
Select-Object cmdlet or accessed directly using
object-oriented nature. This allows data stores
dot notation. For example, the Get-Process
to be manipulated using PowerShell’s built-in
cmdlet returns a list of process objects, each

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
6 POWERSHELL

with properties such as Name, Id, and CPU. networking.

• Pipelines in PowerShell are used to pass objects • Modules can be loaded using the Import-Module
from one cmdlet to another, allowing complex cmdlet or automatically loaded when needed
operations to be performed on data without the based on module auto-discovery settings.
need for intermediate variables. For example,
• Once a module is loaded, its cmdlets and
the output of Get-Process can be passed to
functions can be used in the PowerShell
Select-Object to retrieve only the Name and CPU
session. For example, the Get-ADUser cmdlet in
properties, and then to Sort-Object to sort the
the ActiveDirectory module can be used to
results by CPU usage.
retrieve information about users in Active
• PowerShell’s pipeline supports both filtering Directory.
and sorting, as well as a variety of other
• Modules can be managed using the Get-Module,
operations such as grouping, joining, and
Import-Module, and Remove-Module cmdlets,
formatting. This allows users to perform
which allow users to list loaded modules, load
complex data manipulations using simple one-
new modules, and remove loaded modules,
liners.
respectively.
• PowerShell also supports the creation of
• Users can create their own modules using
custom objects using the New-Object cmdlet.
PowerShell scripts and manifest files. This
This allows users to create objects with custom
allows users to package their own cmdlets,
properties and methods, and then pass them to
functions, and other resources for easy
other cmdlets in the pipeline.
distribution and use by others.
• PowerShell’s object-oriented nature allows for
• Modules can also include other resources, such
easy integration with .NET Framework and
as scripts, configuration files, and help files,
other third-party libraries, allowing users to
which can be accessed using the Get-Command,
take advantage of existing code and APIs from
Get-Help, and Get-Content cmdlets, respectively.
within PowerShell scripts.
• PowerShell also supports module versioning,
• One important thing to note is that objects in
which allows users to load and use specific
PowerShell are not always compatible with
versions of a module, ensuring compatibility
other command-line tools that expect text-
with existing scripts and dependencies.
based input and output. In such cases,
PowerShell provides options for converting • Modules can be published to PowerShell
objects to text and vice versa, such as the galleries, such as the PowerShell Gallery or a
ConvertTo-Json and ConvertFrom-Json cmdlets private gallery, for easy sharing and
for working with JSON data. installation by others.

MODULES VARIABLES

Modules in PowerShell are collections of cmdlets, Variables in PowerShell are used to store and
functions, providers, and other resources that can manipulate data in scripts and interactive sessions.
be loaded and used in PowerShell. Modules allow PowerShell supports several different types of
users to extend the functionality of PowerShell variables, each with its own scope and lifetime.
beyond the built-in cmdlets and provide a way to
share code and functionality with others. Here are some key things to know about variables
in PowerShell:
Here are some key things to know about modules in
PowerShell: • Variables in PowerShell are represented using
a dollar sign $ followed by the variable name.
• PowerShell includes several built-in modules, For example, $myVariable is a valid variable
such as the ActiveDirectory module for name in PowerShell.
working with Active Directory, the Hyper-V • PowerShell supports several different types of
module for managing virtual machines, and the variables, including scalar variables (which
NetTCPIP module for working with TCP/IP store a single value), array variables (which

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
7 POWERSHELL

store multiple values of the same type), and function keyword, followed by the function
hash tables (which store key-value pairs). name, any parameters the function accepts,
and the body of the function enclosed in braces.
• Variables in PowerShell have a scope, which
For example, function MyFunction { Write-
determines where the variable is visible and
Output "Hello, World!" } defines a function
accessible. PowerShell supports several
called MyFunction that simply writes the string
different scopes, including global (which is
"Hello, World!" to the console.
visible throughout the entire session), local
(which is visible only within the current script • Functions in PowerShell can accept
or function), and script (which is visible parameters, which are used to pass data into
throughout the entire script but not outside of the function. Parameters are defined inside the
it). parentheses following the function name,
separated by commas. For example, function
• PowerShell also supports automatic variables,
MyFunction ($Name) { Write-Output "Hello,
which are predefined variables that hold
$Name!" } defines a function called MyFunction
system information such as the current user,
that accepts a parameter called $Name and
the last error message, and the current
writes a personalized greeting to the console.
directory.
• Functions in PowerShell can return values
• PowerShell allows variables to be assigned
using the return keyword. For example,
values using the = operator. For example,
function Add-Numbers ($a, $b) { return $a +
$myVariable = "Hello, World!" assigns the
$b } defines a function called Add-Numbers that
string "Hello, World!" to the variable
accepts two parameters, adds them together,
$myVariable.
and returns the result.
• PowerShell also supports variable expansion,
• Functions in PowerShell can be saved to disk as
which allows variables to be used inside strings
script files, just like regular PowerShell scripts.
and other commands. Variable expansion is
This allows you to reuse functions across
done using the $() syntax. For example, "The
different scripts and sessions.
value of my variable is $($myVariable)" would
expand to "The value of my variable is Hello, • PowerShell supports several different types of
World!" if $myVariable was assigned the string functions, including advanced functions (which
"Hello, World!". provide additional features like parameter
validation and pipeline input), script functions
• PowerShell allows variables to be passed
(which allow you to define a function as a
between cmdlets and functions using the
separate script file), and anonymous functions
pipeline. For example, Get-ChildItem | Where-
(which are defined inline as part of a larger
Object {$_.Name -like "*.txt"} | Select-
command).
Object FullName retrieves a list of files, filters
the list to include only files with a .txt • PowerShell functions can be called from other
extension, and then returns the full path of functions, scripts, or interactive sessions,
each file as a string object to the pipeline. These making them a powerful tool for building
string objects can then be assigned to a variable complex automation workflows.
for further processing or manipulation.
SCRIPTS
FUNCTIONS
Scripts in PowerShell are text files that contain a
Functions in PowerShell are reusable blocks of code series of PowerShell commands and statements.
that perform a specific task. They allow you to write They allow you to automate tasks by running the
complex scripts more easily by breaking them same set of commands multiple times, or by
down into smaller, more manageable pieces. running them on a schedule.

Here are some key things to know about functions Here are some key things to know about scripts in
in PowerShell: PowerShell:

• Functions in PowerShell are defined using the • PowerShell scripts are saved as plain text files

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
8 POWERSHELL

with a .ps1 file extension. They can be edited in computer and the remote computer. WinRM
any text editor, including the built-in must be enabled and configured on both the
PowerShell Integrated Scripting Environment local and remote computers before PowerShell
(ISE). Remoting can be used.

• PowerShell scripts are executed by invoking • PowerShell Remoting can be initiated from the
the powershell.exe executable and passing the local computer using the Enter-PSSession
script file as a command-line argument. For cmdlet or the Invoke-Command cmdlet. Enter-
example, powershell.exe -File PSSession creates an interactive session with
C:ScriptsMyScript.ps1 runs a script file called the remote computer, allowing you to enter
MyScript.ps1 located in the C:Scripts directory. commands as if you were physically present at
the remote computer. Invoke-Command executes a
• PowerShell scripts can contain any valid
single command or script on the remote
PowerShell command or statement, including
computer and returns the results to the local
cmdlets, functions, variables, loops, and
computer.
conditional statements. They can also include
comments, which are denoted by the # symbol. • PowerShell Remoting requires that you have
administrative privileges on both the local and
• PowerShell scripts can accept parameters,
remote computers in order to establish a
which are used to pass data into the script.
connection and execute commands. You must
Parameters are defined using the param
also have the appropriate permissions to access
keyword at the beginning of the script,
and modify the resources on the remote
followed by the parameter names enclosed in
computer.
parentheses. For example, param($Name) Write-
Output "Hello, $Name!" defines a script that • PowerShell Remoting supports several
accepts a parameter called $Name and writes a authentication methods, including Kerberos,
personalized greeting to the console. Negotiate, and Basic authentication. You can
also use Secure Sockets Layer (SSL) or
• PowerShell scripts can be run on a schedule
Transport Layer Security (TLS) to encrypt the
using the Windows Task Scheduler. This allows
connection between the local and remote
you to automate tasks like backups, report
computers.
generation, and system maintenance without
manual intervention. • PowerShell Remoting allows you to manage
multiple remote computers simultaneously
• PowerShell scripts can be used to build more
using a single command. This makes it easy to
complex automation workflows by calling
perform common administrative tasks like
other scripts, functions, or cmdlets. This allows
software installation, patching, and
you to break down large tasks into smaller,
configuration changes across a large number of
more manageable pieces that can be reused
computers.
across different scripts and sessions.
• PowerShell Remoting can be configured to run
commands in the background, allowing you to
REMOTING
continue working on other tasks while the
PowerShell Remoting allows you to execute remote command executes. This is especially
PowerShell commands and scripts on remote useful for long-running tasks like software
computers. It enables you to manage large numbers installations or system backups.
of computers or servers from a single, centralized • PowerShell Remoting can be used in
location, without having to physically access each combination with other PowerShell features
one. like workflows and Desired State Configuration
(DSC) to build complex automation workflows
Here are some key things to know about
and ensure consistent configuration across
PowerShell Remoting:
large numbers of computers.

• PowerShell Remoting relies on the Windows


Remote Management (WinRM) service to
establish a connection between the local

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
9 POWERSHELL

THE
THELANGUAGE
LANGUAGE cmdlet.

• PowerShell scripts can be written using a


SYNTAX AND GRAMMAR variety of text editors and integrated
development environments (IDEs), including
PowerShell has its own syntax and grammar rules the built-in PowerShell Integrated Scripting
that govern how commands and scripts are written Environment (ISE), Visual Studio Code, and
and executed. Here are some key things to know Notepad++. These tools provide features like
about the syntax and grammar of PowerShell: syntax highlighting, code completion, and
debugging support to make it easier to write
• PowerShell commands are composed of
and test PowerShell scripts.
cmdlets, parameters, and arguments. A cmdlet
is a PowerShell command that performs a
specific action, like Get-Process or Set-Item.
DATA TYPES
Parameters modify the behavior of a cmdlet
PowerShell supports a variety of data types that can
and are specified using a dash followed by the
be used to store and manipulate values in scripts
parameter name, like -Name or -Path.
and commands. Here are some of the most common
Arguments are values that are passed to a
data types in PowerShell:
cmdlet or parameter and are usually enclosed
in parentheses or quotation marks, like (Get-
Types Description
ChildItem) or "C:MyFolder".
Strings A string is a sequence of
• PowerShell uses a pipeline to pass objects
characters that is
between cmdlets. A pipeline is denoted by the |
enclosed in quotation
symbol and allows you to chain together
marks. Strings can be
multiple cmdlets to perform complex
concatenated using the +
operations. For example, Get-ChildItem |
operator, or interpolated
Where-Object {$_.Name -like "*.txt"} retrieves
into other strings using
all files in the current directory with an .txt
the $ symbol. For
extension.
example, "Hello, " +
• PowerShell uses a set of reserved keywords to "world" would produce
define its grammar and syntax. These include the string "Hello, world"
keywords like if, else, for, and while, which are
Integers An integer is a whole
used to create conditional statements and loops
number that can be
in PowerShell scripts.
positive or negative.
• PowerShell uses a variable naming convention Integers can be used in
that begins with a $ symbol, followed by a arithmetic operations
name that describes the purpose of the like addition,
variable. For example, $Name might be used to subtraction,
store the name of a user or computer. multiplication, and
division. For example, $x
• PowerShell scripts are saved with a .ps1 file
= 10 + 5 would assign
extension and can be executed from the
the value 15 to the
PowerShell console or from the command line
variable $x
using the powershell.exe executable.
PowerShell scripts can also be run on a
schedule using the Windows Task Scheduler.

• PowerShell scripts can be debugged using a


built-in debugging environment that allows you
to step through each line of code and view the
values of variables and expressions. Debugging
can be initiated by running a script with the
-Debug parameter, or by setting breakpoints
within the script using the Set-PSBreakpoint

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
10 POWERSHELL

Types Description Types Description

Booleans A boolean is a value that Objects An object is a complex


is either true or false. data type that contains
Booleans can be used in properties and methods.
conditional statements Objects can be created
and loops to control using the New-Object
program flow. For cmdlet, and properties
example, if ($x -eq 10) can be accessed using
{ "x is equal to 10" } dot notation. For
would output the example, $myObject =
message "x is equal to New-Object -TypeName
PSObject -Property @{
10" if the variable $x has
Name = "John"; Age = 30
the value 10
} would create an object
Arrays An array is a collection with two properties,
of values that can be "Name" and "Age". The
accessed using an index. value of the "Name"
Arrays can be created property could be
using the @() operator, accessed using
and elements can be $myObject.Name
added or removed using
methods like Add() and VARIABLES AND OPERATORS
Remove(). For example,
$myArray = @(1, 2, 3) Variables and operators are essential components
would create an array of any programming language, including
with three elements PowerShell. Here is a brief overview of variables
Hashtables A hashtable is a and operators in PowerShell:
collection of key-value
pairs that can be Variables
accessed using the key.
In PowerShell, variables are used to store data that
Hashtables can be
can be used and manipulated in scripts and
created using the @{}
commands.
operator, and values can
be added or removed
Variables are defined using the $ symbol followed
using methods like Add()
by the variable name. For example:
and Remove(). For
example, $myHash = @{ $myVariable = "Hello, world!"
Name = "John"; Age = 30
} would create a would assign the string "Hello, world!" to the
hashtable with two keys, variable $myVariable.
"Name" and "Age"
Variables can be used in commands and
expressions by enclosing them in curly braces {}.
For example:

Write-Host "The value of my variable is:


$($myVariable)"

would output the message "The value of my


variable is: Hello, world!".

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
11 POWERSHELL

Operators Bitwise Operators

Operators are used to perform mathematical and In PowerShell, bitwise operators are used to
logical operations on values and variables. manipulate binary values at the bit level. Here are
the bitwise operators available in PowerShell:
Operators Description
Operator Description
+ addition
-bnot Flips all bits in the input
- subtraction
value
* multiplication
-bor Sets each bit in the
/ division result to 1 if either or

% modulus both corresponding bits


in the input values are 1
-eq equal to
-bxor Sets each bit in the
-ne not equal to result to 1 if only one of
-lt less than the corresponding bits
in the input values is 1
-gt greater than
-band Sets each bit in the
-le less than or equal to
result to 1 if both
-ge greater than or equal to corresponding bits in
the input values are 1
-and logical and
-shl Shifts the bits of the
-or logical or
input value to the left by
-not logical not the specified number of
positions
Examples:
-shr Shifts the bits of the
input value to the right
• $x = 10 + 5 assigns the value 15 to the variable
by the specified number
$x.
of positions
• if ($x -eq 15) { Write-Host "x is equal to
15" } would output the message "x is equal to Here’s an example of using bitwise operators in
15" if the variable $x has the value 15. PowerShell:
• $y = $x * 2 assigns the value 30 to the variable
$y.
$a = 0b0110
• if ($x -gt 5 -and $y -lt 40) { Write-Host $b = 0b1010
"Both conditions are true" } would output the
message "Both conditions are true" if the # Bitwise NOT
variable $x has a value greater than 5 and the
$c = -bnot $a
variable $y has a value less than 40.
Write-Host "Bitwise NOT:
Note that PowerShell also supports a variety of $($c.ToString('X'))" # Output: FFFF
other operators and types, such as bitwise FFF9
operators, regular expression operators, and arrays.
The examples above are just a small sampling of # Bitwise OR
what is possible with variables and operators in $c = $a -bor $b
PowerShell. Write-Host "Bitwise OR:
$($c.ToString('X'))" # Output: 1E

# Bitwise XOR

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
12 POWERSHELL

$c = $a -bxor $b Wildcard Description


Write-Host "Bitwise XOR:
[] Matches any single
$($c.ToString('X'))" # Output: 14 character within the
specified range or set.
# Bitwise AND For example, Get-
$c = $a -band $b ChildItem
Write-Host "Bitwise AND: C:WindowsSystem32[abc]*
$($c.ToString('X'))" # Output: 2 returns all files and
folders in the
C:WindowsSystem32
# Shift left
directory that begin
$c = $a -shl 1
with the letters "a", "b",
Write-Host "Shift left: or "c"
$($c.ToString('X'))" # Output: C
- Specifies a range of
characters within [ ].
# Shift right
For example, Get-
$c = $b -shr 1 ChildItem
Write-Host "Shift right: C:WindowsSystem32[a-z]*
$($c.ToString('X'))" # Output: 5 returns all files and
folders in the
C:WindowsSystem32
WILDCARDS directory that begin
with any lowercase
In PowerShell, wildcards are characters that allow letter
you to perform pattern matching when working
with strings or paths. They are used with various {} Specifies a set of

cmdlets and operators to search, filter, and replace alternative characters.

text. For example, Get-


ChildItem
C:Windows{.exe,.dll}
Here are some commonly used wildcards in
returns all files in the
PowerShell:
C:Windows directory that
have either a .exe or
Wildcard Description
.dll extension
* Matches zero or more
characters in a string or Here are some cmdlets and operators that support
path. For example, Get- wildcards:
ChildItem C:Windows*
returns all files and Cmdlet Description
folders in the C:Windows
directory Get-ChildItem Allows you to search for
files and folders using
? Matches any single wildcards
character in a string or
path. For example, Get- Select-String Allows you to search for
ChildItem text in a file or string
C:WindowsSystem32?calc. using wildcards
exe returns all versions
-like<br>-notlike Allows you to filter
of the calc.exe file in the
strings using wildcards
C:WindowsSystem32
directory -match<br>-notmatch Allows you to search for
patterns in a string
using regular
expressions

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
13 POWERSHELL

Here are some examples of using wildcards in is true


PowerShell: } else {
# Code to execute if condition
is false
# Find all files with "log" in their
}
name in the C:WindowsLogs directory
Get-ChildItem C:WindowsLogs*log*
The if keyword is followed by the condition to
# Find all files with a ".txt" check in parentheses, and the code to execute if the
extension in the C:UsersPublic condition is true is enclosed in curly braces {}.

directory
If the condition is false, the code to execute in the
Get-ChildItem C:UsersPublic*.txt
else block is executed instead.

# Search for the word "error" in all You can also chain multiple conditions together
files with a ".log" extension in the using the elseif keyword:
C:WindowsLogs directory
Get-ChildItem C:WindowsLogs*.log |
if (condition1) {
Select-String "error"
# Code to execute if condition1
is true
# Filter all processes whose name
} elseif (condition2) {
begins with "w" using the -like
# Code to execute if condition2
operator
is true
Get-Process | Where-Object { $_.Name
} else {
-like "w*" }
# Code to execute if neither
condition1 nor condition2 is true
# Search for all strings in an array
}
that match a pattern using the
-match operator
$strings = "apple", "banana", You can also use the -and and -or operators to
"cherry" combine conditions together:
$strings -match "a"

if (condition1 -and condition2) {


CONDITIONAL STATEMENTS # Code to execute if both
condition1 and condition2 are true
Conditional statements are an important part of }
any programming language, and PowerShell is no
exception. if (condition1 -or condition2) {
# Code to execute if either
If-Else statements condition1 or condition2 is true
}
If-Else statements allow you to execute different
blocks of code based on whether a certain condition
is true or false.
Ternary Operator
The basic syntax for an If-Else statement is as
In PowerShell, the ternary operator allows you to
follows:
perform a simple comparison and execute one of
two expressions based on the result.

if (condition) {
Here’s an example of using the ternary operator in
# Code to execute if condition
PowerShell:

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
14 POWERSHELL

starts with John." }


$number = 10 "*D*" { Write-Host "The name
contains the letter D." }
$result = if ($number -gt 5) { default { Write-Host "No match
"Greater than 5." } else { "Less found." }
than or equal to 5." } }

# Using ternary operator instead


$result = $number -gt 5 ? "Greater LOOPS
than 5." : "Less than or equal to
Loops are an essential part of any programming
5."
language, and PowerShell provides several types of
loops for repetitive operations. Here is an overview
Write-Host $result of the For, ForEach, and While loops in PowerShell:

Note that the ternary operator is useful for simple For Loop
comparisons and expressions, but can quickly
become unwieldy for more complex scenarios. In The For loop is a classic loop that allows you to
those cases, it’s better to use an if statement for iterate over a range of values a specific number of
clarity and readability. times.

The basic syntax for a For loop is as follows:


Switch

In PowerShell, switch statements are used to


for ($i = 0; $i -lt 10; $i++) {
compare a single value against a set of possible
# Code to execute for each
values and perform different actions based on the
iteration
match. Here is the basic syntax for a switch
statement:
}

The first statement initializes a counter variable $i


switch -exact ($value) {
to 0, the second statement checks if the counter is
<value1> { <action1> }
less than 10, and the third statement increments the
<value2> { <action2> } counter by 1 after each iteration.
<value3> { <action3> }
default { <default-action> } The code to execute for each iteration is enclosed in
} curly braces {}.

ForEach Loop
Switch statements can also be used with regular
expressions or wildcards to match against patterns. The ForEach loop allows you to iterate over a
To use a regular expression, use the -regex collection of items, such as an array or a list.
parameter instead of -exact. To use a wildcard
pattern, use the -wildcard parameter instead of The basic syntax for a ForEach loop is as follows:
-exact.

foreach ($item in $collection) {


$name = "John Doe" # Code to execute for each item
in the collection
switch -wildcard ($name) { }
"*Doe" { Write-Host "The name
ends with Doe." }
The $item variable is assigned each item in the
"John*" { Write-Host "The name

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
15 POWERSHELL

collection in turn, and the code to execute for each would return the first item in the array.
item is enclosed in curly braces {}.
You can add items to an array using the += operator.
For example:
While Loop
$array += "new item"
The While loop allows you to repeatedly execute a
block of code while a certain condition is true.
would add the string "new item" to the end of the
array.
The basic syntax for a While loop is as follows:

Example:

while (condition) {
# Code to execute while # Create an array of strings
condition is true $colors = ("red", "green", "blue")
}
# Access individual items in the
The code to execute is enclosed in curly braces {}, array
and the condition is checked at the beginning of Write-Host $colors[0] # Output:
each iteration. red

Examples: # Add a new item to the end of the


array
• for ($i = 0; $i -lt 10; $i++) { Write-Host $i
} would output the numbers 0 through 9, one
$colors += "yellow"
per line. Write-Host $colors # Output:
red green blue yellow
• $colors = @("red", "green", "blue") ; foreach
($color in $colors) { Write-Host $color }
would output the strings "red", "green", and
Hashtables
"blue", one per line.

• $i = 0 ; while ($i -lt 10) { Write-Host $i ; A hashtable is a collection of key-value pairs, where
$i++ } would output the numbers 0 through 9, each key is unique and maps to a specific value.
one per line.
In PowerShell, you can create a hashtable using the
@{} notation, with each key-value pair separated by
DATA STRUCTURES a semicolon ;.

Arrays and Hashtables are two important data


You can access the value for a specific key using the
structures in PowerShell that allow you to store and
$hashtable[key] notation. For example:
manipulate collections of values. Here is an
overview of Arrays and Hashtables in PowerShell: $hashtable["key1"]

would return the value associated with the key


Arrays
"key1".
An array is a collection of items of the same data
type, such as strings or integers. You can add a new key-value pair to a hashtable
using the $hashtable[key] = value notation.
In PowerShell, you can create an array by enclosing
a comma-separated list of values in parentheses (). Example:

You can access individual items in an array by their


index, which starts at 0. For example: # Create a hashtable of key-value
pairs
$array[0] $ages = @{

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
16 POWERSHELL

"John" = 30 element of the list


"Jane" = 25
}
Slicing an Array

# Access the value for a specific You can extract a slice of an array using the ..
key operator. Here’s an example:
Write-Host $ages["John"] #
Output: 30
$list = @(1, 2, 3, "four", "five")
# Add a new key-value pair $slice = $list[1..3] # returns
$ages["Bob"] = 40 the elements at index 1, 2, and 3
Write-Host $ages #
Output: {John=30; Jane=25; Bob=40}
Removing Elements from a List

You can remove elements from a list using the


Note that PowerShell also supports other types of
Remove() method. Here’s an example:
collections, such as Lists and Queues, which may be
useful in specific situations. However, Arrays and
Hashtables are the most commonly used data
$list = @(1, 2, 3, "four", "five")
structures in PowerShell scripts.
$list.Remove(2) # removes the
element at index 2
Lists

A list is a collection of items that can be of any type.


In PowerShell, you can create a list using the @()
REGULAR EXPRESSIONS
notation. Here’s an example:
Regular Expressions (regex or regexp) is a powerful
tool used for pattern matching and text
manipulation. In PowerShell, you can use regular
$list = @(1, 2, 3, "four", "five")
expressions with a variety of cmdlets and operators
to perform advanced text processing tasks. Here’s
an overview of how to use regular expressions in
Adding Elements to a List
PowerShell:
You can add elements to a list using the += operator.
Here’s an example: Select-String : Is used to search for patterns in
strings or files using regular expressions. It returns
the matching lines and the patterns found in those
$list = @() lines.
$list += 1
$list += 2, 3, 4
# Search for the pattern "error" in
$list += "five"
a file using regular expressions
Get-Content C:log.txt | Select-
Accessing Elements of a List String -Pattern "error"

You can access elements of a list using the []


operator. Here’s an example: -match : Is used to check if a string matches a
regular expression pattern. It returns a Boolean
value.
$list = @(1, 2, 3, "four", "five")
$list[0] # returns the element
# Check if a string matches a
at index 0
regular expression pattern
$list[-1] # returns the last

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
17 POWERSHELL

if ($string -match "pattern") { ERROR HANDLING


# do something
In PowerShell, you can use the Try-Catch statement
}
to handle errors that might occur during script
execution. The Try block contains the code that
-replace : Is used to replace text that matches a might throw an error, while the Catch block
regular expression pattern with a new string. contains the code that is executed if an error
occurs.

# Replace text that matches a Here’s an example of using Try-Catch statement in


regular expression pattern PowerShell:
$string -replace "pattern", "new
string"
try {
# Code that might throw an error
Regular expression patterns can include special Get-ChildItem -Path
characters and metacharacters to match specific "C:SomePathThatDoesNotExist"
types of characters or patterns. For example, the . }
metacharacter matches any single character, while catch {
* matches zero or more occurrences of the
# Code that handles the error
preceding character or group.
Write-Host "An error occurred:
$($_.Exception.Message)"
# Use a regular expression pattern }
to match an IP address
if ($string -match You can also use the Finally block to specify code
"d{1,3}.d{1,3}.d{1,3}.d{1,3}") { that will always be executed, regardless of whether
# do something an error occurs. This can be useful for tasks such as
} cleaning up resources or logging errors.

Here’s an example of using Try-Catch-Finally


PowerShell also includes a number of regular statement in PowerShell:
expression operators and flags that can be used to
modify how regular expressions are matched. For
example, the -regex operator can be used to try {
perform case-insensitive matching, while the -split # Code that might throw an error
operator can be used to split a string into an array $file = Get-Content
using a regular expression pattern as the delimiter.
"C:SomeFileThatDoesNotExist"
}
# Perform a case-insensitive match catch {
using regular expressions # Code that handles the error
if ($string -iregex "pattern") { Write-Host "An error occurred:
# do something $($_.Exception.Message)"
} }
finally {
# Split a string into an array using # Code that is always executed
a regular expression pattern as the Remove-Item -Path
delimiter "C:SomeTempFile.txt" -Force
$array = $string -split "s+" }

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!


STARTING WITH WINDOWS
18 POWERSHELL

DEBUGGING Here’s an example of using Write-Debug statements


to debug a script:
In PowerShell, you can use several methods to
debug your scripts, including:
function Test-Debug {
• Debugging with the PowerShell ISE : If you Write-Debug "Starting function"
are using the PowerShell ISE, you can use the $var1 = "Hello"
built-in debugging features to step through
Write-Debug "Var1 value: $var1"
your code, set breakpoints, and inspect
$var2 = "World"
variables. To enable debugging, click on the
Write-Debug "Var2 value: $var2"
Debug menu, and select Start Debugging or
press F5.
$result = "$var1 $var2"
Write-Debug "Result value:
• Debugging with Visual Studio Code : If you
$result"
are using Visual Studio Code, you can use the
return $result
PowerShell extension to debug your scripts. To
}
enable debugging, add a breakpoint to your
code by clicking on the line number, then press
F5 to start debugging. Write-Debug "Starting script"
$result = Test-Debug
• Adding Write-Debug statements : You can add
Write-Host "Result: $result"
Write-Debug statements to your code to output
debug information. These statements will only
be displayed if you run your script with the The Starting script statement is also a Write-Debug
-Debug parameter. statement, but since debug mode is not enabled, it
• Using the Set-PSDebug cmdlet : You can use will not be displayed. To run the script in debug
the Set-PSDebug cmdlet to enable or disable mode, run it with the -Debug parameter:
debug mode. When debug mode is enabled,
PowerShell will display additional debug
.MyScript.ps1 -Debug
information, such as the current line of code
and the values of variables.
When run in debug mode, the script will output the
Write-Debug statements, as well as additional debug
information.

JCG delivers over 1 million pages each month to more than 700K software
developers, architects and decision makers. JCG offers something for everyone,
including news, tutorials, cheatsheets, research guides, feature articles, source code
and more.
CHEATSHEET FEEDBACK
WELCOME
[email protected]

Copyright © 2014 Exelixis Media P.C. All rights reserved. No part of this publication may be SPONSORSHIP
reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, OPPORTUNITIES
mechanical, photocopying, or otherwise, without prior written permission of the publisher. [email protected]

JAVACODEGEEKS.COM | © EXELIXIS MEDIA P.C. VISIT JAVACODEGEEKS.COM FOR MORE!

You might also like