Movatterモバイル変換


[0]ホーム

URL:


Packt
Search iconClose icon
Search icon CANCEL
Subscription
0
Cart icon
Your Cart(0 item)
Close icon
You have no products in your basket yet
Save more on your purchases!discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Profile icon
Account
Close icon

Change country

Modal Close icon
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timerSALE ENDS IN
0Days
:
00Hours
:
00Minutes
:
00Seconds
Home> Cloud & Networking> System Administration> Mastering PowerShell Scripting
Mastering PowerShell Scripting
Mastering PowerShell Scripting

Mastering PowerShell Scripting: Automate and manage your environment using PowerShell 7.1 , Fourth Edition

Arrow left icon
Profile Icon Chris Dent
Arrow right icon
Can$71.99Can$80.99
Full star iconFull star iconFull star iconFull star iconHalf star icon4.1(20 Ratings)
eBookJun 2021788 pages4th Edition
eBook
Can$71.99 Can$80.99
Paperback
Can$101.99
Subscription
Free Trial
Arrow left icon
Profile Icon Chris Dent
Arrow right icon
Can$71.99Can$80.99
Full star iconFull star iconFull star iconFull star iconHalf star icon4.1(20 Ratings)
eBookJun 2021788 pages4th Edition
eBook
Can$71.99 Can$80.99
Paperback
Can$101.99
Subscription
Free Trial
eBook
Can$71.99 Can$80.99
Paperback
Can$101.99
Subscription
Free Trial

What do you get with eBook?

Product feature iconInstant access to your Digital eBook purchase
Product feature icon Download this book inEPUB andPDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature iconDRM FREE - Read whenever, wherever and however you want
Product feature iconAI Assistant (beta) to help accelerate your learning
OR

Contact Details

Modal Close icon
Payment Processing...
tickCompleted

Billing Address

Table of content iconView table of contentsPreview book icon Preview Book

Mastering PowerShell Scripting

Modules and Snap-Ins

Modules are packaged collections of commands that may be loaded inside PowerShell, allowing PowerShell to interact with new systems and services. Modules come from a wide variety of different sources.

PowerShell itself is installed with a small number of modules, includingThreadJob andPSReadline.

You can install modules by adding Windows features or enabling capabilities, for example, the ActiveDirectory andGroupPolicy modules.

Some applications include modules; for example, MicrosoftLocal Administrator Password Solution (LAPS) includes a PowerShell module in the installer that you can use to manage some of the features of the application.

The Windows platform itself includes many modules, most of these having been included since Windows 8 was released.

Finally, you can install modules from the PowerShell Gallery or another registered repository. The PowerShell Gallery can include updated versions of PowerShell installed modules.

The PowerShell Gallery is therefore a valuable source of modules published by Microsoft, VMware, Amazon Web Services, and many others.

Snap-ins were included in PowerShell 1 and largely replaced with modules with the release of PowerShell 2. PowerShell 7 does not support snap-ins; snap-ins are limited to Windows PowerShell.

The chapter covers the following topics:

  • Introducing modules
  • Using Windows PowerShell modules in PowerShell 7
  • PowerShellGet 3.0
  • PowerShell repositories
  • About snap-ins

Introducing modules

Modules were introduced with therelease of PowerShell version 2.0. A module is a packaged set of commands that includes any required supporting content; modules often include help content.

Modules tend to target a specific system or focus on a small set of related operations. For example, theMicrosoft.PowerShell.Archive module contains a small number of commands for interacting with ZIP files.

The modules available on a system can be discovered using theGet-Module command.

The Get-Module command

Get-Module is used to find the moduleseither in the current PowerShell session, or available on the current system.

PowerShell itselfcomes with several built-in modules, includingPowerShellGet,ThreadJob,PSReadLine, and the commands in theMicrosoft.PowerShell.* modules.

The Windows platform, especially the most recent versions, comes with a wide variety of modules installed. These, as well as any other available modules, can be viewed using the Get-Module -ListAvailable command.

By default,Get-Module returns information about each module that has been imported (either automatically or by usingImport-Module). For example, if the command is run from PowerShell 7, it shows that theISE module has been loaded:

PS> Get-ModuleModuleType    Version    Name                            ExportedCommands ----------    -------    ----                            ---------------- Script        1.0.0.0    ISE                             {Get-IseSnippe...}Manifest      3.1.0.0    Microsoft.PowerShell.Management {Add-Computer...}

TheListAvailable parameter shows the list of modules that are available on the system instead of just those that have been imported:

Get-Module-ListAvailable

Modules are discoveredusing the paths in thePSModulePath environment variable, which contains a delimited list of paths for PowerShell to search.

Get-Module will show allinstances of a module regardless of the path and version when using theAll parameter:

Get-Module <ModuleName>-All-ListAvailable

Modules that are available on a system can be imported either by runningImport-Module or by running a command from the module.

The Import-Module command

PowerShell 3 and laterattempts to automatically load modules if a command from that module is used and the module is under one of thepaths in the$env:PSModulePath environment variable. Explicit use of theImport-Module command is less important than it was before Windows PowerShell 3.

For example, if PowerShell is started and theCimCmdlets module is not imported, running theGet-CimInstance command will cause the module to be automatically imported. This is shown in the following example:

PS> Get-Module CimCmdletsPS> Get-CimInstance Win32_OperatingSystem | Out-NullPS> Get-Module CimCmdletsModuleType Version    PreRelease Name         ExportedCommands---------- -------    ---------- ----         ----------------Binary     7.0.0.0               CimCmdlets   {Get-CimAssociatedInstance,...

The autoloader may be disabled using the$PSModuleAutoLoadingPreference variable as shown here:

$PSModuleAutoLoadingPreference ='None'

You can explicitly import modules in PowerShell using theImport-Module command. Modules may be imported using a name or with a full path, as shown in the following example:

Import-Module-Name ThreadJobImport-Module-Name$PSHome\Modules\ThreadJob\ThreadJob.psd1

Importing a module using apath is only required if the module is not in a discoverable path.

Once a module has been imported, thecommands within the module may be listed usingGet-Command as follows:

Get-Command-Module ThreadJob

Modules, Get-Command, and auto-loading

As the commands exported by a module are only identified by PowerShell importing the module, the previous command will also trigger an automatic import.

Modules installed in Windows PowerShell 5 and later are placed in a folder named after the module version, for example,Modules\ModuleName\1.0.0\<ModuleContent>. This allows multiple versions of the same module to coexist, as shown in the following example:

Figure 2.1: Side-by-side versioning

Version1.8.1 ofPSScriptAnalyzer will be imported by default, as it is the highest version number. It is possible to import a specific version of a module using theMinimumVersion andMaximumVersion parameters:

Import-Module PSScriptAnalyzer-MaxmimumVersion1.7.0

Modules that have been imported can be removed from a PowerShell session using theRemove-Module command.

The Remove-Module command

TheRemove-Module commandremoves a previously imported module from the current session.

For binary modules ormanifest modules that incorporate aDynamic Link Library (DLL), commands are removed from PowerShell but DLLs are notunloaded. DLL files used in a PowerShell session cannot be unloaded without restarting the PowerShell process.

Remove-Module does not remove or delete the files that make up a module from a computer.

Each of the preceding commands, by default, interacts with modules saved in thePSModulePath environment variable.

PSModulePath in PowerShell

PSModulePath is adelimited list of paths that can be used to store modules. You can import modules in these paths by name and they will be automatically loaded when a command from the module is used.

PowerShellallows the value of$env:PSModulePath to be set usinguser- andmachine-scoped environment variables. By default, themachine-scoped variable should include the following paths, which are used by Windows PowerShell and by PowerShell 7 for compatibility:

C:\Program Files\WindowsPowerShell\ModulesC:\Windows\System32\WindowsPowerShell\v1.0\Modules

If the environment variables do not exist, PowerShell 7 uses the default values:

PS>$Env:PSModulePath -split';'C:\Users\whoami\Documents\PowerShell\ModulesC:\Program Files\PowerShell\Modulesc:\program files\powershell\7\Modules

The default values in the preceding list are included regardless of the value of the environment variable.

When using module paths, it is important to note that PowerShell does not search all paths for the latest version of a module. PowerShell searches the list of paths in the order they appear in thePSModulePath environment variable. If a module is listed in more than one path, the most recent version from the first discovered path is used.

For example, if thecurrent user path contains a module with version 1.0.0, and the program files path contains the same module but with version 2.0.0, PowerShell will prefer to load version 1.0.0 because the current user path is searched first. TheVersion orMinimumVersion parameter must be used withImport-Module to avoid this.

If bothWindows PowerShell and PowerShell 7 are in use in an environment, care must be taken when updating thePSModulePath environment variable. The behavior described previously differs from Windows PowerShell. In Windows PowerShell:

  • If theuser environment variable is set, it completely replaces the user value, which defaults toC:\Users\whoami\Documents\WindowsPowerShell\Modules
  • If themachine environment variable is set, it replaces thesystem32 path:C:\windows\system32\windowspowershell\v1.0\Modules
  • In all cases, theC:\Program Files\WindowsPowerShell\Modules path remains

TheC:\windows\system32\windowspowershell\v1.0\Modules path should be included in the machine environment variable to allow PowerShell 7 to load modules, either directly or using a Windows PowerShell compatibility session.

The value of$env:PSModulePath may be safely modified within on all PowerShell versions and all platforms, for example, by using a profile script. Changes made to$env:PSModulePath are scoped to the process and only affect the current PowerShell session and any child processes; the changes do not persist.

PowerShell 7 can use modules intended for Windows PowerShell either directly or by using a Windows PowerShell compatibility session.

Using Windows PowerShell modules in PowerShell 7

Manymodules available to Windows PowerShell are compatible with PowerShell 7 without requiring any changes.

If a module is notcompatible with PowerShell 7, an attempt can be made to load the module in a Windows compatibility session.

In PowerShell 6, the following functionality discussed is part of theWindowsCompatibility module available in the PowerShell Gallery. This module is not required in PowerShell 7. In PowerShell 7, the ability to load a module in a compatibility session is built into theImport-Module command.

TheTLS module, for example, willnot load PowerShell 7 by default because it does not state that it supports the Core edition of PowerShell, as shown byGet-Module:

PS> Get-Module TLS -ListAvailable -SkipEditionCheck    Directory: C:\Windows\System32\WindowsPowerShell\v1.0\ModulesModuleType Version    PreRelease Name       PSEdition ExportedCommands---------- -------    ---------- ----       --------- ----------------Manifest   2.0.0.0               TLS        Desk      {New-TlsSessionTic...

The module can be loaded in two ways:

The edition checkcan be skipped (the module may work, it may just lack testing, and therefore careful testing may be required before using the module in a production scenario):

Import-Module TLS-SkipEditionCheck

Alternatively, if the previous command fails, the module may load in a compatibility session:

PS> Import-Module TLS -UseWindowsPowerShellWARNING: Module TLS is loaded in Windows PowerShell using WinPSCompatSession remoting session; please note that all input and output of commands from this module will be deserialized objects. If you want to load this module into PowerShell Core please use 'Import-Module -SkipEditionCheck' syntax.

The compatibility session can be seen using theGet-PSSession command after the module has been imported:

Get-PSSession-Name WinPSCompatSession

When importing the precedingTLS module, a warning message is displayed that notes the input and output is deserialized. The impact of this depends on the complexity of the objects returned by the command; typically, it will mean that methods of specialized types will not work from PowerShell 7.

The effect of this can be demonstrated by invokingGet-WmiObject in the compatibility session.Get-WmiObject is not available in PowerShell 7 and cannot be directly used:

$session =Get-PSSession-Name WinPSCompatSession$process =Invoke-Command-Session$session-ScriptBlock {Get-WmiObject Win32_Process-Filter"ProcessID=$PID"}

If theGet-WmiObject command isrun in Windows PowerShell without usingInvoke-Command, it will have several methods available. One of these methods isGetRelated, which is typically used as follows when used inWindows PowerShell:

$process =Get-WmiObject Win32_Process-Filter"ProcessID=$PID"$process.GetRelated('Win32_Session')

Because PowerShell 7 has a copy of the properties only, the method does not exist and an error will be displayed:

PS>$session = Get-PSSession -Name WinPSCompatSessionPS>$process = Invoke-Command -Session$session -ScriptBlock {>>     Get-WmiObject Win32_Process -Filter"ProcessID=$PID">> }PS>$process.GetRelated('Win32_Session')InvalidOperation: Method invocation failed because [Deserialized.System.Management.ManagementObject#root\cimv2\Win32_Process] does not contain a method named 'GetRelated'.

The compatibility feature is incredibly useful but does not replace native compatibility with modern versions of PowerShell.

PowerShell on the Windows platform has a wide variety of modules available, or available through installable applications and features to interact with other systems. New modules can also be installed from resources such as the PowerShell Gallery.

Finding and installing modules

PowerShell includes amodule namedPowerShellGet, which can be used to registerrepositories and search for and install modules.

By default,PowerShellGet searches the PowerShell Gallery.

What is the PowerShell Gallery?

The PowerShell Gallery is aMicrosoft-run repository and distribution platform for PowerShell scripts and modules written by Microsoft or other users.

The PowerShell Gallery has parallels in other scripting languages, as shown in the following examples:

  • Perl hascpan.org
  • Python has PyPI
  • Ruby has RubyGems

Support for the gallery is included by default in PowerShell 5 and above. For Windows PowerShell 3 and 4, PowerShellGet must beinstalled as described in Microsoft Docs:https://docs.microsoft.com/powershell/scripting/gallery/installing-psget.

The PowerShell Gallerymay be searched usinghttps://www.powershellgallery.com as shown in the following screenshot:

Figure 2.2: Searching the PowerShell Gallery

You can use theFind-Module command tosearch the PowerShell Gallery, or any registered repository, instead of using the web page.

The Find-Module command

Find-Module is used to search registeredPowerShell repositories. Modules are identified by name, as shown in the following example:

Find-Module CarbonFind-Module-Name CarbonFind-Module-Name Azure*

You can use theFilter parameter when the name alone is not sufficient to find an appropriate module. Supplying a value for theFilter parameter is equivalent to using the search field in the PowerShell Gallery, it expands the search to include tags:

Find-Module-Filter IIS

TheFind-Module command cannot filter based on PowerShell edition, and the result of the search does not state whichversion the module might work with.

Once found, a module can be installed using theInstall-Module command.

The Install-Module command

TheInstall-Module command installsmodules from the PowerShell Gallery or any other configured repository. By default,Install-Module adds modules to the path forAllUsers, atC:\Program Files\PowerShell\Modules on Windows and at/usr/local/share/powershell/Modules on Ubuntu.

Access rights

Installing a module under theAllUsers scope requires administrative access.

For example, theposh-git module may be installed using either of the following two commands:

Find-Module-Name posh-git |Install-ModuleInstall-Module posh-git

Modules may be installed under a user-specific path ($home\Documents\WindowsPowerShell\Modules) using theScope parameter:

Install-Module carbon-Scope CurrentUser

If the most recent version of a module is already installed, the command ends without providing feedback. If a newer version is available, it will be automatically installed alongside the original.

TheForce parameter may be used to reinstall a module:

Install-Module posh-git-Force

Force may also be used to install a newer version of a module when the existing version was not installed from a PS repository, or when changing the scope a module is installed in.

TheInstall-Module command does not provide an option to install modules under the$PSHOME directory. The$PSHOME directory is reserved for modules that are shipped with the PowerShell installer, or for Windows PowerShell, those that are shipped with the Windows operating system.

The Update-Module command

You can use theUpdate-Module command toupdate any module installed using theInstall-Module command.

In both Windows PowerShell and PowerShell 7,Update-Module attempts to update the specified module to the latest or specified version.

The Save-Module command

TheSave-Module command downloads themodule from the PowerShell Gallery (or any other registered repository) to a path without installing it. This is useful if you save a module to an alternate module path, or if you intend to copy the module onto a system that cannot useInstall-Module.

The following example command downloads theCarbon module into aModules directory in the root of theC: drive:

Save-Module-Name Carbon-Path C:\Modules

Save-Module will download the module and overwrite any previously saved version in the specified path. The command ignores other downloaded versions of the module.

Each of the preceding commands is part ofPowerShellGet 2.PowerShellGet 3 is likely to be released in the coming months and adopts a slightly different approach to the commands.

PowerShellGet 3.0

PowerShellGet 2 (for example,PowerShellGet 2.2.4.1) implements theInstall-Module,Update-Module, andSave-Module module commands demonstrated at the beginning of this chapter.

PowerShellGet 3.0 is in preview at thetime of writing; the following commands are based on the beta7 pre-release. One of the key features is that this new version does not depend on thePackageManagement module, allowing a simpler installation process, avoiding the need to bootstrap the NuGet provider, making upgrading the module simpler.

The preview version also uses new command names, completely divorcing it from the previous implementations ofPowerShellGet. The change in command names means the new version can safely be installed alongside any existing version.

PowerShellGet 3.0 can be installed as follows:

Install-Module PowerShellGet-Force-AllowPrerelease

Once installed, you'll need to register the PowerShell Gallery or another repository:

Register-PSResourceRepository-PSGallery

InPowerShellGet 2.0, you implementseparate commands to work with modules and scripts.PowerShellGet 3.0 does not differentiate between modules and scripts; all artifacts are termedPSResource, and all searches use theFind-PSResource command. For example, we can find a module by using the following command:

Find-PSResource-Name Indented.Net.IP-Type Module

TheType parameter may be omitted without affecting the search results in this case.

Most of the commands inPowerShellGet 3.0 use the same approach as those inPowerShellGet 2.2.4 and below. Over time, the differences between the commands are likely to start to appear; for example,Install-PSResource includes aReinstall parameter, which is somewhat like theForce parameter forInstall-Module inPowerShellGet 2.

Repositories

Like older versions ofPowerShellGet, repositories areregistered on a per-user basis. InPowerShellGet 2.2.4 and below, the repository configuration file is found in the following path:

$env:LOCALAPPDATA\Microsoft\Windows\PowerShell\PowerShellGet\PSRepositories.xml

ThePSRepositories.xml file is stored in CliXml format and may be read using theImport-CliXml command. The file is normally read and updated usingGet-PSRepository,Register-PSRepository, andUnregister-PSRespository.

PowerShellGet 3.0 uses a simpler format for thePSResourceRespository.xml file. The file may be found in the following path:

$env:LOCALAPPDATA\PowerShellGet\PSResourceRepository.xml

TheGet-PSResourceRepository,Register-PSResourceRepository, andUnregister-PSResourceRepository commands are the expected way of interacting with this file.

As with older versions ofPowerShellGet, storingcredentials for a repository is not currently supported. If a repository requires authentication, theCredential parameter must be used explicitly with each operation.

Version ranges

Find-PSResource allowswildcards to be used for theVersion parameter; using* will return all available versions except pre-release. ThePrerelease parameter may be added to include those:

Find-PSResource-Name PowerShellGet-Version *

A range of versions may be defined using the range syntax used by NuGet, which is described in the following document:

https://docs.microsoft.com/nuget/concepts/package-versioning#version-ranges-and-wildcards

For example, the highest version ofPowerShellGet available between 1.0 (inclusive) and 2.0 (exclusive) may be found using this:

Find-PSResource-Name PowerShellGet-Version'[1.0,2.0)'

The search can be changed to be inclusive by changing the closing) to]. For example, the following command will find version 2.0.0 ofPowerShellGet:

Find-PSResource-Name PowerShellGet-Version'[1.0,2.0]'

The same syntax will be available when declaring dependencies between modules.

PowerShell repositories

Each of the examples from theprevious section uses the PowerShell Gallery as a source for installing modules. This is an important resource, but in a business setting, it may be desirable to restrict access to the gallery. Instead, an internal repository that holds curated or internally developed content may be implemented to share content.

Creating an SMB repository

A file share is asimple way to share content. Such a repository requires little effort to set up and maintain. A file share may be registered as a repository as follows:

$params =@{    Name               ='Internal'    SourceLocation     ='\\server\share\directory'    InstallationPolicy ='Trusted'}Register-PSRepository @params

Existing modules can be published to the repository using thePublish-Module command. For example, if Pester 5.0.2 is installed, it may be published to the newly created internal repository:

$params =@{    Name            ='pester'    RequiredVersion ='5.0.2'    Repository      ='Internal'}Publish-Module @params

TheRequiredVersion parameter is mandatory if more than one version of the module (in this case Pester) exists on the system publishing the module. Once published, anupkg file will appear in the file share. The Pester module is now available for installation by anyone else with the repository registered.

Users installing content from an SMB share must be authenticated and must have at least read access to the share. Guest access may be granted to avoid the authentication requirement.

NuGet repositories

NuGet is apackage manager for .NET.PowerShellGet can use a NuGet repository as a source for PowerShell modules. The PowerShell Gallery is a NuGet repository.

NuGet offers greater flexibility when dealing with authentication, or package life cycles, when compared with SMB shares.

At the simple end, theChocolatey.Server package availablefromchocolatey.org may be used to configure anInternet Information Services (IIS) website toact as a NuGet repository:

https://chocolatey.org/packages/chocolatey.server

About Chocolatey

Chocolatey is apackage manager for Windows. Seehttps://chocolatey.org for further information.

More advancedservers include Sonatype Nexus and ProGet. Both offer free to use servers, which may be locally deployed. These services must be configured, and once configured, packages will typically be published by using an API key to authenticate.

About snap-ins

Snap-ins, and the commands forinteracting with snap-ins, are only available in Windows PowerShell; they are not present in PowerShell 7.

A snap-in is the precursor to a module. It was the mechanism available to extend the set of commands in PowerShell 1 and was deprecated with the release of PowerShell 2.

You can view the list of installed snap-ins by using the following command:

Get-PSSnapIn-Registered

If theRegistered parameter is excluded,Get-PSSnapIn will show the snap-ins that have been imported into the current PowerShell session.

PowerShell does not automatically load commands from a snap-in. All snap-ins must be explicitly imported using theAdd-PSSnapIn command:

Add-PSSnapIn WDeploySnapin3.0

Once a snap-in has been installed (registered) and added, you can useGet-Command to list the commands as if the snap-in was a module:

Get-Command-Module WDeploySnapin3.0

The snap-in shown will only be visible if the Web Deployment Toolkit 3.0 is installed.

Summary

Modules are a vital part of PowerShell. Modules allow users to extend the commands available within PowerShell, allowing PowerShell to work with many different systems from many different vendors.

The commands explored in this chapter have demonstrated how to discover and use locally available modules along with the commands each module contains. The PowerShell Gallery has been introduced as a public repository of modules, extending PowerShell further still.

PowerShellGet has been a feature of PowerShell since PowerShell 3. With the release of PowerShellGet 3 on the horizon, we demonstrated its new commands and filtering capabilities.

SMB- and NuGet-based repositories were briefly introduced for those looking to establish private repositories for use within an organization. This allows administrators to create private repositories with curated content, reducing exposure to the unknown modules.

Snap-ins, an artifact of PowerShell 1 that is limited to Windows PowerShell, were very briefly demonstrated for the products where snap-ins remain important.

Chapter 3,Working with Objects in PowerShell, dives into the commands available to work with objects in PowerShell, includingWhere-Object andForEach-Object.

Left arrow icon

Page1 of 7

Right arrow icon
Download code iconDownload Code

Key benefits

  • Automate complex tasks, manipulate data, and secure your environment
  • Work with dual code for PowerShell 7 and Windows PowerShell to maintain compatibility with older versions
  • See PowerShell in action, from learning the fundamentals to creating classes, scripts, and modules

Description

PowerShell scripts offer a convenient way to automate various tasks, but working with them can be daunting. Mastering PowerShell Scripting takes away the fear and helps you navigate through PowerShell's capabilities.This extensively revised edition includes new chapters on debugging and troubleshooting and creating GUIs (online chapter). Learn the new features of PowerShell 7.1 by working with parameters, objects, and .NET classes from within PowerShell 7.1.This comprehensive guide starts with the basics before moving on to advanced topics, including asynchronous processing, desired state configuration, using more complex scripts and filters, debugging issues, and error-handling techniques. Explore how to efficiently manage substantial amounts of data and interact with other services using PowerShell 7.1. This book will help you to make the most of PowerShell's automation features, using different methods to parse data, manipulate regular expressions, and work with Windows Management Instrumentation (WMI).

Who is this book for?

This book is for system administrators who want to automate and speed up their processes using PowerShell and Windows PowerShell. You’ll need to know the basics of operating systems, but beginners with no prior experience with PowerShell will have no trouble following along.

What you will learn

  • Optimize code with functions, switches, and looping structures
  • Test and debug your scripts as well as raising and catching errors
  • Work with objects and operators to test and manipulate data
  • Parse and manipulate different data types
  • Use jobs, runspaces, and runspace pools to run code asynchronously
  • Write .NET classes with ease within PowerShell
  • Create and implement regular expressions in PowerShell scripts
  • Make use of advanced techniques to define and restrict the behavior of parameters

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date :Jun 29, 2021
Length:788 pages
Edition :4th
Language :English
ISBN-13 :9781800208575

What do you get with eBook?

Product feature iconInstant access to your Digital eBook purchase
Product feature icon Download this book inEPUB andPDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature iconDRM FREE - Read whenever, wherever and however you want
Product feature iconAI Assistant (beta) to help accelerate your learning
OR

Contact Details

Modal Close icon
Payment Processing...
tickCompleted

Billing Address

Product Details

Publication date :Jun 29, 2021
Length:788 pages
Edition :4th
Language :English
ISBN-13 :9781800208575
Category :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99billed monthly
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconSimple pricing, no contract
$199.99billed annually
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconChoose a DRM-free eBook or Video every month to keep
Feature tick iconPLUS own as many other DRM-free eBooks or Videos as you like for just Can$6 each
Feature tick iconExclusive print discounts
$279.99billed in 18 months
Feature tick iconUnlimited access to Packt's library of 7,000+ practical books and videos
Feature tick iconConstantly refreshed with 50+ new titles a month
Feature tick iconExclusive Early access to books as they're written
Feature tick iconSolve problems while you work with advanced search and reference features
Feature tick iconOffline reading on the mobile app
Feature tick iconChoose a DRM-free eBook or Video every month to keep
Feature tick iconPLUS own as many other DRM-free eBooks or Videos as you like for just Can$6 each
Feature tick iconExclusive print discounts

Frequently bought together


Mastering Active Directory
Mastering Active Directory
Read more
Nov 2021780 pages
Full star icon4.9 (24)
eBook
eBook
Can$49.99Can$55.99
Can$69.99
Can$69.99
Windows Server Automation with PowerShell Cookbook
Windows Server Automation with PowerShell Cookbook
Read more
Jul 2021674 pages
Full star icon4.8 (6)
eBook
eBook
Can$85.99Can$95.99
Can$118.99
Mastering PowerShell Scripting
Mastering PowerShell Scripting
Read more
Jun 2021788 pages
Full star icon4.1 (20)
eBook
eBook
Can$71.99Can$80.99
Can$101.99
Stars icon
TotalCan$290.97
Mastering Active Directory
Can$69.99
Windows Server Automation with PowerShell Cookbook
Can$118.99
Mastering PowerShell Scripting
Can$101.99
TotalCan$290.97Stars icon

Table of Contents

25 Chapters
Introduction to PowerShellChevron down iconChevron up icon
Introduction to PowerShell
What is PowerShell?
PowerShell editors
Getting help
Command naming and discovery
Parameters, values, and parameter sets
Introduction to providers
Introduction to splatting
Parser modes
Experimental features
Summary
Modules and Snap-InsChevron down iconChevron up icon
Modules and Snap-Ins
Introducing modules
Finding and installing modules
PowerShellGet 3.0
PowerShell repositories
About snap-ins
Summary
Working with Objects in PowerShellChevron down iconChevron up icon
Working with Objects in PowerShell
Pipelines
Members
Enumerating and filtering
Selecting and sorting
Grouping and measuring
Comparing
Importing, exporting, and converting
Summary
OperatorsChevron down iconChevron up icon
Operators
Arithmetic operators
Assignment operators
Comparison operators
Regular expression-based operators
Logical operators
Binary operators
Type operators
Redirection operators
Other operators
Summary
Variables, Arrays, and HashtablesChevron down iconChevron up icon
Variables, Arrays, and Hashtables
Naming and creating variables
Objects assigned to variables
Variable commands
Variable provider
Scopes and variables
Types and type conversion
Arrays
Hashtables
Lists, dictionaries, queues, and stacks
Summary
Conditional Statements and LoopsChevron down iconChevron up icon
Conditional Statements and Loops
if, else, and elseif
switch
Loops
Loops, break, and continue
Implicit Boolean
Summary
Working with .NETChevron down iconChevron up icon
Working with .NET
Assemblies
Types
Enumerations
Classes
Namespaces
The using keyword
Type accelerators
Members
Reflection in PowerShell
Summary
Strings, Numbers, and DatesChevron down iconChevron up icon
Strings, Numbers, and Dates
Manipulating strings
Converting strings
Manipulating numbers
Manipulating dates and times
Summary
Regular ExpressionsChevron down iconChevron up icon
Regular Expressions
Regex basics
Anchors
Quantifiers
Character classes
Alternation
Grouping
Look-ahead and look-behind
The .NET Regex type
Regex options
Examples of regular expressions
Summary
Files, Folders, and the RegistryChevron down iconChevron up icon
Files, Folders, and the Registry
Working with providers
Items
Windows permissions
Transactions
File catalog commands
Summary
Windows Management InstrumentationChevron down iconChevron up icon
Windows Management Instrumentation
Working with WMI
CIM cmdlets
The WMI Query Language
WMI Type Accelerators
Permissions
Summary
Working with HTML, XML, and JSONChevron down iconChevron up icon
Working with HTML, XML, and JSON
HTML
XML commands
System.Xml
System.Xml.Linq
JSON
Summary
Web Requests and Web ServicesChevron down iconChevron up icon
Web Requests and Web Services
Technical requirements
Web requests
Working with REST
Working with SOAP
Summary
Remoting and Remote ManagementChevron down iconChevron up icon
Remoting and Remote Management
Technical requirements
WS-Management
PSSessions
Remoting on Linux
Remoting over SSH
The double-hop problem
CIM sessions
Just Enough Administration
Summary
Asynchronous ProcessingChevron down iconChevron up icon
Asynchronous Processing
Working with jobs
Reacting to events
Using runspaces and runspace pools
Summary
Graphical User InterfacesChevron down iconChevron up icon
Graphical User Interfaces
About Windows Presentation Foundation (WPF)
Designing a UI
About XAML
Displaying the UI
Layout
Naming and locating elements
Handling events
Responsive interfaces
Summary
Scripts, Functions, and Script BlocksChevron down iconChevron up icon
Scripts, Functions, and Script Blocks
About style
Capabilities of scripts, functions, and script blocks
Parameters and the param block
The CmdletBinding attribute
The Alias attribute
begin, process, end, and cleanup
Managing output
Working with long lines
Comment-based help
Summary
Parameters, Validation, and Dynamic ParametersChevron down iconChevron up icon
Parameters, Validation, and Dynamic Parameters
The Parameter attribute
Validating input
Pipeline input
Defining parameter sets
Argument completers
Dynamic parameters
Summary
Classes and EnumerationsChevron down iconChevron up icon
Classes and Enumerations
Defining an enumeration
Creating a class
Classes for parameters
Classes and DSC
Summary
Building ModulesChevron down iconChevron up icon
Building Modules
Technical requirements
Creating a module
Publishing a module
Multi-file module layout
Module scope
Initializing and removing modules
Summary
TestingChevron down iconChevron up icon
Testing
Technical requirements
Static analysis
Testing with Pester
Summary
Error HandlingChevron down iconChevron up icon
Error Handling
Error types
Error actions
Raising errors
Catching errors
Summary
Debugging and TroubleshootingChevron down iconChevron up icon
Debugging and Troubleshooting
Common problems
Debugging in the console
Debugging in Visual Studio Code
Summary
Other Books You May EnjoyChevron down iconChevron up icon
Other Books You May Enjoy
IndexChevron down iconChevron up icon
Index

Recommendations for you

Left arrow icon
Solutions Architect's Handbook
Solutions Architect's Handbook
Read more
Mar 2024582 pages
Full star icon4.7 (60)
eBook
eBook
Can$53.99Can$60.99
Can$75.99
Mastering Terraform
Mastering Terraform
Read more
Jul 2024506 pages
Full star icon5 (20)
eBook
eBook
Can$44.99Can$50.99
Can$63.99
The Ultimate Linux Shell Scripting Guide
The Ultimate Linux Shell Scripting Guide
Read more
Oct 2024696 pages
Full star icon4.8 (5)
eBook
eBook
Can$44.99Can$50.99
Can$63.99
Mastering PowerShell Scripting
Mastering PowerShell Scripting
Read more
May 2024826 pages
Full star icon5 (27)
eBook
eBook
Can$44.99Can$50.99
Can$63.99
Kubernetes – An Enterprise Guide
Kubernetes – An Enterprise Guide
Read more
Aug 2024682 pages
Full star icon4.8 (13)
eBook
eBook
Can$49.99Can$55.99
Can$69.99
The Self-Taught Cloud Computing Engineer
The Self-Taught Cloud Computing Engineer
Read more
Sep 2023480 pages
Full star icon5 (180)
eBook
eBook
Can$44.99Can$50.99
Can$63.99
CI/CD Design Patterns
CI/CD Design Patterns
Read more
Dec 2024356 pages
eBook
eBook
Can$35.99Can$40.99
Can$50.99
Platform Engineering for Architects
Platform Engineering for Architects
Read more
Oct 2024374 pages
Full star icon5 (2)
eBook
eBook
Can$44.99Can$50.99
Can$63.99
Microsoft Azure Fundamentals Certification and Beyond
Microsoft Azure Fundamentals Certification and Beyond
Read more
Jan 2024284 pages
Full star icon4.8 (29)
eBook
eBook
Can$40.99Can$45.99
Can$56.99
Right arrow icon

Customer reviews

Top Reviews
Rating distribution
Full star iconFull star iconFull star iconFull star iconHalf star icon4.1
(20 Ratings)
5 star55%
4 star20%
3 star10%
2 star5%
1 star10%
Filter icon Filter
Top Reviews

Filter reviews by




N/AFeb 21, 2024
Full star iconFull star iconFull star iconFull star iconFull star icon5
Pubblicazioni interessanti scritti con il giusto livello tecnico ma soprattutto in modo chiaro.
Feefo Verified reviewFeefo
JoeyASep 03, 2021
Full star iconFull star iconFull star iconFull star iconFull star icon5
Well written book. Great coverage of a variety of topics. Succinct, specific examples provided.I purchased this to have a "master reference" covering a wide gamut of PowerShell. The book delivers!
Amazon Verified reviewAmazon
Jamaal GervaisNov 19, 2023
Full star iconFull star iconFull star iconFull star iconFull star icon5
I have no regrets getting this book! Excellent reference for my future scripts. Easy to digest and there was no fluff.
Amazon Verified reviewAmazon
Alexander WittigAug 05, 2021
Full star iconFull star iconFull star iconFull star iconFull star icon5
I am a PowerShell enthusiast myself, this book is a roundhouse kick of Powershell! It's full of gems and little tricks and hints. From the basics, what is an object, to building GUIs and a ton of info about PowerShell 7 and its features. “PowerShell in a Month of Lunches’ used to by my go to I recommended new people, this is my new ‘goto’, it covers just about anything you want to do with PowerShell.
Amazon Verified reviewAmazon
Girard and NatalieSep 20, 2021
Full star iconFull star iconFull star iconFull star iconFull star icon5
As an IT Pro of over 15 years & using PowerShell for 5 or more of them, this book was so resourceful in assisting me when getting stuck on scripting a new tool to assist in my day to day! A must read for any IT Pro the author did an incredible job of covering the PowerShell platform in full detail!
Amazon Verified reviewAmazon
  • Arrow left icon Previous
  • 1
  • 2
  • 3
  • 4
  • Arrow right icon Next

People who bought this also bought

Left arrow icon
Mastering Ubuntu Server
Mastering Ubuntu Server
Read more
Sep 2022584 pages
Full star icon4.7 (43)
eBook
eBook
Can$38.99Can$55.99
Can$55.98Can$69.99
Mastering Kubernetes
Mastering Kubernetes
Read more
Jun 2023746 pages
Full star icon4.5 (47)
eBook
eBook
Can$49.99Can$55.99
Can$69.99
Ansible for Real-Life Automation
Ansible for Real-Life Automation
Read more
Sep 2022480 pages
Full star icon3.9 (7)
eBook
eBook
Can$37.99Can$42.99
Can$53.99
AWS for Solutions Architects
AWS for Solutions Architects
Read more
Apr 2023696 pages
Full star icon4.3 (64)
eBook
eBook
Can$49.99Can$55.99
Can$69.99
Right arrow icon

About the author

Profile icon Chris Dent
Chris Dent
Github icon
Chris Dent is an automation specialist with deep expertise in the PowerShell language. Chris is often found answering questions about PowerShell in both the UK and virtual PowerShell user groups. Chris has been developing in PowerShell since 2007 and has released several modules over the years.
Read more
See other products by Chris Dent
Getfree access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook?Chevron down iconChevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website?Chevron down iconChevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook?Chevron down iconChevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support?Chevron down iconChevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks?Chevron down iconChevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook?Chevron down iconChevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.


[8]ページ先頭

©2009-2025 Movatter.jp