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> Shell Scripting> Mastering Windows PowerShell Scripting
Mastering Windows PowerShell Scripting
Mastering Windows PowerShell Scripting

Mastering Windows PowerShell Scripting: One-stop guide to automating administrative tasks , Second Edition

Arrow left icon
Profile Icon Chris DentProfile Icon Brenton J.W. Blawat
Arrow right icon
$48.99
Full star iconFull star iconFull star iconHalf star iconEmpty star icon3.3(8 Ratings)
PaperbackOct 2017440 pages2nd Edition
eBook
$9.99 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Chris DentProfile Icon Brenton J.W. Blawat
Arrow right icon
$48.99
Full star iconFull star iconFull star iconHalf star iconEmpty star icon3.3(8 Ratings)
PaperbackOct 2017440 pages2nd Edition
eBook
$9.99 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$9.99 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with Print?

Product feature iconInstant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
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

Contact Details

Modal Close icon
Payment Processing...
tickCompleted

Shipping Address

Billing Address

Shipping Methods
Table of content iconView table of contentsPreview book icon Preview Book

Mastering Windows PowerShell Scripting

Introduction to PowerShell

I write this as PowerShell approaches its 10th birthday since its release. PowerShell has come a long way since that time.

For me, PowerShell has gone from being a speculative replacement for a mixture of VBScript, C#, and Perl to a complex language with a great community.

This book is split into a number of sections. Much of the book is intended to act as a reference. We will cover the following topics in this book:

  • Exploring PowerShell fundamentals
  • Working with data
  • Automating with PowerShell
  • Extending PowerShell

In the first section of this book, while exploring the PowerShell fundamentals, we will look at the use of language and cover as many building blocks as possible.

In this chapter, we will briefly look at a number of short, diverse topics:

  • What is PowerShell?
  • Quick reference
  • PowerShell editors
  • PowerShell on Linux

Quick reference

There is a wide variety of quick references available for PowerShell. This particular reference is intended to kick-start the book, as a lot of this is either not explicitly explained or used often before in a more detailed explanation.

Comments

Refer to the following table:

Line comment

#
# This is a line comment

Block comment

<#

#>
<#
This is a block or multi-line comment
#>

Special characters

Refer to the following table:

Statement separator

;

Get-Command Get-Process; Get-Command Get-Help

Call operator

&
& ‘Get-Process’   # Invoke the string as a command
& { Get-Process –Id $PID } # Invoke the script block

Dot-source operator

.
. C:\script.ps1    # Execute the script in the current scope (instead of its own scope)

Tick in PowerShell

PowerShell uses a tick as a multipurposeescaped character.

A tick may be used as a line continuation character. Consider the following example:

'one' -replace 'o', 't' `       -replace 'n', 'w' `       -replace 'e', 'o'

When using a tick to split a long statement across several lines, the tick must be the last character (it cannot be followed by a space or any other character).

A tick is used to construct several characters that can be used in strings:

DescriptionStringASCII character code

Null

`00

Bell sound

`a7

Backspace

`b8

New page form feed

`f12

Line feed

`n10

Carriage return

`r13

Horizontal tab

`t9

Vertical tab

`v11

 

Thetab character, for example, may be included in a string:

PS> Write-Host "First`tSecond" First Second

Alternatively, the bell sound may be played in the PowerShell console (but not ISE):

Write-Host "`a"

Common operators

Refer to the following table:

Equal to

-eq
1 –eq 1    # Returns $true
1 –eq 2 # Returns $false

Not equal to

-ne
1 –ne 2    # Returns $true
1 –ne 1 # Returns $false

And

-and
$true –and $true    # Returns $true
$true –and $false # Returns $false
$false –and $false # Returns $false

Or

-or
$true –or $true    # Returns $true
$true –or $false # Returns $true
$false –or $false # Returns $false

Addition and concatenation

+
1 + 1            # Equals 2
“one” + “one” # Equals oneone

Subexpression operator

$( )
“Culture is $($host.CurrentCulture)”
“Culture is $(Get-Culture)”

Dropping unwanted output

Refer to the following table:

Assign tonull

$null = Expression
$null = Get-Command

Cast tovoid

[Void](Expression)
[Void](Get-Command)

Pipe toOut-Null

Expression | Out-Null
Get-Command | Out-Null

Redirect tonull

Expression > $null
Get-Command > $null

Creating arrays and hashtables

Refer to the following table:

Using the array operator

@()
$array = @()    # Empty array
$array = @(1, 2, 3, 4)

Implicit array

Value1, Value2, Value3
$array = 1, 2, 3, 4
$array = “one”, “two”, “three”, “four”

Using thehashtable operator

@{}
$hashtable = @{}    # Empty hashtable
$hashtable = @{Key1 = “Value1”}
$hashtable = @{Key1 = “Value1”; Key2 = “Value2”}

Strings

Refer to the following table:

Expanding string

“ “
“Value”
$greeting = “Hello”; “$greeting World” # Expands variable

Expanding here-string

@”

“@
$one = ‘One’
@”
Must be opened on its own line.
This string will expand variables like $var.
Can contain other quotes like “ and ‘.
Must be closed on its own line with no preceding white space.
“@

Non-expanding string

‘ ‘
‘Value’
‘$greeting World’ # Does not expand variable

Non-expanding here-string

@’

‘@
@’
Must be opened on its own line.
This string will not expand variables like $var.
Can contain other quotes like “ and ‘.
Must be closed on its own line with no preceding white space.
‘@

Quotes in strings

“ `” “

“ ““ “

‘ `’ ‘

‘ ‘‘ ‘
“Double-quotes may be escaped with tick like `”.”
“Or double-quotes may be escaped with another quote ““.”
‘Single-quotes may be escaped with tick like `’.’
‘Or single-quotes may be escaped with another quote like ‘‘.’

Common reserved variables

Refer to the following table:

Errors

$Error
$Error[0]    # The last error

Formats the enumeration limit. Dictates the number of elements displayed for objects with properties based on arrays.

The default is4.

$FormatEnumerationLimit
$object = [PSCustomObject]@{
Array = @(1, 2, 3, 4, 5)
}
$object # Shows 1, 2, 3, and 4
$formatenumerationlimit = 1
$object # Shows 1

Holds data of the current PowerShell host.

$Host
$host
$host.UI.RawUI.WindowTitle
The matches found when using the-match operator.$Matches
‘text’ –match ‘.*’
$matches

The output field separator.

The default is a single space.

Dictates how arrays are joined when included in an expandable string.
$OFS
$arr = 1, 2, 3, 4
“Joined based on OFS: $arr”
$ofs = ‘, ‘
“Joined based on OFS: $arr”

Current PowerShell process ID.

$PID
Get-Process –Id $PID

Holds the path to each of theprofile files.

$PROFILE
$profile.AllUsersAllHosts
$profile.AllUsersCurrentHost
$profile.CurrentUserAllHosts
$profile.CurrentUserCurrentHost

PowerShell version information.

$PSVersionTable

$PSVersionTable.PSVersion

Present working directory.

$PWD
$PWD.Path

Quick commands and hot keys

Refer to the following table:

ise

ise <file>

Opens PowerShell ISE.

Opens a file with ISE if a filename is given.

code

code <file or folder>

If Visual Studio Code is installed (and in%PATH%).

Opens the VS Code.

Opens a file or folder with the VS Code.

Get-History

history
Shows command history for the current session.
<Text><Tab>

Autocompletes in context.Tab can be used to complete command names, parameter names, and some parameter values.

#<Text><Tab>

Autocompletes against history (beginning of the line).Typing#get-and repeatedly pressingTabwill cycle through all commands containingGet-from your history.

iiii is an alias for theinvoke-item. Opens the current directory in Explorer.
start iexplore

start is an alias for the start-process. Opens Internet Explorer.

start <name> -verb runasRuns a process as administrator.

PowerShell editors

While it is possible to write for PowerShell using the Notepad application alone, it is rarely desirable. Using an editor designed to work with PowerShell can save a lot of time.

Specialized PowerShell editors, at a minimum, offer automatic completion (IntelliSense) that reduces the amount of cross-referencing required while writing code. Finding a comfortable editor early is a good way to ease into PowerShell: memorizing commands and parameters is not necessary.

Two editors are discussed, as follows:

  • PowerShell ISE
  • Visual Studio Code

PowerShell ISE

PowerShellIntegratedScriptingEnvironment (ISE) was introduced with PowerShell 2 in October 2009 and has been updated with every subsequent release.

ISE has an immediate advantage over other editors. It is installed along with PowerShell itself and is likely to be available in some form wherever PowerShell is. ISE consists of a text editor pane and a script pane, as shown in the following screenshot:

Features

ISE is a rich editing environment that includes IntelliSense, built-in help, syntax checking, debugging, and so on.

Additional features are available for ISE from the following add-on tools website:

http://social.technet.microsoft.com/wiki/contents/articles/2969.windows-powershell-ise-add-on-tools.aspx

If you are developing code for use on production systems, I strongly recommend adding PS Script Analyzer. PS Script Analyzer will highlight areas of your code that do not conform to its rule set; for example, using an alias instead of a command name would be highlighted.

Community and commercial add-ons can greatly extend the functionality of ISE to simplify day-to-day use.

Installing ISE Preview

In PowerShell 5, the distribution model for ISE is in the process of changing. Until version 5, ISE was released as a part of theWindows Management Framework (WMF). New features were introduced with each version of WMF, but the time between the versions was long.

ISE Preview may be installed from the PowerShell gallery using the following command:

Install-Module -Name PowerShellISE-Preview

Once installed, theupdate-module command may be used to bring ISE up to par with the published version.

ISE Preview can coexist with the version of ISE installed by the WMF package.

Starting ISE

ISE may be started from the start menu; however, running thepowershell_isecommand (from theRun dialog,cmd, or the search box) is sufficient. In PowerShell, the simplerisecommand is aliased topowershell_ise.exe.

If the preview version from the PowerShell gallery is being used, the following command will start that version of ISE:

Start-ISEPreview

This first preview version differs a little from the version of ISE shipping with WMF 5. If the distribution model is successful, the PowerShell team hopes to release a new version of ISE every month, with each release fixing bugs and/or adding new features.

Visual Studio Code

Visual Studio Code is a free open source editor published by Microsoft. VS Code may be downloaded fromhttp://code.visualstudio.com.

VS Code is a good choice of editor when working with multiple languages or when specifically looking for an editor that supports Git in a simple manner.

Features

VS Code does not come with the native PowerShell support. It must be added. Once VS Code is installed, open it, and select theEXTENSIONS button on the left-hand side.

TypePowerShell in the search dialog box, and install the PowerShell language support:

After installation, the extension providesSyntax highlighting, testing usingPowerShell Script Analyzer, debugging, and so on.

Console

Unlike ISE, the console (or terminal, as it is named) in VS Code must be configured. By default, the terminal in code usescmd.exe.

The following process is used to make the terminal use PowerShell:

  1. OpenUserSettings fromFileandPreferences. The same may be achieved by pressingF1 and typinguser settings followed by return.
  2. This opens two windows: aDefault Settings file on the left and asettings.json on the right. The file on the right holds user-specific configuration that overrides or adds to the default.
  3. Expand theIntegrated Terminal section inDefault Settings (by clicking on theo9 symbol) to show the default values.
  4. On the right-hand side, enter the following between the curly braces:
"terminal.integrated.shell.windows": "C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
  1. Save the changes, then pressCtrl+Shift+' (apostrophe) to open a new PowerShell terminal.Ctrl +' (apostrophe) toggles the visibility of the terminal window.
This is not ISE
In PowerShell ISE,F5 +F8 may be used to execute a script. This is not the case in VS Code. A selection may be executed by pressingF1 and typingrun selected to filter options toTerminal: Run Selected Text in Active Terminal.

Version control (Git)

Visual Studio Code comes with integrated support for Git version control. Git is a distributed version control system; each developer has a copy of the same repository.

Setting up a repository is simple, as follows:

  1. Open a folder that contains a project. Then, select theGit button (or pressCtrl +Shift +G).
  2. Click onInitialize git repository button as shown in the following screenshot:
  1. Once you have done this, files may be added to version control when committing (applying a change).

Subsequent changes to files may be inspected before committing again:

PowerShell on Linux

PowerShell for Linux is, at least at the time of writing, in alpha. The current release is still worth installing even if only to see what having a unified shell may look like.

What about Cygwin?
PowerShell is not the first to give a hint of a single shell across different operating systems. However, until PowerShell matured, it was a serious challenge to manage Windows and Microsoft-based systems from the command line alone.

Some familiarity with Linux is assumed during this process.

Installing PowerShell

This installation is based on PowerShell 6, alpha 12 as the latest at the time of writing. The package can be downloaded from GitHub withyum, which will also install the dependencies (https://github.com/PowerShell/PowerShell/releases/latest):

  1. The following command will install PowerShell and any dependencies (libicu,libunwind, anduuid):
sudo yum install https://github.com/PowerShell/PowerShell/releases/download/v6.0.0-alpha.12/powershell-6.0.0_alpha.12-1.el7.centos.x86_64.rpm

alpha 12 is the latest release but it may not be when you read this.

  1. PowerShell can be immediately started by running the following command:
powershell
  1. Create a few files in thehome directory as a test:
Set-Location ~ 1..10 | ForEach-Object { New-Item $_ -ItemType File }
  1. The previous command creates10 empty files named1 to10 (with no file extension). Ensure that the new files are now visible usingGet-ChildItem:
Get-ChildItem
ls versus Get-ChildItem:
On Windows,ls (list) in PowerShell is an alias forGet-ChildItem. On Linux,ls is the original command. SeeGet-Alias -Definition Get-ChildItem to view what still is.

Where are the PowerShell files?

Several of the followingused paths are specific to the installed release (in this case, alpha 12).

As with PowerShell on Windows, thePSHOME variable shows where PowerShell itself has been installed:

PS> $PSHOME /opt/microsoft/powershell/6.0.0-alpha.12

The paths for module installation may be viewed using the environment variables:

PS> $env:PSMODULEPATH -split ':' /home/psuser/.local/share/powershell/Modules /usr/local/share/powershell/Modules /opt/microsoft/powershell/6.0.0-alpha.12/Modules
Case sensitivity
Linux has a much higher regard for case than Windows. Environment variables, file paths, executables, and so on, are case sensitive. The previously used variable name must be written in uppercase.
UseGet-ChildItem to list all of the environment variables using the following command:
Get-ChildItem env:

Changing the shell

Once installed, PowerShell is visible in the list of available shells:

chsh -l

Set PowerShell as the defaultshell for the current user:

chsh New shell [/bin/bash]: /usr/bin/powershell

Profiles

The current user profile on Linux resides under the home directory:

~/.config/powershell

Two profiles can be created:CurrentUserCurrentHost (Microsoft.PowerShell_profile.ps1) andCurrent User (profile.ps1). Inspecting the automatic variable,$PROFILE shows the first of these:

  1. The directory will need to be created prior to use; the following command creates it:
New-Item ~/.config/powershell -ItemType Directory
  1. Create a simple profile file by sending a string to a file:
‘Write-Host “Welcome to PowerShell” -ForegroundColor Green’ |
Out-File .config/powershell/profile.ps1
  1. TheAllUser profile may be created under PowerShell's installation directory, in this case, alpha 12, as this is the version I have installed:
/opt/microsoft/powershell/6.0.0-alpha.12
  1. Writing to this area of the filesystem requires theroot privileges:
sudo vi /opt/microsoft/powershell/6.0.0-alpha.12/profile.ps1
  1. Insidevi, pressi to enter insert mode and then type the following:
Write-Host 'This is the system profile' -ForegroundColor Yellow
  1. Once completed, pressEsc, then type:wq to save and quitvi.
  2. As with PowerShell on Windows, this will be executed before a user-levelprofile that shows the following in the console when the shell is started:
This is the system profile Welcome to PowerShell

Multiplatform scripting

PowerShell on Linux (and macOS) has a long way to go to reach maturity. Our experience writing for these systems has to make a similar journey.

One of the most important facets is that Linux and macOS run PowerShell Core. It lacks some features we may have become used to when writing for Windows.

Line endings

Windows editors, including ISE, tend to use a carriage return followed by linefeed (\r\n or`r`n) at the end of each line. Linux editors use linefeed only (\n or`n).

Line endings are less important if the only thing reading the file is PowerShell (on any platform). However, if a script is set to executable on Linux, a sha-bang must be included and the line-ending character used must be linefeed only.

For example, a created as follows namedtest.ps1 must use\n to end lines:

#!/usr/bin/env powershell Get-Process

The first line is the sha-bang and lets Linux know which parser to use when executing the shell script.

Once created,chmod may be used to make the script executable outside of PowerShell:

chmod +x test.ps1

After being made executable, the script may be executed frombash with the full path or a relative path:

./test.ps1
Editor defaults
PowerShell ISE uses carriage return followed by line feed (\r\n). This behavior is by design and cannot be changed.
Visual Studio Code uses\r\n for line endings by default. This may be changed inUser Settings by adding the following command:
"files.eol": "\n"

File encoding

Windows editors, including ISE, tend to save files using what is commonly known as ANSI encoding; this is more correctly known as Windows-1252.

As Windows-1252 is a Microsoft native format, it may be more appropriate to save files in a universally accepted format such as UTF8.

Editor defaults
PowerShell ISE defaults to saving files in UTF8 with aByte Order Mark (BOM).
Visual Studio Code saves files using UTF8 (without a BOM) by default. The setting may be changed inUser Settings by adding"files.encoding": "utf8bom".

Path separator

Testing shows that PowerShell on Linux is forgiving about path separators; that is, Microsoft Windows uses the backslash (\), where Linux uses a forward slash (/).

If anything outside of PowerShell (including native commands) is to be used, a correct separator should be chosen.

TheJoin-Path command will merge path elements using the correct separator for each platform. Manual path construction (based on merging strings) should be avoided.

Example

The following function uses theSystem.Net.NetworkInformation namespace to discover IPv4 address information. This allows us to return the same thing whether it is run on Windows or Linux.

If it were Windows only, we might have used WMI or theGet-NetIPConfiguration command. Creating something to work on both operating systems is more challenging:

function Get-IPConfig {     [System.Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() | ForEach-Object {         $ipProperties = $_.GetIPProperties()                      $addresses = $ipProperties.UnicastAddresses |             Where-Object {                 $_.Address.AddressFamily -eq 'InterNetwork'             } | ForEach-Object {                 "$($_.Address) $($_.IPv4Mask)"             }          $gateway = $ipProperties.GatewayAddresses.Address |             Where-Object {                 $_.AddressFamily -eq 'InterNetwork' -and                  $_ -ne '0.0.0.0'             }          [PSCustomObject]@{             Name      = $_.Name             Id        = $_.Id             Addresses = $addresses             Gateway   = $gateway         }     } | Where-Object { $_.Addresses } } Get-IPConfig
Left arrow icon

Page1 of 6

Right arrow icon

Key benefits

  • Find quick solutions to automate your environment with ease
  • Work with large amounts of data effortlessly with PowerShell data types and secure them
  • Packed with real-world examples to automate and simplify the management of your Windows environment

Description

PowerShell scripts offer a handy way to automate various chores. Working with these scripts effectively can be a difficult task.This comprehensive guide starts from scratch and covers advanced-level topics to make you a PowerShell expert. The first module, PowerShell Fundamentals, begins with new features, installing PowerShell on Linux, working with parameters and objects, and also how you can work with .NET classes from within PowerShell. In the next module, you’ll see how to efficiently manage large amounts of data and interact with other services using PowerShell. You’ll be able to make the most of PowerShell’s powerful automation feature, where you will have different methods to parse and manipulate data, regular expressions, and WMI.After automation, you will enter the Extending PowerShell module, which covers topics such as asynchronous processing and, creating modules. The final step is to secure your PowerShell, so you will land in the last module, Securing and Debugging PowerShell, which covers PowerShell execution policies, error handling techniques, and testing. By the end of the book, you will be an expert in using the PowerShell language.

Who is this book for?

If you are a system administrator who wants to become an expert in controlling and automating your Windows environment, then this book is for you. It is also for those new to the PowerShell language.

What you will learn

  • * Optimize code through the use of functions, switches, and looping structures
  • * Install PowerShell on your Linux system
  • * Utilize variables, hashes, and arrays to store data
  • * Work with Objects and Operators to test and manipulate data
  • * Parse and manipulate different data types
  • * Write .NET classes with ease within the PowerShell
  • * Create and implement regular expressions in PowerShell scripts
  • * Deploy applications and code with PowerShell's Package management modules
  • * Leverage session-based remote management
  • * Manage files, folders, and registries through the use of PowerShell
Estimated delivery feeDeliver to Russia

Economy delivery10 - 13 business days

$6.95

Premium delivery6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date :Oct 27, 2017
Length:440 pages
Edition :2nd
Language :English
ISBN-13 :9781787126305
Vendor :
Microsoft
Languages :

What do you get with Print?

Product feature iconInstant access to your digital copy whilst your Print order is Shipped
Product feature icon Paperback book shipped to your preferred address
Product feature icon Redeem a companion digital copy on all Print orders
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

Contact Details

Modal Close icon
Payment Processing...
tickCompleted

Shipping Address

Billing Address

Shipping Methods
Estimated delivery feeDeliver to Russia

Economy delivery10 - 13 business days

$6.95

Premium delivery6 - 9 business days

$21.95
(Includes tracking information)

Product Details

Publication date :Oct 27, 2017
Length:440 pages
Edition :2nd
Language :English
ISBN-13 :9781787126305
Vendor :
Microsoft
Category :
Languages :
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 $5 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 $5 each
Feature tick iconExclusive print discounts

Frequently bought together


Windows Server 2016 Automation with PowerShell Cookbook
Windows Server 2016 Automation with PowerShell Cookbook
Read more
Sep 2017660 pages
Full star icon4.7 (7)
eBook
eBook
$9.99$51.99
$65.99
Mastering Windows PowerShell Scripting
Mastering Windows PowerShell Scripting
Read more
Oct 2017440 pages
Full star icon3.3 (8)
eBook
eBook
$9.99$39.99
$48.99
Learning PowerShell DSC
Learning PowerShell DSC
Read more
Sep 2017272 pages
Full star icon4 (1)
eBook
eBook
$9.99$39.99
$48.99
Stars icon
Total$163.97
Windows Server 2016 Automation with PowerShell Cookbook
$65.99
Mastering Windows PowerShell Scripting
$48.99
Learning PowerShell DSC
$48.99
Total$163.97Stars icon
Buy 2+ to unlock$7.99 prices - master what's next.
SHOP NOW

Table of Contents

17 Chapters
Introduction to PowerShellChevron down iconChevron up icon
Introduction to PowerShell
What is PowerShell?
Quick reference
PowerShell editors
PowerShell on Linux
Summary
Working with PowerShellChevron down iconChevron up icon
Working with PowerShell
Getting help
Command naming and discovery
Parameters and parameter sets
Providers
Summary
Modules and Snap-InsChevron down iconChevron up icon
Modules and Snap-Ins
What is a module?
What is the PowerShell Gallery?
The Get-Module command
The Import-Module command
The Remove-Module command
The Find-Module command
The Install-Module command
The Save-Module command
What is a snap-in?
Using 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
Binary operators
Logical operators
Type operators
Redirection operators
Other operators
Summary
Variables, Arrays, and HashtablesChevron down iconChevron up icon
Variables, Arrays, and Hashtables
Naming and creating variables
Variable commands
Variable scope
Type and type conversion
Objects assigned to variables
Arrays
Hashtables
Lists, dictionaries, queues, and stacks
Summary
Branching and LoopingChevron down iconChevron up icon
Branching and Looping
Conditional statements
Loops
Summary
Working with .NETChevron down iconChevron up icon
Working with .NET
Assemblies
Namespaces
Types
Classes
Constructors
Properties and methods
Static properties
Static methods
Non-public classes
Type accelerators
Using
Summary
Data Parsing and ManipulationChevron down iconChevron up icon
Data Parsing and Manipulation
String manipulation
Converting strings
Number manipulation
Converting strings to numeric values
Date and time manipulation
Summary
Regular ExpressionsChevron down iconChevron up icon
Regular Expressions
Regex basics
Anchors
Repetition
Character classes
Alternation
Grouping
Examples of regular expressions
Summary
Files, Folders, and the RegistryChevron down iconChevron up icon
Files, Folders, and the Registry
Working with providers
Items
Item properties
Permissions
Transactions
File catalogs
Summary
Windows Management InstrumentationChevron down iconChevron up icon
Windows Management Instrumentation
Working with WMI
CIM cmdlets
The WMI cmdlets
Permissions
Summary
HTML, XML, and JSONChevron down iconChevron up icon
HTML, XML, and JSON
HTML
XML
System.Xml
System.Xml.Linq
JSON
Summary
Working with REST and SOAPChevron down iconChevron up icon
Working with REST and SOAP
Web requests
Working with REST
Working with SOAP
Summary
Remoting and Remote ManagementChevron down iconChevron up icon
Remoting and Remote Management
WS-Management
CIM sessions
PS sessions
The double-hop problem
Summary
TestingChevron down iconChevron up icon
Testing
Static analysis
Testing with Pester
Summary
Error HandlingChevron down iconChevron up icon
Error Handling
Error types
Error action
Raising errors
Catching errors
Summary

Recommendations for you

Left arrow icon
Solutions Architect's Handbook
Solutions Architect's Handbook
Read more
Mar 2024582 pages
Full star icon4.6 (57)
eBook
eBook
$9.99$47.99
$59.99
Mastering Terraform
Mastering Terraform
Read more
Jul 2024506 pages
Full star icon5 (21)
eBook
eBook
$9.99$39.99
$49.99
The Ultimate Linux Shell Scripting Guide
The Ultimate Linux Shell Scripting Guide
Read more
Oct 2024696 pages
Full star icon4.9 (8)
eBook
eBook
$9.99$39.99
$49.99
Kubernetes – An Enterprise Guide
Kubernetes – An Enterprise Guide
Read more
Aug 2024682 pages
Full star icon4.8 (13)
eBook
eBook
$9.99$43.99
$54.99
The Self-Taught Cloud Computing Engineer
The Self-Taught Cloud Computing Engineer
Read more
Sep 2023480 pages
Full star icon5 (180)
eBook
eBook
$9.99$39.99
$49.99
CI/CD Design Patterns
CI/CD Design Patterns
Read more
Dec 2024356 pages
eBook
eBook
$9.99$31.99
$39.99
Platform Engineering for Architects
Platform Engineering for Architects
Read more
Oct 2024374 pages
Full star icon5 (2)
eBook
eBook
$9.99$39.99
$49.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
$9.99$35.99
$44.99
The Ultimate Docker Container Book
The Ultimate Docker Container Book
Read more
Aug 2023626 pages
Full star icon4 (8)
eBook
eBook
$9.99$39.99
$49.99
Right arrow icon

Customer reviews

Top Reviews
Rating distribution
Full star iconFull star iconFull star iconHalf star iconEmpty star icon3.3
(8 Ratings)
5 star25%
4 star25%
3 star12.5%
2 star25%
1 star12.5%
Filter icon Filter
Top Reviews

Filter reviews by




nickpMar 13, 2018
Full star iconFull star iconFull star iconFull star iconFull star icon5
I really enjoyed this book. full disclosure: - i was given a copy by the publisher to review, but i would happily have paid for it. i am a Microsoft trainer, and deliver the Microsoft 10961 "Automating Administration with Windows Powershell" course three or four times a year; this book makes an excellent supplement to that course, especially now Microsoft only give students the electronic skillpipe version of the training material. The book not only covers but expands on all the course material, providing in-depth explanations, tips and tricks and pointing out some of the pitfalls. There are also a number of chapters on subjects that are not covered in the course that have become more important in the last few years, such as working with REST, HTML and JSON calls, and testing using Pester. Add in an excellent introductory chapter to working with .NET and all the powershell regex i ever want to see, and the book is a winner. i am recommending it to my colleagues and students.if there was one thing that could be improved upon, it would be the examples. i would like to see more 'real-world' examples, using things an admin might do, rather than some of the simple ones that are given to demonstrate the syntax.other than that, i loved it. i'll be forking out for a paper copy i can put next to my first edition "powershell scripting and toolmaking" book.
Amazon Verified reviewAmazon
Mr. BannerDec 29, 2018
Full star iconFull star iconFull star iconFull star iconFull star icon5
Great for entry level powershell users
Amazon Verified reviewAmazon
Dung H NguyenApr 18, 2019
Full star iconFull star iconFull star iconFull star iconEmpty star icon4
This is good book for advanced programmers. If anyone wants to explore more codes, he should read this books at least couple times.
Amazon Verified reviewAmazon
WorksGreatSoFarJul 09, 2018
Full star iconFull star iconFull star iconFull star iconEmpty star icon4
An excellent book to start with to understand and take your powershell scripting to the next level.
Amazon Verified reviewAmazon
michaelMay 25, 2018
Full star iconFull star iconFull star iconEmpty star iconEmpty star icon3
Giving 3 stars because I don’t consider this a “mastering” book. It’s more of a reference guide/learn it fast guide. I’ve read multiple books, and this book is lacking detail and content.
Amazon Verified reviewAmazon
  • Arrow left icon Previous
  • 1
  • 2
  • 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.6 (36)
eBook
eBook
$9.99$43.99
$54.99
The Ultimate Docker Container Book
The Ultimate Docker Container Book
Read more
Aug 2023626 pages
Full star icon4 (8)
eBook
eBook
$9.99$39.99
$49.99
Mastering Kubernetes
Mastering Kubernetes
Read more
Jun 2023746 pages
Full star icon4.6 (45)
eBook
eBook
$9.99$43.99
$54.99
Ansible for Real-Life Automation
Ansible for Real-Life Automation
Read more
Sep 2022480 pages
Full star icon3.9 (7)
eBook
eBook
$9.99$33.99
$41.99
AWS for Solutions Architects
AWS for Solutions Architects
Read more
Apr 2023696 pages
Full star icon4.3 (62)
eBook
eBook
$9.99$59.99
$79.99
Right arrow icon

About the authors

Left arrow icon
Profile icon Chris Dent
Chris Dent
LinkedIn iconGithub 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
Profile icon Brenton J.W. Blawat
Brenton J.W. Blawat
Brenton J.W. Blawat is an entrepreneur, strategic technical advisor, author, and enterprise architect, who has a passion for the procurement of technology in profit-based organizations. He is business-centric and technology-minded. Brenton has many years of experience in bridging the gap between technical staff and decision-makers in several organizations. He takes pride in his ability to effectively communicate with a diverse audience and provide strategic direction for large and small organizations alike._x000D_ In 2013, Brenton authored his first book, PowerShell 3.0 WMI Starter, Packt Publishing. In March 2015, he authored his second book Mastering Windows PowerShell Scripting, Packt Publishing._x000D_ Brenton currently works at CDW as an Enterprise Architect in strategic solutions and services. CDW is a leading multibrand technology solutions provider in the fields of business, government, education, and healthcare. A Fortune 500 company, it was founded in 1984 and employs approximately 7,200 coworkers. In 2016, the company generated net sales of more than $13.0 billion._x000D_ His current specialisation sits on top of 15 years experience spread across (predominantly Microsoft) systems, (Juniper and Cisco) networking, and security.
Read more
See other products by Brenton J.W. Blawat
Right arrow icon
Getfree access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the digital copy I get with my Print order?Chevron down iconChevron up icon

When you buy any Print edition of our Books, you can redeem (for free) the eBook edition of the Print Book you’ve purchased. This gives you instant access to your book when you make an order via PDF, EPUB or our online Reader experience.

What is the delivery time and cost of print book?Chevron down iconChevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium:Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge?Chevron down iconChevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order?Chevron down iconChevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries:www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges?Chevron down iconChevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live inMexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live inTurkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order?Chevron down iconChevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy?Chevron down iconChevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged?Chevron down iconChevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use?Chevron down iconChevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books?Chevron down iconChevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium:Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela

Create a Free Account To Continue Reading

Modal Close icon
OR
    First name is required.
    Last name is required.

The Password should contain at least :

  • 8 characters
  • 1 uppercase
  • 1 number
Notify me about special offers, personalized product recommendations, and learning tips By signing up for the free trial you will receive emails related to this service, you can unsubscribe at any time
By clicking ‘Create Account’, you are agreeing to ourPrivacy Policy andTerms & Conditions
Already have an account? SIGN IN

Sign in to activate your 7-day free access

Modal Close icon
OR
By redeeming the free trial you will receive emails related to this service, you can unsubscribe at any time.

[8]ページ先頭

©2009-2025 Movatter.jp