Errata

Windows PowerShell Cookbook

Errata for Windows PowerShell Cookbook

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
Printed Page xix
Foreward section p2.1 last para - code sample (http://safari.oreilly.com/9780596528492/foreword)

$objShell = New-Object?com Shell.Application

should be

$objShell = New-Object ?comobject Shell.Application

Anonymous   
Printed Page index
throughout

Several online sample programs are missing from the index:

ConvertFrom-FahrenheitWithoutFunction.ps1
ConvertFrom-FahrenheitWithFunction.ps1
ConvertFrom-FahrenheitWithLibrary.ps1
Get-ScriptPerformanceProfile.ps1
Grant-RegistryAccessFullControl.ps1
Invoke-ComplexScript.ps1
Invoke-DemonstrationScript.ps1
Invoke-LongRunningOperation.ps1
InvokeTemplateCmdletCommand.cs
LibraryDirectory.ps1
LibraryInputComparison.ps1
LibraryInvocation.ps1
LibraryPrompt.ps1
LibraryProperties.ps1
Read-InputBox.ps1
RulesWizardExample.cs p. 283-285.

Search-WmiClass.ps1 (NOTE: this is the name of the online sample program; Search-WmiNamespace.ps1, which
does not exist in online examples, is the name of this file in the book.) p. 258-261

Anonymous   
i
foreward section p2.1 last para - code sample (http://safari.oreilly.com/9780596528492/foreword)

$objShell = New-Object?com Shell.Application

should be

$objShell = New-Object ?comobject Shell.Application

Anonymous  Jul 22, 2008 
Printed Page back cover
bottom right

"Free online edition" ... "Details on last page."
The last page with type talks about registering the book. I registered the book and then realized that the online edition is just a 45 day trial of Safari. If you want to keep it, you have to pay $22.99 / mo. I got the book at my local B&N. I see online that I could have bought print + PDF for just $5 more. I would have paid $5 more to add the PDF, but it appears to be $39.95 if I buy it from you without buying the book from you.
PS Other than that, I am very highly impressed with PowerShell and this book about it.

Anonymous  Aug 21, 2009 
10.4.3
10.4.3 Discussion

In section 10.4.3 the two MultiplyInput... functions are given the same name. The first is named correctly, but the second should be name MultiplyInputComplex.

Richard Reynolds  Sep 15, 2009 
Printed Page 36
Near bottom of page.

The last line of the script does not work.

Here's what will work:

Set-StrictMode -Version Latest

$path = (Resolve-Path C:\Windows\Help\mui\*\WindowsPowerShellHelp.chm).Path

& $path

Anonymous  Dec 13, 2011 
Printed Page 37
Example code

In the Sample code:
$helpMatches += "Suggestion: An alias for $($alias.Definition) is $($alias.name)"

Needs a newline character or the suggestion lines all run together.
This can be fixed by adding a newline character.

$helpMatches += "Suggestion: An alias for $($alias.Definition) is $($alias.Name)`n"

Cool example tool to learn with so its worth having around.

Dr. Blaine Hagstrom  May 31, 2009 
Printed Page 40
5th paragraph

The script I downloaded from O'Reilly for recipe 3.11 (Add Custom Methods and Properties to Objects) will not resolve some paths and will fail if the user attempts to get the owner of an empty directory. This code will fix both issues:

function Get-Owner ([string]$dir = (get-location).path) {
$files = Get-ChildItem $dir
if ($files -ne $null){
foreach($file in $files) {
if ($file -ne $null){
$owner = (Get-Acl $file.PSPath).Owner # fixes path issue in original code
$file | Add-Member NoteProperty Owner $owner
$file
}
}
}else{
# get owner of an empty directory
$files = Get-ItemProperty $dir
$owner = (Get-Acl $dir).Owner
$files | Add-Member NoteProperty Owner $owner
$files
}
}

Anonymous  Dec 04, 2008 
Printed Page 59
top of page

"...can let you to omit" should be reworded for clarity.

Anonymous   
Printed Page 120
Working with any root and example 6-1

The whole of this section is about how to find the cube root etc for a number.
The section states that power shell does not support the cube root or similar and goes on to give a complex (but correct) formula. But that formula is not required and powershell can find the cube root or nth root of any number:
PS> #Cube root of 27
PS> [math]::pow(27,1/3)
3

PS> #Tenth root of 1024
PS> [math]::pow(1024,1/10)
2

Jeremy Pack  Dec 13, 2008 
Printed Page 211
Example 12-1

The listing provided is completely different from the version of the Program that is provided on the samples file.

Anonymous   
Printed Page 211
Example 12-1

The listing provided is completely different from the version of the Program that is provided on the samples file.

Anonymous  May 22, 2008 
Printed Page 244
last line

Line reads
Set-Alias gii Get-InvocationInfo

Should read
Set-Alias gii ./Get-InvocationInfo

Anonymous   
Printed Page 270
Discussion

"Example 15.6 illustrates working with a performance counter from a specific category."

Example 15.6 is for COM scripting, not performance counters. I guess the author meant to recipe 15.8.

Anonymous   
Printed Page 323
$filename = (Resolve-Path $file -ErrorAction SilentlyContinue).Path

Example 17-3, get-filehash.ps1, has these lines of code:
$filename = (Resolve-Path $file -ErrorAction SilentlyContinue).Path
...
$inputStream = New-Object IO.StreamReader $filename

In Powershell 2.0, when resolving remote UNC paths, the $filename variable is given a value in this format:
Microsoft.PowerShell.Core\FileSystem::\\server\share

This value can not be passed to the StreamReader constructor.

Instead, the ProviderPath should be used:
$filename = (Resolve-Path $file -ErrorAction SilentlyContinue).ProviderPath
This sets the $filename variable to the expected format:
\\server\share

Jesper Holmberg  Apr 07, 2009 
338
United States

Typo in code, in name of the $option param

## Options to provide in the prompt
[Parameter(Mandatory = $true)]
$Pption,

Could cause confusion as to variable scope.

Kevin Brown  Oct 12, 2011 
Printed Page 399
Recipe 23.16, 3rd paragraph (Discussion)

The discussion says:

To see whether you have removed the user successfully, see Section 23.18, "List a User's Group
Membership."

However the current solution is about ADDing a user to a group, not removing it. Therefore the discussion
should say "to see whether you have added the user successfully, ..."

Anonymous   
Printed Page 467
top and inside code block

The error in the book concerns the use of the continue statement when used with a label. The book has the text "continue :outer" when the correct usage should be "continue outer". The colon is only used when defining the label.

Chuck Heatherly  May 20, 2009