100% found this document useful (4 votes)
575 views55 pages

Download Complete PowerShell Cookbook, 4th Edition Lee Holmes PDF for All Chapters

Lee

Uploaded by

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

Download Complete PowerShell Cookbook, 4th Edition Lee Holmes PDF for All Chapters

Lee

Uploaded by

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

Download the Full Version of textbook for Fast Typing at textbookfull.

com

PowerShell Cookbook, 4th Edition Lee Holmes

https://textbookfull.com/product/powershell-cookbook-4th-
edition-lee-holmes/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

PowerShell Pocket Reference 3rd Edition Lee Holmes

https://textbookfull.com/product/powershell-pocket-reference-3rd-
edition-lee-holmes/

textboxfull.com

Biota Grow 2C gather 2C cook Loucas

https://textbookfull.com/product/biota-grow-2c-gather-2c-cook-loucas/

textboxfull.com

Endless summer cookbook First Edition Katie Lee

https://textbookfull.com/product/endless-summer-cookbook-first-
edition-katie-lee/

textboxfull.com

Australian Sociology A Changing Society 4th Edition David


Holmes

https://textbookfull.com/product/australian-sociology-a-changing-
society-4th-edition-david-holmes/

textboxfull.com
Auf geht s beginning German language and culture 4th
edition Lee Forester

https://textbookfull.com/product/auf-geht-s-beginning-german-language-
and-culture-4th-edition-lee-forester/

textboxfull.com

Windows PowerShell in Action 3rd Edition Bruce Payette

https://textbookfull.com/product/windows-powershell-in-action-3rd-
edition-bruce-payette/

textboxfull.com

PowerShell 7 Workshop 1 / converted Edition Nick Parlow

https://textbookfull.com/product/powershell-7-workshop-1-converted-
edition-nick-parlow/

textboxfull.com

Essential PowerShell for Office 365 Vlad Catrinescu

https://textbookfull.com/product/essential-powershell-for-
office-365-vlad-catrinescu/

textboxfull.com

The Powershell Scripting & Toolmaking Book Don Jones

https://textbookfull.com/product/the-powershell-scripting-toolmaking-
book-don-jones/

textboxfull.com
PowerShell Cookbook
FOURTH EDITION
Your Complete Guide to Scripting the Ubiquitous Object-Based Shell

With Early Release ebooks, you get books in their earliest form—the author’s
raw and unedited content as they write—so you can take advantage of these
technologies long before the official release of these titles.

Lee Holmes
PowerShell Cookbook
by Lee Holmes
Copyright © 2021 O’Reilly Media. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North,
Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales
promotional use. Online editions are also available for most titles
(http://oreilly.com). For more information, contact our
corporate/institutional sales department: 800-998-9938 or
[email protected].
Acquisitions Editor: Suzanne McQuade
Development Editor: Angela Rufino
Production Editor: Kate Galloway
Interior Designer: David Futato
Cover Designer: Karen Montgomery
Illustrator: Kate Dullea
June 2021: Fourth Edition
Revision History for the Early Release
2021-01-21: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781098101602 for
release details.
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc.
PowerShell Cookbookem>, the cover image, and related trade dress
are trademarks of O’Reilly Media, Inc.
The views expressed in this work are those of the author, and do not
represent the publisher’s views. While the publisher and the author
have used good faith efforts to ensure that the information and
instructions contained in this work are accurate, the publisher and
the author disclaim all responsibility for errors or omissions,
including without limitation responsibility for damages resulting from
the use of or reliance on this work. Use of the information and
instructions contained in this work is at your own risk. If any code
samples or other technology this work contains or describes is
subject to open source licenses or the intellectual property rights of
others, it is your responsibility to ensure that your use thereof
complies with such licenses and/or rights.
978-1-098-10154-1
Chapter 1. The PowerShell
Interactive Shell

A NOTE FOR EARLY RELEASE READERS


With Early Release ebooks, you get books in their earliest form—the author’s
raw and unedited content as they write—so you can take advantage of these
technologies long before the official release of these titles.
This will be the 1st chapter of the final book. Please note that the GitHub repo
will be made active later on.
f you have comments about how we might improve the content and/or
examples in this book, or if you notice missing material within this chapter,
please visit https://www.powershellcookbook.com/4th_ed_techreview. You
can also reach out to the author at [email protected].

1.0 Introduction
Above all else, the design of PowerShell places priority on its use as
an efficient and powerful interactive shell. Even its scripting
language plays a critical role in this effort, as it too heavily favors
interactive use.
What surprises most people when they first launch PowerShell is its
similarity to the command prompt that has long existed as part of
Windows. Familiar tools continue to run. Familiar commands
continue to run. Even familiar hotkeys are the same. Supporting this
familiar user interface, though, is a powerful engine that lets you
accomplish once cumbersome administrative and scripting tasks with
ease.
This chapter introduces PowerShell from the perspective of its
interactive shell.
1.1 Install PowerShell Core

Problem
You want to install the most recent version of PowerShell on your
Windows, Mac, or Linux system.

Solution
Visit https://microsoft.com/PowerShell to find the installation
instructions for the operating system and platform you want to
install on. For the most common:

Windows
Install PowerShell from Microsoft through the the Microsoft Store
application in the Start Menu. Then, install Windows Terminal from
Microsoft through the Microsoft Store application in the Start Menu.

Mac
Install PowerShell from Homebrew:

brew install --cask powershell

Linux
Installation instructions vary per Linux distribution, but the most
common distribution among PowerShell Core users is Ubuntu:

# Update the list of packages


sudo apt-get update

# Install pre-requisite packages.


sudo apt-get install -y wget apt-transport-https software-
properties-common

# Download the Microsoft repository GPG keys


wget -q
https://packages.microsoft.com/config/ubuntu/20.04/packages
-microsoft-prod.deb

# Register the Microsoft repository GPG keys


sudo dpkg -i packages-microsoft-prod.deb

# Update the list of packages after we added


packages.microsoft.com
sudo apt-get update

# Install PowerShell
sudo apt-get install -y powershell

Discussion
PowerShell has already led a long and exciting life. For the first
fifteen years of its existence, it was known as “Windows
PowerShell”: a fantastic object-based management shell and
platform that made it easy and fun for administrators, developers,
and power users to get their jobs done.
In its earliest stages, this support came as part of the “Windows
Management Framework”: a standalone download that provided this
much needed functionality on Windows. Windows PowerShell
eventually became part of Windows itself, and has been a core part
of the operating system since Windows 7.
In 2016, PowerShell made a tremendous shift by announcing that it
would ship PowerShell on multiple operating system platforms — and
by the way — open source the entire project at the same time!
Windows PowerShell got a new name with its new future: simply
PowerShell. This major change opened the doors for vastly quicker
innovation, community participation, and availability through
avenues that previously would never have been possible. While the
classic Windows PowerShell is still included in the operating system
by default, it no longer receives updates and should be avoided.
Installing and Running PowerShell on Windows
As mentioned in the Solution, the best way to get PowerShell is to
install it through the Windows Store. This makes it easy to install
and easy to update. Once you’ve installed it, you can find PowerShell
in the Start Menu like you would any other application.

NOTE
If you want to install a system-wide version of PowerShell for
automation and other adminstration tasks, you will likely prefer the MSI-
based installation mechanism. For more information, see
https://microsoft.com/PowerShell.

While you’re installing PowerShell from the Windows Store, now is a


good time to install the Windows Terminal application from the
Windows Store. The traditional console interface (the window that
PowerShell runs inside of) included in Windows has so many tools
and applications depending on its exact quirks that it is nearly
impossible to meaningfully change. It has fallen woefully behind on
what you would expect of a terminal console interface, so the
Windows Terminal application from the Windows Store is the
solution. Like PowerShell — it is open source, a focus of rapid
innovation, and a vast improvement to what ships in Windows by
default.
Figure 1-1. Windows Terminal running PowerShell, Bash, and even Azure Cloud
Shell!

You can run many shells within tabs in Windows Terminal:


PowerShell, Windows PowerShell, cmd.exe, Bash (if you’ve enabled
the Windows Subsystem for Linux), and even a connection to Azure
Cloud Shell. Windows Terminal defaults to PowerShell if you have it
installed.

Customizing PowerShell on Windows Terminal


There are two changes to a default Windows Terminal + PowerShell
installation that really improve the experience: taskbar pinning, and
themes.
Taskbar pinning
When you launch Windows Terminal, right-click on its taskbar icon.
Select “Pin to Taskbar”, and then drag the icon to the far left of the
taskbar. From now on, whenever you press the Windows Key + 1 at
the same time, you will either launch Windows Terminal and
PowerShell (if it’s not already open), or activate it. This is an
incredible way to keep your favorite shell close at hand.
Themes
Windows Powershell has a gorgeous Noble Blue theme. It is easy on
the eyes, quick to identify, and sets it apart from the dozens of other
shells out there. PowerShell Core did not take this color scheme with
it by default, but it is still possible to customize your installation.
From Windows Terminal, press Ctrl+Comma or click the downward
arrow on the right-hand side of the tab strip to open the Settings
dialog of Windows Terminal. The file that contains these settings will
open in your default text editor. Under Profiles, find the item with
Windows.Terminal.PowershellCore as its source, and add
Campbell PowerShell as a colorScheme. The result should
look like this:

{
"guid": ...
"hidden": false,
"name": "PowerShell",
"colorScheme": "Campbell Powershell",
"source": "Windows.Terminal.PowershellCore"
},

Pay attention to quotes, colons, and commas, and you should have
your PowerShell sessions looking noble again in no time!
Installing and Running PowerShell on Mac and Linux
For the most part, installing PowerShell on Mac and Linux follows the
patterns that you are likely already familiar with.
On Mac, the recommended installation method is through the
popular Homebrew package manager. Homebrew is not installed by
default on MacOS, but installation is quite easy. If you haven’t
installed Homebrew yet, you can find instructions at https://brew.sh.
On Linux, the installation methods vary depending on the
distribution you are interested in. For the most part, installation is as
simple as registering the Microsoft repository for your distribution’s
package manager, and then installing PowerShell. The Solution
provides an example specific to Ubuntu 20.04, but you can specific
instructions for your distribution and specific version here:
https://docs.microsoft.com/en-
us/powershell/scripting/install/installing-powershell-core-on-linux.

1.2 Run Programs, Scripts, and Existing Tools

Problem
You rely on a lot of effort invested in your current tools. You have
traditional executables, Perl scripts, VBScript, and of course, a legacy
build system that has organically grown into a tangled mess of batch
files. You want to use PowerShell, but you don’t want to give up
everything you already have.

Solution
To run a program, script, batch file, or other executable command in
the system’s path, enter its filename. For these executable types, the
extension is optional:
Program.exe arguments
ScriptName.ps1 arguments
BatchFile.cmd arguments

To run a command that contains a space in its name, enclose its


filename in single-quotes (') and precede the command with an
ampersand (&), known in PowerShell as the invoke operator:

& 'C:\Program Files\Program\Program.exe' arguments

To run a command in the current directory, place .\ in front of its


filename:

.\Program.exe arguments

To run a command with spaces in its name from the current


directory, precede it with both an ampersand and .\:

& '.\Program With Spaces.exe' arguments

Discussion
In this case, the solution is mainly to use your current tools as you
always have. The only difference is that you run them in the
PowerShell interactive shell rather than cmd.exe.

Specifying the command name


The final three tips in the Solution merit special attention. They are
the features of PowerShell that many new users stumble on when it
comes to running programs. The first is running commands that
contain spaces. In cmd.exe, the way to run a command that
contains spaces is to surround it with quotes:

"C:\Program Files\Program\Program.exe"
In PowerShell, though, placing text inside quotes is part of a feature
that lets you evaluate complex expressions at the prompt, as shown
in Example 1-1.
Example 1-1. Evaluating expressions at the PowerShell prompt
PS > 1 + 1
2
PS > 26 * 1.15
29.9
PS > "Hello" + " World"
Hello World
PS > "Hello World"
Hello World
PS > "C:\Program Files\Program\Program.exe"
C:\Program Files\Program\Program.exe
PS >

So, a program name in quotes is no different from any other string


in quotes. It’s just an expression. As shown previously, the way to
run a command in a string is to precede that string with the invoke
operator (&). If the command you want to run is a batch file that
modifies its environment, see Recipe 3.5.

NOTE
By default, PowerShell’s security policies prevent scripts from running.
Once you begin writing or using scripts, though, you should configure
this policy to something less restrictive. For information on how to
configure your execution policy, see Recipe 18.1.

The second command that new users (and seasoned veterans before
coffee!) sometimes stumble on is running commands from the
current directory. In cmd.exe, the current directory is considered
part of the path: the list of directories that Windows searches to find
the program name you typed. If you are in the C:\Programs
directory, cmd.exe looks in C:\Programs (among other places) for
applications to run.
PowerShell, like most Unix shells, requires that you explicitly state
your desire to run a program from the current directory. To do that,
you use the .\Program.exe syntax, as shown previously. This
prevents malicious users on your system from littering your hard
drive with evil programs that have names similar to (or the same as)
commands you might run while visiting that directory.
To save themselves from having to type the location of commonly
used scripts and programs, many users put commonly used utilities
along with their PowerShell scripts in a “tools” directory, which they
add to their system’s path. If PowerShell can find a script or utility in
your system’s path, you do not need to explicitly specify its location.
If you want PowerShell to automatically look in your current working
directory for scripts, you can add a period (.) to your PATH
environment variable.
For more information about updating your system path, see Recipe
16.2.
If you want to capture the output of a command, you can either
save the results into a variable, or save the results into a file. To
save the results into a variable, see Recipe 3.3. To save the results
into a file, see Recipe 9.2.

Specifying command arguments


To specify arguments to a command, you can again type them just
as you would in other shells. For example, to make a specified file
read-only (two arguments to attrib.exe), simply type:

attrib +R c:\path\to\file.txt

Where many scripters get misled when it comes to command


arguments is how to change them within your scripts. For example,
how do you get the filename from a PowerShell variable? The
answer is to define a variable to hold the argument value, and just
use that in the place you used to write the command argument:
$filename = "c:\path\to\other\file.txt"
attrib +R $filename

You can use the same technique when you call a PowerShell cmdlet,
script, or function:

$filename = "c:\path\to\other\file.txt"
Get-Acl -Path $filename

If you see a solution that uses the Invoke-Expression cmdlet to


compose command arguments, it is almost certainly incorrect. The
Invoke-Expression cmdlet takes the string that you give it and
treats it like a full PowerShell script. As just one example of the
problems this can cause, consider the following: filenames are
allowed to contain the semicolon (;) character, but when Invoke-
Expression sees a semicolon, it assumes that it is a new line of
PowerShell script. For example, try running this:

$filename = "c:\file.txt; Write-Warning 'This could be


bad'"
Invoke-Expression "Get-Acl -Path $filename"

Given that these dynamic arguments often come from user input,
using Invoke-Expression to compose commands can (at best)
cause unpredictable script results. Worse, it could result in damage
to your system or a security vulnerability.
In addition to letting you supply arguments through variables one at
a time, PowerShell also lets you supply several of them at once
through a technique known as splatting. For more information about
splatting, see Recipe 11.14.

See Also
Recipe 3.3
Recipe 3.5
Recipe 11.14
Recipe 16.2
Recipe 18.1

1.3 Run a PowerShell Command

Problem
You want to run a PowerShell command.

Solution
To run a PowerShell command, type its name at the command
prompt. For example:

PS > Get-Process

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id


ProcessName
------- ------ ----- ----- ----- ------ -- ---
--------
133 5 11760 7668 46 1112
audiodg
184 5 33248 508 93 1692
avgamsvr
143 7 31852 984 97 1788
avgemc

Discussion
The Get-Process command is an example of a native PowerShell
command, called a cmdlet. As compared to traditional commands,
cmdlets provide significant benefits to both administrators and
developers:
They share a common and regular command-line syntax.
They support rich pipeline scenarios (using the output of one
command as the input of another).
They produce easily manageable object-based output, rather than
error-prone plain-text output.
Because the Get-Process cmdlet generates rich object-based
output, you can use its output for many process-related tasks.
Every PowerShell command lets you provide input to the command
through its parameters. For more information on providing input to
commands, see Appendix A.
The Get-Process cmdlet is just one of the many that PowerShell
supports. See Recipe 1.12 to learn techniques for finding additional
commands that PowerShell supports.
For more information about working with classes from the .NET
Framework, see Recipe 3.8.

See Also
Recipe 1.12
Recipe 3.8
Appendix A

1.4 Resolve Errors Calling Native Executables

Problem
You have a command line that works from cmd.exe, and want to
resolve errors that occur from running that command in PowerShell.

Solution
Enclose any affected command arguments in single quotes to
prevent them from being interpreted by PowerShell, and replace any
single quotes in the command with two single quotes.

PS > cmd /c echo '!"#$%&''()*+,-./09:;<=>?@AZ[\]^_`az{|}~'


!"#$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~

For complicated commands where this does not work, use the
verbatim argument (--%) syntax.

PS > cmd /c echo 'quotes' "and" $variables @{ etc = $true }


quotes and System.Collections.Hashtable

PS > cmd --% /c echo 'quotes' "and" $variables @{ etc =


$true }
'quotes' "and" $variables @{ etc = $true }

Discussion
One of PowerShell’s primary goals has always been command
consistency. Because of this, cmdlets are very regular in the way
that they accept parameters. Native executables write their own
parameter parsing, so you never know what to expect when working
with them. In addition, PowerShell offers many features that make
you more efficient at the command line: command substitution,
variable expansion, and more. Since many native executables were
written before PowerShell was developed, they may use special
characters that conflict with these features.
As an example, the command given in the Solution uses all the
special characters available on a typical keyboard. Without the
quotes, PowerShell treats some of them as language features, as
shown in Table 1-1.

Table 1-1. Sample of special characters


Special character Meaning

" The beginning (or end) of quoted text


Special character Meaning

# The beginning of a comment

$ The beginning of a variable

& Reserved for future use

( ) Parentheses used for subexpressions

; Statement separator

{ } Script block

| Pipeline separator

` Escape character

When surrounded by single quotes, PowerShell accepts these


characters as written, without the special meaning.
Despite these precautions, you may still sometimes run into a
command that doesn’t seem to work when called from PowerShell.
For the most part, these can be resolved by reviewing what
PowerShell passes to the command and escaping the special
characters.
To see exactly what PowerShell passes to that command, you can
view the output of the trace source called
NativeCommandParameterBinder:

PS > Trace-Command NativeCommandParameterBinder {


cmd /c echo '!"#$%&''()*+,-./09:;<=>?@AZ[\]^_`az{|}~'
} -PsHost

DEBUG: NativeCommandParameterBinder Information: 0 :


WriteLine
Argument 0: /c
DEBUG: NativeCommandParameterBinder Information: 0 :
WriteLine
Argument 1: echo
DEBUG: NativeCommandParameterBinder Information: 0 :
WriteLine
Argument 2: !#$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~
!"#$%&'()*+,-./09:;<=>?@AZ[\]^_`az{|}~

If the command arguments shown in this output don’t match the


arguments you expect, they have special meaning to PowerShell and
should be escaped.
For a complex enough command that “just used to work,” though,
escaping special characters is tiresome. To escape the whole
command invocation, use the verbatim argument marker (--%) to
prevent PowerShell from interpreting any of the remaining
characters on the line. You can place this marker anywhere in the
command’s arguments, letting you benefit from PowerShell
constructs where appropriate. The following example uses a
PowerShell variable for some of the command arguments, but then
uses verbatim arguments for the rest:

PS > $username = "Lee"


PS > cmd /c echo Hello $username with 'quotes' "and"
$variables @{ etc = $true }
Hello Lee with quotes and System.Collections.Hashtable
PS > cmd /c echo Hello $username `
--% with 'quotes' "and" $variables @{ etc = $true }
Hello Lee with 'quotes' "and" $variables @{ etc = $true }

While in this mode, PowerShell also accepts cmd.exe-style


environment variables—as these are frequently used in commands
that “just used to work”:

PS > $env:host = "myhost"


PS > ping %host%
Ping request could not find host %host%. Please check the
name and try again.
PS > ping --% %host%
Pinging myhost [127.0.1.1] with 32 bytes of data:
(...)

See Also
Appendix A

1.5 Supply Default Values for Parameters

Problem
You want to define a default value for a parameter in a PowerShell
command.

Solution
Add an entry to the PSDefaultParameterValues hashtable.

PS > Get-Process

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id


ProcessName
------- ------ ----- ----- ----- ------ -- -
----------
150 13 9692 9612 39 21.43 996
audiodg
1013 84 45572 42716 315 1.67 4596
WWAHost
(...)

PS > $PSDefaultParameterValues["Get-Process:ID"] = $pid


PS > Get-Process

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id


ProcessName
------- ------ ----- ----- ----- ------ -- -
----------
584 62 132776 157940 985 13.15 9104
powershell_ise
PS > Get-Process -Id 0

Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id


ProcessName
------- ------ ----- ----- ----- ------ -- -
----------
0 0 0 20 0 0
Idle

Discussion
In PowerShell, many commands (cmdlets and advanced functions)
have parameters that let you configure their behavior. For a full
description of how to provide input to commands, see Appendix A.
Sometimes, though, supplying values for those parameters at each
invocation becomes awkward or repetitive.
In early versions of PowerShell, it was the responsibility of each
cmdlet author to recognize awkward or repetitive configuration
properties and build support for “preference variables” into the
cmdlet itself. For example, the Send-MailMessage cmdlet looks
for the $PSEmailServer variable if you do not supply a value for
its -SmtpServer parameter.
To make this support more consistent and configurable, PowerShell
supports the PSDefaultParameterValues preference variable.
This preference variable is a hashtable. Like all other PowerShell
hashtables, entries come in two parts: the key and the value.
Keys in the PSDefaultParameterValues hashtable must match
the pattern cmdlet:parameter—that is, a cmdlet name and
parameter name, separated by a colon. Either (or both) may use
wildcards, and spaces between the command name, colon, and
parameter are ignored.
Values for the cmdlet/parameter pairs can be either a simple
parameter value (a string, boolean value, integer, etc.) or a script
block. Simple parameter values are what you will use most often.
If you need the default value to dynamically change based on what
parameter values are provided so far, you can use a script block as
the default. When you do so, PowerShell evaluates the script block
and uses its result as the default value. If your script block doesn’t
return a result, PowerShell doesn’t apply a default value.
When PowerShell invokes your script block, $args[0] contains
information about any parameters bound so far:
BoundDefaultParameters, BoundParameters, and
BoundPositionalParameters. As one example of this, consider
providing default values to the -Credential parameter based on
the computer being connected to. Here is a function that simply
outputs the credential being used:

function RemoteConnector
{
param(
[Parameter()]
$ComputerName,

[Parameter(Mandatory = $true)]
$Credential)

"Connecting as " + $Credential.UserName


}

Now, you can define a credential map:

PS > $credmap = @{}


PS > $credmap["RemoteComputer1"] = Get-Credential
PS > $credmap["RemoteComputer2"] = Get-Credential

Then, create a parameter default for all Credential parameters


that looks at the ComputerName bound parameter:

$PSDefaultParameterValues["*:Credential"] = {
if($args[0].BoundParameters -contains "ComputerName")
{
$cred =
$credmap[$PSBoundParameters["ComputerName"]]
if($cred) { $cred }
}
}

Here is an example of this in use:

PS > RemoteConnector -ComputerName RemoteComputer1


Connecting as UserForRemoteComputer1
PS > RemoteConnector -ComputerName RemoteComputer2
Connecting as UserForRemoteComputer2
PS > RemoteConnector -ComputerName RemoteComputer3

cmdlet RemoteConnector at command pipeline position 1


Supply values for the following parameters:
Credential: (...)

For more information about working with hashtables in PowerShell,


see Appendix A.

See Also
Appendix A

1.6 Invoke a Long-Running or Background


Command

Problem
You want to invoke a long-running command on a local or remote
computer.

Solution
Invoke the command as a Job to have PowerShell run it in the
background:
PS > Start-Job { while($true) { Get-Random; Start-Sleep 5 }
} -Name Sleeper

Id Name State HasMoreData


Location
-- ---- ----- -----------
--------
1 Sleeper Running True
localhost

PS > Receive-Job Sleeper


671032665
1862308704
PS > Stop-Job Sleeper

Or, if your command is a single pipeline, place a & character at the


end of the line to run that pipeline in the background:

PS > dir c:\windows\system32 -recurse &

Id Name PSJobTypeName State


HasMore
Data
-- ---- ------------- ----- ------
-
1 Job1 BackgroundJob Running True

PS > 1+1
2

PS > Receive-Job -id 1 | Select -First 5

Directory: C:\Windows\System32

Mode LastWriteTime Length Name


---- ------------- ------ ----
d---- 12/7/2019 1:50 AM 0409
d---- 11/5/2020 7:09 AM 1028
d---- 11/5/2020 7:09 AM 1029
d---- 11/5/2020 7:09 AM 1031
d---- 11/5/2020 7:09 AM 1033
Discussion
PowerShell’s job cmdlets provide a consistent way to create and
interact with background tasks. In the Solution, we use the Start-
Job cmdlet to launch a background job on the local computer. We
give it the name of Sleeper, but otherwise we don’t customize
much of its execution environment.
In addition to allowing you to customize the job name, the Start-
Job cmdlet also lets you launch the job under alternate user
credentials or as a 32-bit process (if run originally from a 64-bit
process).
As an alternative to the Start-Job cmdlet, you can also use the
Start-ThreadJob cmdlet. The Start-ThreadJob cmdlet is a bit
quicker at starting background jobs and also lets you supply and
interact with live objects in the jobs that you create. However, it
consumes resources of your current PowerShell process and does
not let you run your job under alternate user credentials.
Once you have launched a job, you can use the other Job cmdlets
to interact with it:
Get-Job
Gets all jobs associated with the current session. In addition, the
-Before, -After, -Newest, and -State parameters let you
filter jobs based on their state or completion time.
Wait-Job
Waits for a job until it has output ready to be retrieved.

Receive-Job
Retrieves any output the job has generated since the last call to
Receive-Job.

Stop-Job
Stops a job.
Remove-Job
Removes a job from the list of active jobs.

NOTE
In addition to the Start-Job cmdlet, you can also use the -AsJob
parameter in many cmdlets to have them perform their tasks in the
background. Two of the most useful examples are the Invoke-
Command cmdlet (when operating against remote computers) and the
set of WMI-related cmdlets.

If your job generates an error, the Receive-Job cmdlet will display


it to you when you receive the results, as shown in Example 1-2. If
you want to investigate these errors further, the object returned by
Get-Job exposes them through the Error property.
Example 1-2. Retrieving errors from a Job
PS > Start-Job -Name ErrorJob { Write-Error Error! }

Id Name State HasMoreData


Location
-- ---- ----- ----------- --
------
1 ErrorJob Running True
localhost

PS > Receive-Job ErrorJob


Error!
+ CategoryInfo : NotSpecified: (:) [Write-
Error], WriteError
Exception
+ FullyQualifiedErrorId :
Microsoft.PowerShell.Commands.WriteErrorExc
eption,Microsoft.PowerShell.Commands.WriteErrorCommand
PS > $job = Get-Job ErrorJob
PS > $job | Format-List *

State : Completed
HasMoreData : False
StatusMessage :
Location : localhost
Command : Write-Error Error!
JobStateInfo : Completed
Finished : System.Threading.ManualResetEvent
InstanceId : 801e932c-5580-4c8b-af06-ddd1024840b7
Id : 1
Name : ErrorJob
ChildJobs : {Job2}
Output : {}
Error : {}
Progress : {}
Verbose : {}
Debug : {}
Warning : {}

PS > $job.ChildJobs[0] | Format-List *


State : Completed
StatusMessage :
HasMoreData : False
Location : localhost
Runspace : System.Management.Automation.RemoteRunspace
Command : Write-Error Error!
JobStateInfo : Completed
Finished : System.Threading.ManualResetEvent
InstanceId : 60fa85da-448b-49ff-8116-6eae6c3f5006
Id : 2
Name : Job2
ChildJobs : {}
Output : {}
Error :
{Microsoft.PowerShell.Commands.WriteErrorException,Microso
ft.PowerShell.Commands.WriteErrorCommand}
Progress : {}
Verbose : {}
Debug : {}
Warning : {}

PS > $job.ChildJobs[0].Error
Error!
+ CategoryInfo : NotSpecified: (:) [Write-
Error], WriteError
Exception
+ FullyQualifiedErrorId :
Microsoft.PowerShell.Commands.WriteErrorExc
eption,Microsoft.PowerShell.Commands.WriteErrorCommand

PS >

As this example shows, jobs are sometimes containers for other


jobs, called child jobs. Jobs created through the Start-Job cmdlet
will always be child jobs attached to a generic container. To access
the errors returned by these jobs, you instead access the errors in its
first child job (called child job number zero).
In addition to long-running jobs that execute under control of the
current PowerShell session, you might want to register and control
jobs that run on a schedule, or independently of the current
PowerShell session. PowerShell has a handful of commands to let
you work with scheduled jobs like this; for more information, see
Recipe 27.14.

See Also
Recipe 27.14
Recipe 28.7
Recipe 29.5

1.7 Program: Monitor a Command for Changes


As thrilling as our lives are, some days are reduced to running a
command over and over and over. Did the files finish copying yet? Is
the build finished? Is the site still up?
Usually, the answer to these questions comes from running a
command, looking at its output, and then deciding whether it meets
Another Random Scribd Document
with Unrelated Content
CHAPTER XIV
Biplane Driven by
Compressed-air Engine
The model aeroplane illustrated by Fig. 148 has been designed
to suit the compressed-air plant fully illustrated and described in the
preceding chapter. It is from the results obtained from the testing of
the plant that the dimensions of a suitable model for it are
determined; and while the design may suit the majority of the plants
constructed from the illustrations shown in pp. 95 to 101, it is chiefly
given to show the correct method of designing a “power-driven”
machine, since the power unit (unlike the elastic motor) cannot be
varied, and recourse to some established line of reasoning becomes
essential.
The first thing to do, then, once the plant has been “tuned up,” is
to ascertain the thrust obtainable from it. This is found by suspending
the plant by the valve on a balance, with a container fully inflated, the
weight registered being carefully noted. The container pressure
should now be released, and the weight registered when the motor is
running observed. By subtracting the former from the latter the thrust
is obtained.
Thus, assuming the plant, at rest, to weigh 8 oz., and when
running 12 oz., it is clear that the thrust is equal to 4 oz. Now, it is
necessary to know the average thrust developed, since, as hitherto
explained, the thrust is not constant, but gradually diminishes as the
density of the air in the container approaches normal atmospheric
conditions; that is, 14·6 lb. per square inch (known as an
atmosphere). It is possible to obtain some very interesting data by
plotting a graph of the thrust given off at various moments from the
release of the pressure in the container. Meanwhile it can be taken
as a good rule that the thrust registered after one-third of the
effective run of the motor represents approximately the average
thrust; and the figure given above (4 oz.) will serve for the purpose of
illustration.
It is next necessary to know the weight of the model it will lift. It is
well established that a plant will fly a machine weighing from four to
six times the weight of the thrust it develops, although, of course,
much depends on the efficiency of the model; the greater the
complexity of frame members the lower the lift drag ratio, and
consequently the lower the ratio between the thrust and the weight of
the model. Compromising, and taking 5: 1 as the ratio, 20 oz. is
obtained as the total weight of the plant and model.
The next point to be decided on is the loading, and as the model
is to be a biplane a comparatively light loading can be used. In the
case of the machine shown in side elevation by Fig. 146 and in front
elevation by Fig. 147, 4 oz. has been taken as the loading per
square foot. So that the total area of the wings will be

20
— = 5 sq. ft. = 720 sq. in.
4
A span of 54 in. for the top plane and 46 in. for the bottom one
has been decided on, and by using a chord of 8¾ in. the total area of
the wings vies very approximately with this figure, allowing a small
margin for excess weight. The area of the tail, which is non-lifting,
need not be taken into account. Although the “gap” is given as being
equal to the chord, it could be made, if anything, ½ in. greater.
Now with regard to actual materials. Birch is to be used for the
longitudinals, straight in the grain and of the cross-sections
illustrated. The lower member is bent under steam to the curvature
shown—of 6½-in. radius. Two vertical struts support the wings, and
these should be cut from hickory. A short tie-strut secures the bottom
longitudinal to the front inter-strut, the joint being made by means of
side angle-plates bound into place. It will be found good practice to
make a full-size drawing of the machine in side elevation, so that it
can be used as a template to fit up the cross members—particularly
with regard to the cutting of the angles.
The joint of the longeron to the cross member is shown
separately at A (Fig. 146). The usual fish-plates are employed, so
made that a small wiring plate is left protruding from the binding, to
which the cross-sectional and longitudinal-sectional wires are made
off.

Fig. 148.—Plan View of Biplane Driven by


Compressed Air
The plant itself is slung into the framework by means of eight
wires, each being made off to the wiring plates. Each should also be
provided with a small ¾-in. wire strainer to enable the plant to be
fixed quite rigidly—albeit permitting of its being removed for
inspection or repairs. The wires from the engine itself are taken off
from the four small eyes soldered to the stationary portion of the
crank-shaft. Great care should be taken to ensure that the plane of
rotation of the screw is at right angles to the main planes. A 1¼-in.
dihedral is given to the bottom plane by means of the bracing wires
passing between the inter-struts, and shown on the preceding page.
It has been thought advisable to attach a small rear wheel, to
enable the model to rise off the ground with as little loss of power as
possible. Such a wheel, with attachments, need weigh no more than
¼ oz., and is a great improvement over the cane skid usually
employed.

Fig. 146.—Side Elevation of Biplane Driven by


Compressed Air
In bracing the outriggers, or longerons, some care will be
required to ensure their being quite true. It will be easier to finish
each section off first, so that they are quite parallel at the joints.
The part plan view of the model (Fig. 148) will make the relative
position of the various component parts quite plain. The two top tail
outriggers pass through the fabric at the point where the spar is
located, their front ends being pinned and cross bound to the wing
spar, which is made of greater cross-section in the centre, so that its
strength is not materially impaired through the piercing of it. Birch is
to be used for the wing spars and ribs of the sections indicated.
The planes are ribbed at periods of 6 in. and given a camber of ¾
in., the greatest depth of which is 2¼ in. from the leading edge. It is
far easier to impart the camber after the wing framework is made
than to camber each rib separately. Each rib should be cut 1 in.
longer than necessary, and pinned and glued to the spars, with ½ in.
overlapping each of these latter. When the glue is quite set, the pins
may be clinched over by supporting the wing on an iron weight and
tapping them back flush to the spars.
The full-size section of the camber should be drawn upon a
board, with which to check the accuracy of the first rib to be
cambered (the end rib).
The ribs are cambered in a jet of steam, the convex or top sides
being placed nearest to it. Having cambered the end rib carefully to
agree with the drawing, the others may be matched to it. It will thus
be easy to ensure that every rib is of the correct curvature, as any
mistake in the steaming of the rib will distort the wing spar at the
point of its attachment.
If, however, it is thought advisable to camber the ribs first, a
wooden bending jig should be made, to enable several ribs to be
bent at one operation. The ribs should be tied down to the jig with
string, and thus held under the steam jet, being well dried in front of
the fire before they are detached from the jig. All three spars pass
underneath the ribs.
A very light fabric should be chosen, such as can be obtained
from the model-aero accessory warehouses, or an unproofed
Japanese silk can be used and varnished when on the wing. If this
latter is used, it will be found advantageous to use a yellow hue, as
this colour is least affected by the action of the varnish. But the
covering of the wings must be left for the time being, for the reason
that the sockets to which the inter-struts are made fast must first be
attached. Further, the top plane must be covered after the tail
outriggers have been assembled, as it is so much easier to make the
joint between the wing spars and these latter before the fabric is
attached.
To render it unnecessary to refer to the point further, it may be
noted that the fabric is brought over the leading spar of each wing to
pocket it out. It is much neater to sew the fabric along on the leading
edge, as when glue is used an unsightly black smear shows through.
The fabric should be stretched from end to end first, the fabric
overlaps being glued on the bottom face of each end rib. Drawing-
pins should be partially pressed into the ribs to secure the fabric until
the glue is set.
At B in Fig. 148 is shown the method of securing the bottom
plane to the inter-struts. Convenient notches are cut in the struts into
which the plane is sprung. It will have been noticed from the side
elevation (Fig. 146) that the width of the inter-struts increases
towards the bottom or lower ends, and also that they incline slightly;
this is to provide for the entry of the lower plane, since the top plane
is attached outside the struts, while the bottom is placed inside them.
At C is shown the method of attaching the inter-struts.
The tail is built up from split bamboo, ⅒ in. by ³/₃₂ in. in cross-
section, and the rudders are framed up from No. 20 gauge piano
wire. The ends of the rudder frames are forced through the
longerons, and the ends bent back in alignment with them; they are
then bound to the longerons with black three-cord carpet thread. The
rudders are covered after being fixed to the outriggers. When it is
necessary to adjust them, the piano wire will be found sufficiently
ductile to admit of a warp being placed thereon.

Fig. 147.—Front Elevation of Compressed-air-driven


Model
Eleven ribs connect the spars of the top plane and nine those of
the lower, the camber of each being the same; that is, the same
depth of camber is maintained throughout. Before the wings are
covered, the angle-plates to which the inter-struts are fixed must be
bound on; and these are cut from No. 30 gauge sheet tin. They
should be cut less in width than the spar to which they are attached,
in order that their sharp edges shall not cut through the binding. To
prevent the plates from moving, they should be lightly sunk into the
wing spar with two centre-punch dots, and a film of glue should also
be spread over the face of the plate coming in contact with the spar.
The inter-struts are streamlined in cross-section (see Fig. 149);
but they are to be left rectangular in section at their ends, to provide
a flat surface for the plates to bed home on. The ends of the plates
are turned back over the binding, which may be of the light machine
variety.
The lower ends of the inter-struts are cut off to the same angle as
the dihedral on the lower plane, to avoid distortion of the plane.
Spruce or American whitewood may be used for them, the greatest
cross section being ½ in. by ⅛ in. The greatest cross-section is
situated at the middle of the strut, whence it tapers to ³/₁₆ in. by ⅛ in.
Fig. 149 shows the attachment of the inner strut to the wing spar. In
Fig. 150 are shown the brackets forming the guides for the axle, and
also the supports for the rubber shock-absorbers. Piano wire is used
for them. The width of the guide should be such that the umbrella-
ribbing, which constitutes the inner portion of the axle, rides freely
within it. The wheel axles are cut from No. 16 gauge piano wire, and
they are soldered to the umbrella-ribbing, being sunk into the
channel of the latter, bound with No. 30 gauge tinned iron wire, and
then soldered.
Ordinary elastic, as used for a rubber-driven model, can be used
as the shock-absorber, and it should be neatly and fairly loosely
bound to the vertical guide, the axle of course being first seated
therein. In order that the absorber brackets may maintain a vertical
position, their ends are shaped to a form similar to the letter U. They
are wire-bound to the skids and lightly soldered.
Fig. 149.—Details of Inter-struts.

Fig. 150.—Detail of Axle Guides.


Fig. 151.—Outrigger and Wing-spar Joint.

Fig. 152.—Tail Crossbar Joint.


Fig. 153.—Detail of Front Skid Angle-plates.

Fig. 154.—Tail Incidence-quadrant.


Fig. 155.—Details of Axle.

Fig. 156.—Rear Chassis Details.

Fig. 157.—Inter-strut and Longeron Joint.


The bottom plane only must be covered; it will be easier to cover
the top plane when the machine is assembled, for it would be a
difficult matter to secure the top outriggers to the spars were the
fabric attached.
Having assembled the outriggers and completed the bracing of it,
it will be possible to attach it to the wings.
Small elliptical holes are cut in the fabric of the lower wing,
through which the central supports or stanchions pass, and the
bottom plane is seated home in the notches alluded to in Fig. 148.
Next, the top outrigger ends are fitted up, being cut off to correct
length and halved on to the wing spars, as shown in Fig. 151. The
vertical support is then glued, pinned, and cross-bound to the
outrigger.
Great care will be necessary to ensure that the outriggers are
quite central with the planes. A point to be made clear is that if in the
fitting of the top outriggers one is cut even ¹/₃₂ in. short, the tail end
of the machine may be ¾ in. out of centre. In order to check
inaccuracy in this direction it would be advisable to mark the centre
of the horizontal tail member, insert a drawing-pin, and take the
measurement to the corner of the wing tip, on both sides of the
model; the outriggers should be temporarily lashed to the wing
spars, and gradually adjusted until they are located centrally with the
planes. Perhaps it may be interesting to here mention that this is the
method employed in locating the fuselage of full-size machines.
The bracing of the planes should now be undertaken. All lift wires
should first be fixed, beginning from the wing tips. Just sufficient
tension should be placed on each wire to ensure rigidity. A wooden
straightedge should be used to reveal any distortion of the spar. The
top plane must be given a slight dihedral, so that when the anti-lift
wires are inserted it assumes a perfectly parallel position.
Fig. 158.—Biplane Driven by Compressed Air
The upper and lower longerons are spanned at the tail end with
light spruce cross-bars, ⅛-in. by ¼-in. section, which are let into
mortises cut in the longerons; and two vertical posts are halved on to
these cross members (see Fig. 152), to provide the fulcrum about
which the tail swings in the quadrant, to be referred to presently.
They are spaced 4 in. apart, which is equivalent to the distance
between two ribs; and on the outside of them a groove is cut in the
centre of each to provide a seating for the two central tail ribs. These
grooves must be cut V-shaped, the apex of the V facing the trailing
edge of the post. The object of the groove is to form a guide for the
tail when it is desired to alter the angle of it. A pin should be driven
through the rib and into the groove to constitute the pivot on which
the tail swings; and the ribs must be bound with fine thread on each
side of the pin to prevent the rib from splitting. It will be found that it
is better to bind the ribs before inserting the pin.
The central inter-struts are attached to the skids by angle-plates,
and in Fig. 153 the form of these is given. It must be understood that
there are two plates to each joint, one on each side of it, and for
neatness and simplicity they can be cut from one piece of tin, both
plates being thus formed in the one. No. 30 gauge tinplate is
suitable. The plates are pinned, clinched, and bound into place, and
constitute an exceedingly rigid piece of construction, which is
needed in this portion of the machine, bearing as it does the impact
of landing. Glue should be neatly brushed into all the joints. The tie-
strut is to be streamlined as far as practicable without materially
impairing the strength of it.
A very neat finish can be given to the binding if it is just brushed
round with japan black, which shows up in pleasing contrast to the
light brown varnish with which the framework is coated.
Fig. 154 gives the shape of the quadrant, which makes possible
the variation to the angle on the tail. It is cut to a radius of 4 in., and
is pinned into position. The pitch of the teeth is ⅛ in., and this
facilitates a very fine adjustment. It should be so fixed that the tail
springs tightly into notches, but not so tightly as to render adjustment
difficult. Trial and error will be found the best method of locating its
position.
Fig. 159.—Compressed-air-driven Monoplane
It was mentioned in the preceding chapter (see pp. 94 to 103)
that the axle is composed of two portions, umbrella-ribbing and piano
wire, and Fig. 155 shows the construction. It will be seen that the
piano wire beds into the channel (which is fixed in a trailing position),
wherein it is bound and soldered. The wheels are spaced apart by
means of small brass-tube collars, soldered to the piano-wire axles
in their respective positions. The axle itself, as mentioned earlier in
the chapter, is attached between the shock-absorber brackets, being
held there by means of suitable radius wires secured to any
convenient part, the rubber binding forming the absorber. The radius
wires are essential in order to maintain the lateral position of the axle
relatively to the planes. Sufficient rubber binding is to be used to
absorb the shocks the model is bound to receive, the exact quantity,
of course, being impossible to define.
The rear wheel members are fixed to the longerons in the
following manner. The ends are bent back parallel to align with the
frame member. The apices of the V chassis members are soldered
to the short axle carrying the back wheel, the axle being cut a length
suitable to the hub of the wheel. No. 20 gauge wire is used for all
portions of the rear chassis. Fig. 156 makes this clear.
Fig. 157 shows the joint of the trailing central inter-struts to the
top longeron. It will be seen that the joint is a halved one, pinning
and binding forming the security.
All woodwork may be polished by filling the grain with gold size,
and finishing with a good varnish.
In flying the model the writer would point out that full pressure
should not be given to the plant until adjustment has been
completed, also the importance of tuning the machine by starting it
from the ground, thus obviating many vexing smashes. Further, the
rudder must be set to counteract torque; if the screw is of left-hand
pitch, then torque will tend to bank the machine to the right, and the
rudder must therefore be set to the left, and vice versa.
A sketch of the finished machine is given by Fig. 158, and a
design for a monoplane driven by the same plant in Fig. 159.
CHAPTER XV
General Notes on Model Designing
Calculations in Designing a Plant for a Model Aeroplane.—
The correct method to adopt in designing a model is to build the
machine exclusive of the motor, weigh it, and design the plant to suit;
or to build the plant first, determine the thrust it develops, and vary
the dimensions of the machine (and hence the weight) to suit.
It can now be taken as a general rule that a plant will fly a
machine three times the weight of its thrust. Hence a plant
developing 3-oz. thrust would fly a machine weighing 9 oz. or 10 oz.
But, since the thrust of a compressed-air engine is not constant,
gradually diminishing as the pressure in the container grows less, for
a machine weighing 9 oz. (assuming the machine to be built first) the
plant will require to develop about 5 oz. initial thrust. The diameter of
the propeller is dependent on the most efficient speed of the
particular motor employed.
Assuming that the model does not weigh more than 17 oz., a
four-cylinder engine constructed would answer admirably. It would
require a container 24 in. long and 3 in. in diameter, constructed of
copper or hard-drawn brass foil ·002 in. thick. Should, however, the
reader particularly desire to fit a rotary motor, doubtless the five-
cylinder rotary previously described will suit.
Building Scale Models.—The great difficulty in building scale
models to fly with rubber motors is to get the centre of gravity in the
same relative position that it holds in the prototype. This is due to the
long length of rubber motor required to give the requisite power, and
also to ensure a reasonable time-length of flight.
It is in connection with the fixing or arranging of the rubber motor
that the most radical departures in the design of the prototype will
have to be made, although the writer has evolved an arrangement
whereby even this need not entail much departure from the lines of
the original. This arrangement consists in providing a separate strut
or frame to take up all strain from the rubber, it only being necessary
to arrange suitable fastenings for the strut, which may take the form
of clips, so making it possible either to remove the motor for the
purpose of changing or repairing the rubber, or substituting a motor
of different power or length. This is a great advantage on tractor
monoplanes (with the main plane in front), where the rubber is more
or less inaccessible by reason of the closed-in frame or fuselage of
the machine. Another important advantage to be gained from the use
of a detachable motor is that its position fore and aft on the machine
can be varied, in order to bring the centre of gravity into the proper
position to obtain correct balance, or, speaking with more technical
accuracy, to make the centres of pressure and gravity coincide.
With regard to the type of motor to adopt, this depends very
largely on the machine which is being modelled. Whenever possible
it should be of the simplest possible kind, consisting of the main strut
to take the tensile strain, compressive, of course, so far as it affects
the strut, and the torsional strain put on by the twisting of the rubber.
At one end of this strut a hook of wire or other form of metal is
formed to hold the rubber skein, whilst at the other end is fixed a
plain bearing. Through this the propeller spindle is passed, having a
hook at its end, over which the other end of the rubber is placed.
On certain types such a simple motor is not possible. In order to
concentrate the weight more at one point, the rubber and its struts
have to be shortened; and to get the necessary number of
revolutions of the propeller a gearing of two to one, three to one, or
four to one, as the case may be, must be used. By this means the
small number of turns which can be got on a short thick skein of
rubber of great power will still give the number of propeller
revolutions required to make a good flight, just the same as with a
motor of ordinary thickness and of great length. Of course, some
power is lost in the gearing.
To resist fuselage distortion the spar must be suitably braced in a
lateral direction, the outrigger carrying the bracing wires being
situated just forward of the centre of the spar. No. 35 s.w.g. is quite
strong enough for fuselage bracing. Silk fishing-line or Japanese silk
gut is admirably suited for wing bracing, and is not so liable to stretch
as the tinned iron or brass wire sometimes used. Piano wire is
generally used for elevators, tail planes, chassis, and propeller
shafts, of a gauge ranging from No. 17 s.w.g. to No. 22 s.w.g. A
clock-spring or piano-wire protector fitted to the nose of a model
aeroplane will also prevent a broken spar should it strike some
object such as a tree or wall during flight.
The Kite and Model Aeroplane Association, which is the
paramount body to observe and control model flying in England, and
which is recognised by the Royal Aero Club, stipulate that protectors
must be fitted to all machines competing in their contests.
CHAPTER XVI
General Notes
Stability.—The principles underlying the design of a successful
flying model aeroplane are almost, if not quite, as complex as those
involved in the planning of full-size machines. In some respects
perhaps this is more so, owing to the fact that models must be
practically automatically stable both longitudinally and laterally, since
they are not under any sort of control after they have left the hands
of the person flying them. The adjustments to produce this automatic
stability must be made before the machine is launched, and the fact
that there are models which are capable of flying distances of
several hundreds of yards, and high up in the air, is evidence that it
is quite possible to make this adjustment accurately.
A useful rule to remember is that to produce a longitudinally
stable effect, the leading plane should make a greater angle (that is,
a positive angle) than the following plane. And that conversely a
condition of instability is set up when the leading plane makes a
negative angle to the trailing one (see Fig. 160).
Referring now to lateral stability, the same principle applies,
although in the case of biplanes stability to a great extent can be
obtained in another way.
Monoplanes and sometimes biplanes are made stable by what is
known as a dihedral angle shown by Fig. 161, which represents the
usual method of shaping the planes. This last-mentioned figure is
intended to represent a front (or back) view of the machine. In
aeroplanes of this type the elevator or tail, whichever is employed,
may also be given a dihedral, though this is not often done.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like