100% found this document useful (6 votes)
49 views

Full Download Building Better PowerShell Code: Applying Proven Practices One Tip at A Time Adam Bertram PDF

One

Uploaded by

brixisultan
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 (6 votes)
49 views

Full Download Building Better PowerShell Code: Applying Proven Practices One Tip at A Time Adam Bertram PDF

One

Uploaded by

brixisultan
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/ 62

Download the full version of the textbook now at textbookfull.

com

Building Better PowerShell Code: Applying


Proven Practices One Tip at a Time Adam
Bertram

https://textbookfull.com/product/building-better-
powershell-code-applying-proven-practices-one-tip-
at-a-time-adam-bertram/

Explore and download more textbook at https://textbookfull.com


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

Fierce conversations achieving success at work in life one


coversation at a time Scott

https://textbookfull.com/product/fierce-conversations-achieving-
success-at-work-in-life-one-coversation-at-a-time-scott/

textbookfull.com

One wild bird at a time portraits of individual lives


Heinrich

https://textbookfull.com/product/one-wild-bird-at-a-time-portraits-of-
individual-lives-heinrich/

textbookfull.com

Going Horizontal Creating a Non Hierarchical Organization


One Practice at a Time Samantha Slade

https://textbookfull.com/product/going-horizontal-creating-a-non-
hierarchical-organization-one-practice-at-a-time-samantha-slade/

textbookfull.com

Practical Mobile Forensics A hands on guide to mastering


mobile forensics for the iOS Android and the Windows Phone
platforms 3rd Edition Rohit Tamma
https://textbookfull.com/product/practical-mobile-forensics-a-hands-
on-guide-to-mastering-mobile-forensics-for-the-ios-android-and-the-
windows-phone-platforms-3rd-edition-rohit-tamma/
textbookfull.com
Nanomechanics of Graphene and Design of Graphene
Composites Xiaoyi Liu

https://textbookfull.com/product/nanomechanics-of-graphene-and-design-
of-graphene-composites-xiaoyi-liu/

textbookfull.com

Essential Clinical Anesthesia Review Keywords Questions


and Answers for the Boards 1st Edition Linda S. Aglio

https://textbookfull.com/product/essential-clinical-anesthesia-review-
keywords-questions-and-answers-for-the-boards-1st-edition-linda-s-
aglio/
textbookfull.com

British National Formulary BNF 68 68th Edition


Pharmaceutical Press

https://textbookfull.com/product/british-national-formulary-
bnf-68-68th-edition-pharmaceutical-press/

textbookfull.com

Patterns of World History Peter Von Sivers

https://textbookfull.com/product/patterns-of-world-history-peter-von-
sivers/

textbookfull.com

Best Practices for Administering Online Programs 1st


Edition Daniel Hillman

https://textbookfull.com/product/best-practices-for-administering-
online-programs-1st-edition-daniel-hillman/

textbookfull.com
Data simplification taming information with open source
tools First Edition (Online-Ausg.) Berman

https://textbookfull.com/product/data-simplification-taming-
information-with-open-source-tools-first-edition-online-ausg-berman/

textbookfull.com
Building Better
PowerShell Code
Applying Proven Practices One Tip
at a Time

Adam Bertram
Building Better
PowerShell Code
Applying Proven Practices
One Tip at a Time

Adam Bertram
Building Better PowerShell Code: Applying Proven Practices One Tip
at a Time
Adam Bertram
Evansville, IN, USA

ISBN-13 (pbk): 978-1-4842-6387-7 ISBN-13 (electronic): 978-1-4842-6388-4


https://doi.org/10.1007/978-1-4842-6388-4

Copyright © 2020 by Adam Bertram


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of
the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations,
recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or
information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar
methodology now known or hereafter developed.
Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol
with every occurrence of a trademarked name, logo, or image we use the names, logos, and images
only in an editorial fashion and to the benefit of the trademark owner, with no intention of
infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms, even if they
are not identified as such, is not to be taken as an expression of opinion as to whether or not they are
subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the date of
publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for
any errors or omissions that may be made. The publisher makes no warranty, express or implied, with
respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Smriti Srivastava
Development Editor: Matthew Moodie
Coordinating Editor: Shrikant Vishwakarma
Cover designed by eStudioCalamar
Cover image designed by Pexels
Distributed to the book trade worldwide by Springer Science+Business Media LLC, 1 New York
Plaza, Suite 4600, New York, NY 10004. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail
[email protected], or visit www.springeronline.com. Apress Media, LLC is a California LLC
and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc).
SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail [email protected]; for reprint,
paperback, or audio rights, please e-mail [email protected].
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions
and licenses are also available for most titles. For more information, reference our Print and eBook
Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available
to readers on GitHub via the book’s product page, located at www.apress.com/978-1-4842-6387-7.
For more detailed information, please visit http://www.apress.com/source-code.
Printed on acid-free paper
This book is dedicated to all of the tech professionals
out there that have been intrigued by PowerShell and
have taken the time to dig in, learn, and better
themselves with knowledge.
Table of Contents
About the Author���������������������������������������������������������������������������������xi
About the Technical Reviewer�����������������������������������������������������������xiii
Acknowledgments������������������������������������������������������������������������������xv
Introduction��������������������������������������������������������������������������������������xvii

Chapter 1: Do the Basics����������������������������������������������������������������������1


Plan Before You Code��������������������������������������������������������������������������������������������1
Don’t Reinvent the Wheel��������������������������������������������������������������������������������������2
Build Functions As Building Blocks�����������������������������������������������������������������������2
Build Reusable Tools���������������������������������������������������������������������������������������������3
Don’t Focus Purely on Performance����������������������������������������������������������������������3
Build Pester Tests��������������������������������������������������������������������������������������������������4
Implement Error Handling�������������������������������������������������������������������������������������4
Build Manageable Code����������������������������������������������������������������������������������������5
Don’t Skimp on Security���������������������������������������������������������������������������������������5
Log Script Activity�������������������������������������������������������������������������������������������������6
Parameterize Everything���������������������������������������������������������������������������������������6
Limit Script and Function Input�����������������������������������������������������������������������������7
Maintain Coding Standards�����������������������������������������������������������������������������������7
Code in Context�����������������������������������������������������������������������������������������������������8
Return Informational Output���������������������������������������������������������������������������������8
Understand Your Code�������������������������������������������������������������������������������������������9

v
Table of Contents

Use Version Control�����������������������������������������������������������������������������������������������9


Write for Cross-Platform�������������������������������������������������������������������������������������10
Write for the Next Person������������������������������������������������������������������������������������10
Use Visual Studio Code���������������������������������������������������������������������������������������11

Chapter 2: Don’t Reinvent the Wheel��������������������������������������������������13


Use Community Modules������������������������������������������������������������������������������������13
Leverage Others’ Work����������������������������������������������������������������������������������������14

Chapter 3: Use Visual Studio Code�����������������������������������������������������17


Install the PowerShell Extension�������������������������������������������������������������������������19
Integrate VS Code with Git����������������������������������������������������������������������������������19

Chapter 4: Plan Before You Code��������������������������������������������������������21


Write Comments Before Coding��������������������������������������������������������������������������21
Use Your Code As a Todo List������������������������������������������������������������������������������23

Chapter 5: Create Building Blocks with Functions�����������������������������25


Write Functions with One, Single Goal����������������������������������������������������������������25
Build Functions with Pipeline Support����������������������������������������������������������������27
Save Commonly Used, Interactive Functions to Your User Profile�����������������������30

Chapter 6: Parameterize Everything���������������������������������������������������33


Don’t Hardcode. Always Use Parameters������������������������������������������������������������33
Use Parameter Sets When All Parameters Should Not Be Used at Once������������36
Use a PSCredential Object Rather Than a Separate Username and
Password������������������������������������������������������������������������������������������������������������40

Chapter 7: Log Script Activity�������������������������������������������������������������43


Use a Logging Function���������������������������������������������������������������������������������������43
Clean Up Verbose Messages�������������������������������������������������������������������������������46

vi
Table of Contents

Chapter 8: Build with Manageability in Mind������������������������������������49


DRY: Don’t Repeat Yourself���������������������������������������������������������������������������������49
Don’t Store Configuration Items in Code�������������������������������������������������������������51
Always Remove Dead Code��������������������������������������������������������������������������������53

Chapter 9: Be Specific������������������������������������������������������������������������55


Explicitly Type All Parameters�����������������������������������������������������������������������������55
Always Use Parameter Validation When Possible�����������������������������������������������57
Always Define a Function’s OutputType��������������������������������������������������������������59
Write Specific Regular Expressions��������������������������������������������������������������������61

Chapter 10: Write for the Next Person�����������������������������������������������63


Give Your Variables Meaningful Names���������������������������������������������������������������63
String Substitution����������������������������������������������������������������������������������������������65
Keep Aliases to the Console Only, Not in Scripts�������������������������������������������������66
Put Functions in Alphabetical Order in a Module������������������������������������������������67
Explain Regular Expressions with Comments�����������������������������������������������������68
Write Comment-Based Help��������������������������������������������������������������������������������69
Weigh the Difference Between Performance and Readability����������������������������71

Chapter 11: Handle Errors Gracefully�������������������������������������������������73


Force Hard-Terminating Errors���������������������������������������������������������������������������73
Avoid Using $?����������������������������������������������������������������������������������������������������76

Chapter 12: Don’t Skimp on Security�������������������������������������������������79


Sign Scripts���������������������������������������������������������������������������������������������������������79
Use Scriptblock Logging�������������������������������������������������������������������������������������81
Never Store Sensitive Information in Clear Text in Code�������������������������������������82
Don’t Use Invoke-Expression������������������������������������������������������������������������������84
Use PowerShell Constrained Language Mode����������������������������������������������������86

vii
Table of Contents

Chapter 13: Stick to PowerShell���������������������������������������������������������87


Use Native PowerShell Where Possible��������������������������������������������������������������87
Use Approved, Standard Function Names�����������������������������������������������������������89

Chapter 14: Build Tools�����������������������������������������������������������������������91


Think Ahead and Build Abstraction “Layers”������������������������������������������������������91
Wrap Command-Line Utilities in Functions���������������������������������������������������������97
Make Module Functions Return Common Object Types��������������������������������������98
Ensure Module Functions Cover All the Verbs���������������������������������������������������100

Chapter 15: Return Standardized, Informational Output������������������101


Use Progress Bars Wisely���������������������������������������������������������������������������������101
Leave the Format Cmdlets to the Console��������������������������������������������������������103
Use Write-Verbose��������������������������������������������������������������������������������������������105
Use Write-Information���������������������������������������������������������������������������������������107
Ensure a Command Returns One Type of Object�����������������������������������������������108
Only Return Necessary Information to the Pipeline������������������������������������������110

Chapter 16: Build Scripts for Speed�������������������������������������������������113


Don’t Use Write-Host in Bulk�������������������������������������������������������������������������113
Don’t Use the Pipeline���������������������������������������������������������������������������������������114
Use the foreach Statement in PowerShell Core���������������������������������������������115
Use Parallel Processing������������������������������������������������������������������������������������117
Use the .NET StreamReader Class When Reading Large Text Files������������������119

Chapter 17: Use Version Control�������������������������������������������������������121


Create Repositories Based on a Purpose����������������������������������������������������������121
Commit Code Changes Based on Small Goals��������������������������������������������������122
Create a Branch Based on a Feature����������������������������������������������������������������122
Use a Distributed Version Control Service��������������������������������������������������������123

viii
Table of Contents

Chapter 18: Build and Run Tests�������������������������������������������������������125


Learn the Pester Basics������������������������������������������������������������������������������������125
Leverage Infrastructure Tests���������������������������������������������������������������������������126
Automate Pester Tests��������������������������������������������������������������������������������������127
Use PSScriptAnalyzer����������������������������������������������������������������������������������������128

Chapter 19: Miscellaneous Tips��������������������������������������������������������131


Write for Cross-Platform�����������������������������������������������������������������������������������131
Don’t Query the Win32_Product CIM Class�������������������������������������������������������133
Create a Shortcut to Run PowerShell As Administrator������������������������������������134
Store “Formattable” Strings for Later Use��������������������������������������������������������136
Use Out-GridView for GUI-Based Sorting and Filtering�������������������������������������137
Don’t Make Automation Scripts Interactive�������������������������������������������������������139

Chapter 20: Summary�����������������������������������������������������������������������141

Index�������������������������������������������������������������������������������������������������143

ix
About the Author
Adam Bertram is a 22-year veteran of IT and
experienced online business professional.
He’s an entrepreneur, Microsoft MVP, blogger
at adamtheautomator.com, trainer, and writer
for multiple technology companies. Catch up
on Adam’s articles at adamtheautomator.com,
connect on linkedin.com/in/AdamBertram/,
or follow him on twitter.com/adbertram.

xi
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
About the Technical Reviewer
Vikas Sukhija has over 16 years of IT
infrastructure experience. He is certified/
worked on various Microsoft and related
technologies.
He has been awarded five times with
Microsoft Most Valuable Professional title
(thrice in Cloud and Datacenter management
(PowerShell) and twice in the Office 365
category).
With his experience on messaging and collaboration technologies, he
has assisted clients in migrating from one messaging platform to another.
He has utilized PowerShell for automation of various monotonous tasks
as well as created self-service solutions for users.
He has been recognized many times by clients for automations that
resulted in direct/indirect cost avoidance.
He is playing key roles with various large clients in the implementation
and adoption of Office 365.
He is the owner and author of the http://TechWizard.cloud,
http://SysCloudPro.comblog site.
He is also the owner and author of the https://www.facebook.com/
TechWizard.cloud Facebook page.

xiii
Acknowledgments
This book, along with all of my other career projects, could not have been
possible without my wife, Miranda. She’s the rock of our household and
has allowed me to pursue projects regardless of how crazy they have been
and has supported me for nearly 20 years now.
I also want to acknowledge all of those that have reached out and let
me know how much my work means to you. It may mean a lot to you,
but trust me, it means more to me to hear stories of how I’ve helped
throughout your career.

xv
Introduction
This book was created out of necessity. There are many books out there
on how to learn PowerShell. You’ll also find thousands of articles and blog
posts on PowerShell best practices. But there wasn’t an entire collection of
PowerShell learning and best practices brought together before.
Each chapter in this book is broken down by chapter with multiple
“tips” inside. Each chapter is a bucket for the kinds of tips you can expect
to read about. Each tip is a best practice. Tips are short, actionable steps
you can take today to help you improve your PowerShell scripts.
Tips do not go into major detail. There are other resources out there for
that. The tips in this book are not meant to be exhaustive how-tos but to
rather act as a checklist for actions to take. With each tip, you will typically
find an example to solidify your understanding of the tip.
All tips within this book should be treated as universal across all
PowerShell versions and platforms from Windows PowerShell 5.1 and later
including all PowerShell Core versions. If you see an example using code,
assume that it will work in your PowerShell version of choice. All examples
were written to be as generic as possible.
All tips in this book were written by me, but many were contributed
by the PowerShell community. If a tip did come from the community, the
community member will be referenced.

Who Is This Book For?


This book is for anyone wanting to learn how to write better PowerShell code.
The book’s examples are primarily targeted to the IT professional, although
anyone writing PowerShell for any purpose can get a lot from this book.

xvii
Introduction

This book is not meant to be “training,” per se. It’s not specifically
targeted at any level of PowerShell expertise. You will find tips in this book
ranging from the basic level all the way up to the advanced level. It’s up to
you to skip those tips that don’t apply to you and soak up the ones that do.
Read over this book periodically throughout your career. You’ll find
that each tip will vary based on specific contexts, use cases, and expertise
levels. Once you find yourself at that level, you’ll be able to understand and
get more out of those tips.

B
 ook Resources
You will find all code referenced in this book in the (a) GitHub repository
called PowerShellTipsToWriteBy.

xviii
CHAPTER 1

Do the Basics
When it comes to code, there are a lot of opinions out there about
“best practices.” What one developer thinks is a must, another will refute
it. But these disagreements typically happen around specific, nuanced
situations like tabs vs. spaces and if a curly brace should go on a new line.
There are larger categories of tips and best practices that are universal.
Everyone can agree on broad tips like “write tests,” “make code reusable,”
and “don’t store passwords in clear text.”
In this chapter, we’re going to hit those broad strokes. We’re going to
cover the basic truths that almost everyone can agree on.
In the later chapters, we’ll dive deeper into each of these areas to
provide more specific tips the community and I have come up with.
Without further ado, let’s get to the tips!

Plan Before You Code


Don’t automatically jump into coding. Instead, take a little bit of time to do
a “back of the napkin” plan on what your code will do. Scaffold out code in
comments briefly outlining what the code will do in those spots.
Write pseudocode. The practice of writing pseudocode will take your
brain through the mental steps of what you need to do.

F urther Learning
• How to Write a Pseudocode?

© Adam Bertram 2020 1


A. Bertram, Building Better PowerShell Code,
https://doi.org/10.1007/978-1-4842-6388-4_1
Chapter 1 Do the Basics

Don’t Reinvent the Wheel


Leverage the hard work of others. Don’t completely write a new solution if
one already exists. Issue pull requests to existing open source projects if an
existing PowerShell module doesn’t quite fit your needs. Don’t fork it and
build your own.
Look to the PowerShell Gallery first before embarking on a new script.
Someone may have already solved that problem.

F urther Learning
• Get Started with the PowerShell Gallery

Build Functions As Building Blocks


As you begin to build more complex PowerShell code, begin to think in
functions, not lines of code. As you write code, consider if what you’re
writing could stand on its own. Consider what the default commands in
PowerShell do already. Get-Content reads a text file. Test-Connection
checks the status of a network connection. Copy-Item copies a file.
If a script does more than one “thing,” consider breaking it up into one
or more functions. If you begin to collect a library of functions, create a
module.

F urther Learning
• Building Advanced PowerShell Functions and Modules

2
Chapter 1 Do the Basics

Build Reusable Tools


Similar to the “Build Functions As Building Blocks” tip, build PowerShell
tools, not code. Focus on building reusable scripts, functions, or modules
that you can reuse consistently. You should strive to build a library of tools
that can be called from other code.
Instead of rewriting code over and over again, you should naturally begin
to write code that calls tools. Eventually, you’ll find the majority of your code
will be making calls to your tools rather than re-creating the wheel.

F urther Learning
• Learn PowerShell Toolmaking in a Month of Lunches

Don’t Focus Purely on Performance


Jeffrey Snover, the father of PowerShell, once said that (paraphrasing)
PowerShell was meant for humans, not computers. It was built not
for blazing performance but to be human readable. It was built to be
approachable for non-developers, the IT admins that need to automate
tasks but can’t and would rather not develop software applications.
If you’re trying to eke out every last bit of speed from a PowerShell
script for no reason other than to satisfy your own OCD tendencies, you’re
doing it wrong.

F urther Learning
• Writing PowerShell Code for Performance

3
Chapter 1 Do the Basics

Build Pester Tests


If you build scripts that make their way into production, always include
Pester tests with it. Pester tests:
• Ensure that your code (at all angles) “works”

• Allow you to make changes and confirm new bugs


weren’t introduced

• Help you trust your code instead of being afraid you’re


going to break it by introducing changes

Build Pester unit tests to test your code. Build Pester integration/
acceptance/infrastructure tests to confirm the code you wrote changed
what you expected.

F urther Learning
• The Pester Book

Implement Error Handling


Never let your code throw an exception you didn’t account for. Use
$ErrorActionPreference = 'Stop' religiously to ensure all errors are
hard-terminating errors. Wrap all code in try/catch blocks and handle
thrown exceptions. Don’t leave any possibility for your code to exit without
you already expecting it.

F urther Learning
• The Big Book of PowerShell Error Handling

4
Chapter 1 Do the Basics

Build Manageable Code


Build code for the future. Build PowerShell code that won’t leave you
wondering WTF this thing does a year from now. Ensure your code can
be managed in the long term. Practice the DRY (don’t repeat yourself )
principle. Write code once and refer to it rather than copying/pasting.
The fewer place code duplication exists, the simpler the code and the
easier that code is to manage.

F urther Learning
• Clean Code: A Handbook of Agile Software
Craftsmanship

Don’t Skimp on Security


Many PowerShell developers disregard security implications. It’s not
because they don’t care (well, some don’t), it’s because they don’t know
any better. Infosec professionals and IT have always been separate
wheelhouses. You may not need to know the ins and outs of vulnerability
assessments, root kits, ransomware, encryption, or Ttrojans. But you do
need to practice common security sense.
Don’t put plaintext passwords in your scripts. Sign your scripts. Don’t
set your execution policy to unrestricted. We’ll cover these and more in the
security chapter.

F urther Learning
• PowerShell Security at Enterprise Customers

5
Chapter 1 Do the Basics

Log Script Activity


Record script activity across your organization. PowerShell is a powerful
scripting language. PowerShell can automate tasks in no time, but it
doesn’t discriminate between test and production. It can also be run by
nefarious individuals.
Log script activity. Log it to a text file, a database, or some other
data source; just record and audit the activity somehow. Logging is like
backups. You might not need them now, but when you do, you’ll be glad
you did.

F urther Learning
• Greater Visibility Through PowerShell Logging

P
 arameterize Everything
This tip is related to the functions and tools tip. When building scripts and
functions, add as many parameters as necessary. Always add a parameter
that might one day hold a different value. Never add “static” values to your
scripts. If you need to define a value in code, create a parameter and assign
it a default value. Don’t assign that value in the code.
Creating parameters allows you to pass different values to your
functions or scripts at runtime instead of changing the code.

F urther Learning
• The PowerShell Parameter Demystified

6
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Chapter 1 Do the Basics

Limit Script and Function Input


When you open up your scripts to input, limit what can be input as tightly
as possible. Be sure to account for as many different ways as possible
values may be passed into your code at runtime.
Validate as much input as possible with parameter validation
attributes, conditional checks, and so on. Try to never allow a value or type
of input into your code you didn’t expect.

F urther Learning
• The PowerShell Parameter Demystified

Maintain Coding Standards


Come up with a standard and stick to that for everything. Don’t name
variables $Var1 in one script and $var1 (note the case) in another. Don’t
include a bracket on the same line in one script and the bracket on a new
line in the next.
Maintain a consistent coding methodology for everything. If your code
is consistent, others (and you) will be able to understand your code much
better.

F urther Learning
• How to Use the PowerShell Script Analyzer to Clean Up
Your Code

7
Chapter 1 Do the Basics

C
 ode in Context
Write a solution specific to context in which it will run. Don’t write a script
that expects 10 parameters and give it to your help desk staff. Write a GUI
instead. Don’t quickly bang out a script without much thought if it’s going
to be used in production.
Worry about performance if the action your script is taking is time
sensitive. How you code always depends on the context in which it will
run. Don’t assume the code you write and test on your workstation is going
to run fine in another environment. Code in the context that the script will
run in.

F urther Learning
• Clean Code: A Handbook of Agile Software
Craftsmanship

Return Informational Output


Even though you can return anything you want to the output stream, do
it wisely. Define what’s verbose, informational, and error output and only
show that output in the various streams. Don’t show unnecessary object
properties. Instead, use PowerShell formatting rules to hide properties
from being seen by default.

F urther Learning
• PowerShell Format Output View

8
Chapter 1 Do the Basics

Understand Your Code


If you don’t know what a line of code does, remove it or write a Pester test.
Understand what each command or function you call is capable of at all
times. Don’t simply run a command under a single situation and expect it
to run the same way every time.
Test as many scenarios as possible to understand what your code is
capable of until various circumstances.

F urther Learning
• 10 Steps to Plan Better so You Can Write Less Code

Use Version Control


File names like myscript.ps1.bak and myscript.ps1.bak2 shouldn’t exist.
Instead, use tools like Git and GitHub to put your scripts under version
control. Version control allows you to audit and roll back changes to your
code if necessary.
Version control becomes even more important in a team environment.
If you’re serious at all about PowerShell scripting, you must use version
control.
Tip Source: https://twitter.com/Dus10

F urther Learning
• Git Basics for IT Pros: Using Git with Your PowerShell
Scripts

9
Chapter 1 Do the Basics

W
 rite for Cross-Platform
PowerShell isn’t just on Windows anymore. PowerShell Core is cross-­platform
and so should be your scripts. If you ever see a time when your scripts need to
run on other operating systems, account and test for that now.
If you’re sharing scripts via the PowerShell Gallery or some other
community repository, cross-platform is especially important. Don’t let
others find out the hard way your script only runs on Windows.

F urther Learning
• Tips for Writing Cross-Platform PowerShell Code

Write for the Next Person


Be sure other people understand your code. Write your code (and
comments) in a clear, concise manner. A layperson should be able to look
at your code and understand what it’s doing.
Don’t get fancy just because you can. Don’t use aliases. Instead, write
understandable code, include detailed help content, and comment code
heavily. Ensure the next person can easily digest your code. You never
know. That next person might be you!

F urther Learning
• Getting Fancy with Code Just Makes You Look Stupid

10
Chapter 1 Do the Basics

Use Visual Studio Code


You can’t get away with a text editor anymore. Your code is too important
to sloppily throw together and hope that it runs in a terminal. Using an
integrated development environment (IDE) is a must if you want your
code to be taken seriously. Use Visual Studio Code with the PowerShell
extension. You’ll get all the benefits of a full ISE, linting functionality,
autocompletion, and more.

F urther Learning
• PowerShell Tip: Use a Code Editor

11
Random documents with unrelated
content Scribd suggests to you:
“I don’t believe any reality on earth could equal the descriptions
we have had of Niagara. It would need heaven and hell almost to
body forth the ideas that travelers have called up. I can only hope to
be able, if ever I see it, to forget all that I have ever heard about it,
so as to shrink before its magnificence as I should feel bound to do.”
“Suppose we try, Claire?” said I.
“With all my heart,” answered she, evidently glad in her restless
state to be going somewhere. I had previously told her that Herbert
had gone to Quebec.
In a week’s time Claire and myself, with a man-servant, had
reached Albany, and there took the canal-boats to Buffalo. The
wearisome journey by stage-coach had admirably prepared us for
the monotonous ease of the boat. Fortunately there were very few
passengers, and we lay in our little clean white berths and rested
and read as quietly as if we had been in our own rooms.
On reaching the Falls we were too thoroughly wearied to attempt
more that night, and went to our beds.
On our way, a fellow passenger, experienced in sight-seeing, had
recommended to us to take our first view from the American side,
and from below, instead of the usual view from Table Rock. We
therefore crossed the river a little distance below the Falls, without
giving way to the temptation of gazing for a moment at the view
before us, though the roar was terrible in our ears. Then we walked
on the American side, closer, closer till we were within twenty feet of
the cataract. The spray dripped over us, the rocks were slippery to
our feet, the roar of a thousand floods seemed in our bewildered
ears; and below, as it were, the reverberating yells of damned spirits
tossing, and whirling, and dashing and howling forever. Then we
looked up. The volume of water seemed coming down from the very
heavens upon us. We uttered a faint cry of terror—turned round and
fled. That is to say, we fled several yards. No matter. We were
impressed sufficiently with the physical grandeur of the scene. It
was oppressive, overwhelming. Afterward, when we roamed over all
these rocks and took views from every point, and gazed at the
cataract’s wondrous beauty as well as power, we found a moral
grandeur with which our souls sympathized, and to which they rose
to enjoy and adore. These jottings down of our impressions can give
no idea to one who has not visited the Falls, and to one who has,
will scarcely enhance his recollections. I mention them only to
illustrate a trait of Claire’s character.
A mother with her child were wandering along among the loose
stones and sharp rocks close to the terrible whirlpool from which we
had just turned. The mother had let go the child’s hand, and he, a
lad of some four or five years old, slipped from the stone on which
he stood, and as a natural consequence was in imminent danger of
his life. But one rock, and that slippery and sloping, intervened
between the little fellow and certain death. The mother screamed,
but was motionless from mere horror; Claire, who at once forgot
every thing about her but what was connected with the living drama
before her, pulled at a stroke her scarf from her neck, and giving me
one end to hold, while she held the other, slid her feet rapidly down
to the very brink of the torrent, caught the boy firmly by his foot and
stood holding him. She was as pale as death, but as firm and strong
in her attitude as if she stood on the parlor floor. She dared not
move, and I had not strength, and was too distrustful of the
strength of the scarf, to dare to pull them up.
As we stood thus it seemed hours, though it could scarcely be
half a minute before relief was obtained by a rope thrown by a
strong arm from behind over the form of Claire, which fully
supported her in her perilous position. Immediately after she was
clasped in the arms of a man in a cloak, whom we had seen sitting
near us in an absorbed attitude, seemingly regardless of all about
him. He had sprung from his seat, caught up a boat-rope, which I
perfectly remembered afterward to have stepped over, thrown it
around Claire, so as to support her, and then giving the noose to my
servant, who stood close but inactively behind, steadied himself by
the other end of the rope, slipped and sprang down by Claire,
caught up the boy with one hand and tossed him up to his mother,
and then bore the now fainting Claire carefully up to the bank.
The boy screamed wildly with fright, and the mother was voluble
with her thanks and offers of assistance. Claire remained still and
motionless in the arms of the stranger, and I watched the spray dash
over her marble face. Presently her eyes opened slowly, with a deep
sigh. She looked at her preserver and a beautiful color overspread
her face. Then for the first time I also looked at him, for to this
moment no one had spoken but the woman whose carelessness had
put in jeopardy three lives.
He had bent his head down to hers and had kissed her forehead,
rosy with returned consciousness. She replied by pulling her arm
over his neck and kissing, not his forehead, but his very lips. The
woman and her boy had gone, the servant discreetly retired, and
there in the sound and rush of many waters, in the turmoil of
elemental war, the still, small voice of two loving hearts, lately so
near to death, was heard and registered.
“But you wrote me, Herbert, that you were setting off for Quebec
last week. Who could have dreamed of finding you here?”
“And so I did go to Quebec. But I used it up in two days, and
then came on here once more. In my then state of mind it was a
relief to place myself where you found me, and listen to the roar of
the water from morning till night. Now, I don’t care how soon we go
away.”
We did journey, however, for some weeks; and when we returned
and were once more in our own quiet parlor at home, I asked
Herbert to come with me to my room.
“I am going to read you something, Herbert. Something about
Claire.”
Then I opened the packet which Father Angelo had given me.
First there was the official announcement, or rather a copy of it, of
Father Angelo’s admission to the Convent of la Trappe, in Piedmont,
and his consequent death to the world and every body in it. Then a
separate packet contained such particulars of his life as he deemed
necessary for me to know, and to communicate to Claire, if I
thought proper, or to whomsoever she should hereafter marry. There
were also papers conveying a small amount of property to her.
Enough for her subsistence should she be deprived by misfortune of
my support.
The man had been sinned against and was also a great sinner.
He had sinned against the young English girl, Clara, whom he had
seduced from her home under the false pretence of marriage, and
whose fidelity to him and trust in him had continued to her gentle
death. Afterward to win for himself the means of keeping up his
dissipated habits he had recourse to forgery, and had escaped in
disguise, and narrowly, with his life. After that he went to Rome; by
a run of luck in gambling he obtained the means of making a
handsome appearance in society there, and by his cultivation, taste
and fine manners, so impressed an Italian family of some distinction
that he married one of the daughters. The marriage was an unhappy
one. His wife eloped with his friend, and the old drama of a duel was
acted over. Finally his resources were exhausted, and either reason
or conscience suggested to him the claim which a wife and child had
on his memory. At all events, he became an altered man, took holy
orders, obtained permission to travel, and did travel in search of his
long-forgotten wife and child. After a long search he found Claire. He
sought her society. He became her confessor and her friend. He
learned her pure heart, and her enthusiastic devotion to the memory
of her parents. Then the iron entered into his soul. He felt the
impossibility of presenting himself to such an innocent being as the
realization of such an ideal as hers. He now dreaded any chance by
which his relationship could become known to her, as much as he
had heretofore eagerly sought her. All he could do for her he did, but
he constantly watched an opportunity to secure to her an efficient
friend, who could take her into the world, and withdrawing her from
the dull and confined life she then had, put her into the way of
forming connections for herself which would in some degree lead
her to forget or cease to look for her father. The agony of being
forced to deny himself every parental caress, lest he should be
forced to explain his relationship, and consequently the reasons for
his long and unpardonable estrangement, made him wish a
thousand times he were dead indeed, and he said he longed every
hour for the time to arrive when he should take the vow of eternal
silence, for such only harmonized with the gloom of his soul.
It would be wearisome to go through all the details of such a life,
of such talents abused, of such a mournful old age.
We talked the matter over freely and fully, and Herbert concluded
with me that it was best to burn the package, that under no possible
combination of circumstances could it fall into her hands. It should
be his happiness he said to make her forget to look for her father.
How he found out how much she could bless him—and when she
discovered that though he was full of faults, she loved him, faults
and all, I cannot tell; but every body’s experience will furnish similar
instances for themselves or others.
APPEARANCES.
———
BY J. HUNT, JR.
———

It is not by an outward show


To judge where sorrows first begin
An old, thatched cot, for aught we know,
May have a “banquet hall” within.

How true this rule will oft apply,


To some who fill life’s lowly part;
Their very looks may Pain descry,
And Joy be seated in their heart.
HOW CHARLEY BELL BECAME SENATOR.
The whole matter is this.
The tea-things had just been cleared away, the baby just got fast
asleep and laid in his crib, my wife just got fixed by the round-table
making a blue velvet cap for him, and I had just got comfortably
settled in my arm-chair on the other side of the table, when Tom
returned from the post-office through the rain and mud and dark
bringing one letter. My wife gave a pish! when I told her it was not
from her mother, but apologized immediately for her expression
when I informed her that the letter—broad, thick and with a vast
deal of ink in the superscription—was from Charley. Giving the wick
of the lard-lamp another turn she begged me to read it aloud.
Tearing off the envelope—drawing my chair a little nearer the fire
and clearing my throat I read—

Rev. W.——
“My dear W.—Elected! Apart from all nonsense and
affectation I am heartily glad of it! of course I received the
congratulations of every body here quietly, as if it was all a
matter of course that I should be elected Senator, but with
you I have no reserve. Know then, my very dear W., that I
am glad I am elected. For three reasons. First, because I
am elected while just barely of the requisite age: Second,
because I am elected by an overwhelming majority—20 to
1: Third, because it places me out in a free and higher field
of usefulness and energy. Why I feel as if I had just begun
my life. I have not attained the end—only the beginning of
my ambition. I don’t think that it ought to be branded as
ambition—this feeling of mine either. I don’t think it is
ambition. It is a purer feeling—A wish, an eagerness, a
nature to be doing, influencing, bettering as wide a sphere
as I possibly can. I was elected without any art on my part
whatever. I told the people exactly what I was, and what I
intended to try to do if they elected me. I intend to be just
exactly what I am! If I were to try to appear other than
exactly that I would look as well as feel mean—my arm
would falter in every gesture, my tongue stammer, my
knees shake—I would become weak—weak physically,
mentally, utterly! A pure-minded, single-intentioned, whole-
souled manner in thought, word and deed has borne me
thus far like a straight arrow from a true bow. It is the
shortest, best way to cleave the future, I know.
“There is a fourth reason why I do rejoice in my
election. It is because I know that you will rejoice in it. It is
you my friend who have made me high-thoughted and far-
thoughted. It is you who during the last twenty years have
been my good genius—in your conversation when present
with me—in your correspondence when absent from——”

I read the rest of the letter to my wife, but it is entirely too


flattering to me to be coolly written out here. Indeed I remarked all
along, through the three more pages which followed, to my wife,
that his encomiums were only the warm expressions of a warm soul
unusually excited, and which must be taken with all allowance.
Charley’s letter flushed me through and through. That my old
friend should be elected Senator to congress from his State I hoped
but hardly expected. Intimate companionship with a friend, you
know, has a tendency to dwindle him in our eyes. Don’t
misunderstand! Intimacy with such a man as Charles Bell makes one
love and prize him more and more—but does not make one think
more and more that such a man is suited to be a grave and reserved
Senator. It is just as it is with the Swiss peasant whose cabin is on a
side of Mont Blanc—the hoary old mountain does not appear a tithe
so sublime to him as it does to some traveler in the distance.
I say I felt thoroughly warmed and rejoiced. I arose, put all my
wife’s spools and scraps off the table into her lap, laid my portfolio
and ink-stand upon it, begged my wife to absorb herself in her
baby’s velvet cap, dipped my pen in the ink and now have written
thus far.
All my past intercourse with Charley rushes to my lips now, as
tears do sometimes to one’s eyes. I want to tell just as briefly and
distinctly as possible how he has risen from nothing to what he now
is. I know much better than he—and if he reads this, it will do him
good. Any-how, I feel in the mood of writing, and before I go to bed,
if my baby don’t wake with the colic and my wife don’t interrupt me
I will tell you exactly how Charley Bell became a United States
Senator.
The fact is, too, that I have a half-hope that some youth may
read this and may get a word which may wake him to a higher and
nobler life than he has ever yet dreamed of. If the eye of any such a
one rests on these pages, just one word my fine fellow. Forget for a
little while that everlasting Julia whom you fell in love with last
Tuesday a week ago, and read with all your soul of souls.
I cannot exactly say when I did not know Charley. He is some
three years older than myself—he being about eighteen, and I about
fifteen years of age when our friendship began to be a thing to be
remembered. He looked when I saw him a year ago exactly as he
did when we used first to chat cosily beside his fire-side, about
Bulwer and Dora Anson. He is of a medium size, handsome, earnest
face, forehead broad rather than high. There is a peculiar
gentleman-look about him, wherever he is or whatever he is doing.
He has such an enthusiastic sympathy with every man, woman and
child he meets with that he is popular of course.
His peculiarity, however, always consisted in a hunger after
personal excellence. From our first acquaintance we made a distinct
arrangement to tell each other of our faults as plainly as words could
convey meaning. If he did not faithfully do his part toward me in this
arrangement I am very, very much mistaken. He thought aloud
about me—told me exactly what I was, and what I was not. I did the
same in regard to him. We have acted thus for many years now. We
have been of vast benefit to each other—and will continue to be till
we die.
I do verily believe that this arrangement had a good deal to do in
making him the man he is.
Just in this way.
When we first became intimate, and had made our arrangement
as above, I opened the war by talking to him as follows:
“Charley, my fine fellow, you are ambitious to be a good speaker.
Now—you remember our little arrangement about correcting the
faults of each other?”
“Yes.”
“Well, the plain fact is you have got a most miserable, squeaking
voice. Your chest is narrow, you stoop, you don’t have that broad,
strong, manly appearance which is almost essential to a speaker.”
I saw he winced under this. He felt eloquence deeply—he
thought eloquently—and forgot that the thought must be expressed
eloquently, or it is eloquence only to himself.
That afternoon he made a pair of dumb-bells—and I do verily
believe that he has hardly missed a day from that to this in which he
has not exercised his chest and his voice in every possible way. No
one would ever think now that he was not always the broad-
chested, powerful-voiced orator he is.
It strikes me that even this little event had something to do with
Charley in his becoming a Senator. You never saw a narrow-chested
man who had any voice, energy or eloquence in your life. If you
have got a stoop, my boy, you had better correct it if you ever intend
being any thing.
I received from him one day a very, very plain exposition of one
of my many faults. Never mind what it is. He pointed it out to me as
you would point out a rattlesnake in a thicket to any companion you
chanced to be walking with. I saw it—this vile fault of mine—and
have been hunting it, and striking savagely at it, whenever I detect it
stealing through my conduct with its accursed insidiousness ever
since. Alas! it is “only skotched not killed” yet. But that is another
matter. I only mention it to say that his very plain remarks gave an
edge to my remarks, as I observed—
“You are right, Charley, perfectly so—and I war against that
accursed fault forever. But it reminds me of one of yours.”
“Eh?”
“Charley, you have a vile, offensive, disgusting habit of chewing
tobacco. It is loathsome. If you would only keep the weed in your
mouth, why it would only poison yourself—but you will be
everlastingly spitting out its juice—and it poisons me—poisons me
through sight, smell, hearing and feeling. Don’t use it any more.”
True to his own true nature, he never took another quid.
Whether this is one cause of his blooming health and firm nerve I
will not say. I will say that it is one cause of his astonishing
popularity with the ladies—whether they know that it is or not—and
thus one cause of this election of his as Senator.
These faults of ours! I said they are like snakes. So they are.
Sometimes a man catches sight of one of them lying full-length in its
loathsomeness in his own conduct or conversation. Suppose the
fault is self-conceit?—a disease of mentioning one’s self at all times,
which you have contracted. Well, you see the same fault in some
fool or other, or some Charley Bell tells you of it. The knowledge falls
like a flash of daylight on the vice—you see it! If it would only perish
—crawl out of you, it would be well. But the vile thing—crawls into
you—like a snake into its hole. It does not show its head while you
are watching for it. A day or two passes. You forget about it—and it
is out—drawing its filthy trail through all your conduct again.
This is not a digression. Because I wanted to say that Charley
was a man of too strong a desire after personal excellence not to
wage eternal war after such vermin. A shrewd observer would have
known the existence of his besetting faults only by the unusual
prominence of just the opposite virtues, just as you recognize the
former drunkard in the man who has a special horror now of all that
can intoxicate.
There were several minor defects in Charley’s character, which I
pointed out to him, but which he has so completely conquered that I
have forgotten what they were.
I really must say something about that Dora Anson affair.
Dora was the brunette daughter of an established lawyer in our
inland village. I see her as distinctly before me while I write, as if
she was before me. She was some sixteen years of age—had the
usual amount of education and mind—was unaffected—warm-
hearted—black haired and eyed—rosy-lipped—woman-rounded form.
Charley fell in love—astonishingly in love with her. I was amazed. He
was of an intellectual, though impulsive nature; and she had no
conversational power—nothing in the world but a lively, natural,
voluptuous sort of beauty, to recommend her to him.
Astonishingly in love. He made love to her by flowers, and was
accepted in the same way, before he went to college. He was absent
a year. The very night of his return he went to a party at her
father’s, which happened that night. He got a seat near her toward
the close of the evening—in a low voice made a passionate appeal to
her, although surrounded by company—went home—wrote her a still
more passionate letter. He was too impulsive—frightened her—had
his letter returned, and came to me, and as we sat on a log in the
moonlight, told me the whole. He was about twenty years old then,
and the affection had quickened, expanded, strengthened his heart
even more than that chest-exercise had his lungs. There was a
depth, and breadth, and force about his affection for Dora which
stirred up his whole being. It rolled through him like a sea,
deepening and washing out the sands of his heart till that heart
became deep and broad. For months that love lived and worked in
him; at last it died out like the steam from the engine of a
steamship.
When I see his hearty affection for his friends—his warm
sympathy for all among whom he mingles, which gives him his
wonderful popularity, I can trace it all back to that development of
his heart under the hot summer of that love of his for Dora Anson. I
do believe that the genial smile, the cordial manner, the melting
persuasiveness of his tones, all owe their development, if not their
origin, to that culture of his heart. The sun may have set which
shone on his soul, but it left that soul all ruddy and ripe from its
warm rays. If Dora had jilted him, it would have left him a soured
man. If she had married him, it would have left him a satiated man.
In either case it would have injured him. But she did not jilt him—did
not marry him; he outgrew so sensuous a love as that, and
somehow or other they drifted apart.
I believe, however—and my wife, to whom I have just mentioned
it, agrees with me—that his connection with Mr. Nelson had very
much to do in making him the man he is.
You see, when Charley had finished his law-studies, his father
and mother were dead. He never had any brothers or sisters. One or
two thousand dollars was his fortune. Being a young man—now
some twenty-five—of fine appearance, and talents, and manners, he
attracted the attention of Mr. Nelson, a keen and rich lawyer in the
village, and in a few weeks he was settled in his office as a junior
partner. For some six months Nelson seemed wonderfully attached
to Charley—continually spoke of him with the loudest praise—over-
rated him, in fact. At the close of this period, however, he suddenly
took just as violent a set against Bell as he had before for him.
Nobody ever knew the reason of this. I don’t think Nelson himself
did. The truth is, the elder partner was a singular man. He always
dressed neatly in black—was rather thin, with a stooping shoulder, a
retreating forehead, a quick way of talking, and a rapid step. He was
excessively hospitable and generous, more for the sake of being a
sort of protector and superior of the guest than any thing else. Self-
will was the trait of his character.
But I am writing about Charley, and have got no time to paint
this Nelson. Enough to say that he took as vehement a dislike to Bell
as he before had a liking. He ridiculed and opposed and thwarted
him with an astonishing bitterness. Bell, at first, was staggered with
astonishment—then cut to the very soul with such unkindness from
the last man on earth from whom he expected it. But it did him
great good. It corrected his blind confidence in every man
completely, and gave him a quiet watchfulness of men in all his
dealings with them, which was of immense benefit to him. It
destroyed in an instant all his false and colored ideas of things. The
faults of his character which Nelson pointed out and ridiculed, and
made the ostensible cause of his alienation, were forever corrected—
just as a wart is burnt off by corrosive sublimate. Nelson’s
extravagant depreciation of him after such extravagant praise of
him, gave him, in one word, an impulse to prove himself unworthy
that depreciation and more than worthy the former praise, which did
more for him than if his senior partner had given him years of the
most careful instruction and countenance. Besides, it threw him
suddenly on himself—made an independent man of him forever. Just
what that chest-exercise did for his lungs, that Dora affair did for his
heart, this Nelson matter did for his will—it deepened and broadened
and strengthened it to an unusual degree—it did very much toward
making him a Senator.
My wife agrees with me that the little love affair of his with Marie
McCorcle had not much if any effect on our friend. Failing a little in
love with her when he was some twenty-six years old, for a remark
she made in a speech when May Queen, he proposed in a note—was
rejected in a note. Mounting his horse, he took a ride of some
eleven days on business somewhere. On his return he was over with
it, except of course the feeling of pique. The first day of his ride he
chanted, as he told me, the words of her rejection to “Old Hundred,”
all day long, over and over and over. The next day it was to a faster
tune. He trotted his horse rapidly back, making his hoofs keep time
to the swiftest jig of his recollection, as he rode into town with the
words of her rejection still on his lips.
The rest of my task is a pleasant one. I like to think about Annie
Rennaugh—I love even to write her name. She was a cousin of
Dora’s and resided in the same town. I cannot say that she was
pretty—but I can say that she was beautiful. Just in this way. She
was of a small, modest, quiet appearance. You would hardly look at
her twice if you saw her in a promiscuous company. Only become
acquainted with her, however, and an irresistible charm is upon you.
There is such a delicious ease in all she says and does—such a deep
mirth and artless confidence in her that conquers without
observation.
She was a special friend of Charley’s. He confided to her from the
very first all his affair with Dora. I saw him one evening at a party
with her. She was seated in a chair by the door, with a saucer of
strawberries and cream in her lap. He was seated at her feet in the
doorway—enjoying the summer air—conversing in a low, earnest
tone with her as they took alternate teaspoonsful of the fruit. They
were talking about Dora—Charley’s ideal Dora—as earnestly as if
they were talking love on their own account.
Well, the full moon of Dora’s influence waxed into the full orb of
its influence upon her lover, and then waned, and waned. His
friendship, however, for Annie increased slowly—slowly, but most
surely. When he was whirled away for those four weeks by Marie
McCorcle, he told her all about it, and had, as usual, all her
sympathy. Then he was off for college and corresponded with her
regularly. I was with him in college. Many a time has he torn up—at
my advice—the long letter he had written her, because it was
entirely too warm, even though it was directed in the most fraternal
manner possible to “My dear Sister Annie,” and signed, “Your
affectionate brother, Charles.”
You can see immediately how it all ended. A friendship begun in
mere indifference had ripened through six years into deep, genuine
affection. He never dreamed that he loved Annie until he found that
she was essential to his existence. For the first time he knew what
true love was. He found that it was not the sensual flush of passion,
such as warmed him under the hot beauty of Dora—that it was not
the fever of the imagination which diseased him under the moonlight
of Marie. He found that love was not a passion but a feeling; was
not a fit but a condition; was not a hot flush of blood, but the quick,
even, everlasting flow of the heart’s tide, giving health and life to the
whole man.
I am writing nothing but actual fact, and so I cannot say how he
told Annie his love and how she accepted him. He has talked to me
—I do believe in all it amounts to several hundred hours—about
Dora and Marie. He has quoted to me at least one dozen dozen
times every word that ever passed between him and them, but he
never told me any thing about his love conversation with Annie.
They are married. They seem perfectly happy in the quiet possession
of each other and of the blue-eyed baby boy that laughs in their
arms.
This was the making of Charles Bell. A remark of mine has led to
the development of his noble form, and the establishment of that full
health so essential to successful labor. His love for Dora has
expanded his heart and warmed and flushed him all through and
through with an affection and persuasion and love, that shows itself
in his every tone and smile and clasp of the hand and word. His
affair with Marie has cultivated his imagination perhaps. His painful
experience with Mr. Nelson has corrected all false ideas of men—has
given him caution, self-possession, self-reliance and energy. He has
learned to meet things as they come; to do his utmost, and then,
not only not murmur at whatever happens but actually to acquiesce,
to rejoice in every event. Annie is an infinite blessing to him. He is
full of impulse, and she, by a silent, irresistable influence, controls
and directs it. He is full of noble aspiration but inclined to be fickle—
she is ever pouring oil on the fire of his soul as with an unseen angel
hand—is silent and uncongenial when he wanders from his better
self—and thus draws him quietly but irresistibly back.
Of course there were many circumstances in politics and situation
which conspired to elevate him to his present position. I have only
alluded to the quiet under-current of his private life. I wrote what I
have written only because I felt like doing so. I do not think either
he or Annie will be offended at my freedom should they read this—
especially as I have not mentioned his State or his real name. I am
heartily sick of all romance and romantic ideas and descriptions of
men and women, but I do look upon the “Hon. Charles Bell and his
amiable lady,” as the Washington papers will call them, as two of the
finest persons in all my knowledge. Both are most sincere Christians,
and singular as it may seem to some, I regard their companionship
and mutual influence as one which is to last not only through this
poor world, but through all eternity. I would like exceedingly to write
out my ideas on this point, but I cannot do it now. Besides, the
editor may be married to a second wife, and in that case, would
most certainly refuse admission to this little sketch in the pages of
his magazine.
FUNERAL OF ALLSTON.
———
BY ELIHU SPENCER.
———

Speaking of Allston, I was told in Boston that his funeral


was by torch-light, after nine in the evening, and one of the
most impressive and befitting ceremonies ever witnessed.
New York Correspondent Nat. Intelligencer.

Not in the glare of day—


Not to the common eye:
But lay that dreamless brow away
When night is on the sky—
When darkness drops her noiseless pall,
And torches light the funeral.

Not in the glare of day—


Not in the pomp of wo:
Let nature veil the sanctity
Of tears, that none may know
Whose hushed but earnest griefs belie
The clamors of hypocrisy.

Not in the glare of day—


Not by the reeking mart:
He loved the lone and twilight way,
The night-fall of the heart—
When, passion, pride and sense subdued,
The spirit wrought in solitude.
Not in the glare of day—
Not to the common eye:
And though ye lay that brow away
When night is on the sky,
Long years shall yet remember well
The poet-painter’s burial.
A LEAF FROM THE JOURNAL OF FLORENCE
WALTON.
———
BY MISS SUSAN A. STUART.
———

“It was not strange, for in the human breast


Two master-passions cannot co-exist.”

“What a picture of delicious comfort, dear Aunt Mary,” said Cora


Norton, as throwing herself into the luxurious depths of a Voltaire
chair, and placing her pretty little feet on the low fender, she looked
around her Aunt Mary’s snuggery.
A cold, misty rain was falling without; but the ample crimson
curtains were drawn closely, so that no evidence of the inclemency
of the weather was visible within to its two inmates. The cheerful,
crackling fire threw over the chamber and its occupants “fitful
gleams and red,” as drawn closely on the opposite sides of the fire-
place they chatted cosily together.
“Yes, Aunt Mary, you have so much comfort, so much repose,
that I can enter con amore into your feelings, as you thus sit so
tranquilly in your well-lined, little nest, and take a bird’s-eye view of
the bustling, plotting, never-resting world. But, dearest aunty, your
darling little pony has just tired me sufficiently, so as to leave me in
a state of quiescence, in which state one of your pleasant
reminiscences of by-gone days would prove very acceptable. I hope,
my dear aunty, you know how to take a slight hint, for I am awfully
modest about asking favors.” And she crossed her little hands
demurely on her lap, settled herself still more comfortably, and with
an asking smile on her roguish, pretty face nodded her head in a
very patronizing manner at her aunt, saying, “Commencez-donc, s’il
vous plaît, ma bonne.”
“Well! my little chatterbox, is your tongue worn out at last, and
you really wish to play the part of listener! But, what shall I tell you?
Let us see! Florence Walton,” continued the old lady musingly, as she
rubbed her spectacles with her silk apron. “Yes, yes, she is given to
ridicule herself, and might one day suffer from it, as my poor
Florence has done. Here, Co, count the stitches for the heel in this
stocking for me, with your young eyes, and I will try to think over
something about her.”
“You have seen Florence Walton here,” said Mrs. Jordan, as Cora
handed her knitting back to her, “but you must forget her looks, if
you wish to have before your mind’s eye the proud, beautiful girl of
my narrative. A petted and spoiled child was Florence, when she and
I were school-mates. An only child—beautiful, talented, and winning
in her affectionate ways—with parents, who were the happy slaves
to her slightest caprices, how could it be otherwise?”
“I remember, as though but yesterday, when she was ushered in
among us school-girls by Madame Gaspard. As natural, we all sat
silent and restrained before the new-comer, who, unused to school-
discipline, and in all the freedom of her, but just-quitted, home-
circle, was in the habit of giving speech to the first thoughts that
presented themselves to mind, without caring for their fitness, and
too proud to show respect for our opinions, like another school-girl
among utter strangers would have done.
“Yes! I recollect it as freshly as yesterday, and see before me
now the bright, fearless creature, as with an impatient toss of her
glossy ringlets she said half-pettishly—‘Pleasant as my home, indeed!
I wish I was there now, at any-rate, for I feel here as a cat must feel
in a strange garret.’ And a smile parted her saucy lips, as we broke
into hearty laughter at this compliment from the new girl.
“That quaint phrase of Florence Walton’s introduced her at once,
and frolick and fun finished the evening. Many, and many were the
scrapes that her wit and laughter-loving propensity has brought
upon her, but through all her affairs beamed forth the evidence of a
noble, generous, bold, but quick temper, impossible to daunt, but,
like the generality of impulsive temperaments, led child-like and
trusting through the affections. I have seen Florence in after-years,
for we were school-mates a long, long time, throw herself in a
perfect abandonment of tears on her bed, after answering saucily
and with light laughter, some friend whom she dearly prized—and
yet, after remonstrances from me and advice for the future would
reply—‘In vain, dear Mary, all your good advice, and so would be my
promises of amendment, were I foolish enough to make them. I
know, dear friend, my besetting sin—know it, and I assure you, I
most deeply deplore my weakness, which would prevent me from
making good any promise I might make you or myself for the future.
As well ask the bird not to fly, or the fish not to swim, as to make
me promise when irritated, not to use my only weapon—ay! sharper,
I will admit, than a two-edged sword. Mary, it is my misfortune more
than my fault. I have felt—keenly, bitterly felt—how wrong I am in
acting thus. In casting from me by ridicule and foolish jests, friends
whose affection I dearly prize. Oh! you cannot tell how I have
struggled—how in my own heart-communings I have determined to
be more guarded for the future. But the future was ever as the past.
My sin is too strong, and I too weak.’
“Many such conversations have we held together and I, Cora,
was a wicked sinner myself, then, and knew not God, nor the
efficacy of prayer, therefore I could not tell the erring, but warm-
hearted girl, to cast her burthen at the foot of the Cross; and that
from the knowledge of her weakness would come her strength, for
that He, the Mighty One, loved to help the weak ones, who come as
suppliants to his throne. Ah! yes, we were wicked, and only thought
of such things not being respectable, instead of their sinfulness!
“Time sped on, working his changes as he ever does, and our
school-days passed like our girlhood, never to return. Florence and I
made every promise of everlasting friendship when we parted; kept,
too, I believe as faithfully as if made in more mature years. The first
letter I received from her after we had both left for our homes, told
me of the death of her father, which was very sudden. The
newspapers announced shortly after this, the demise of her
remaining parent, and my heart clung still more fondly to her, poor
thing, for she had no brothers or sisters to sympathize with her in
this sad bereavement. She was now alone to struggle with the cold
world, which made no allowance for her faults of the head, but were
visited upon her as crimes of a darker die.
“Years elapsed, and nothing more reached me of Florence. I
married your uncle, dear Cora, and spent many, many happy years
with him here, in my little nest as you term it, when death also came
to tear him from me. Then, too, with my sorrow, came the oftener
thoughts of my girl-friend, Florence Walton. Wondering had she ever
married—was she a mother, a widow—and still above all came the
wish that I could see her once again. I had written to her frequently,
but my letters were never answered, and so I began to imagine that
time had blotted out my name from ‘memory’s page,’ or that she had
gone forth into the world under some other cognomen, and that my
letters had failed to reach her. Somehow, I could never think her
dead, there was too much life and liveliness in my ideal of her, to
join them together.
“Other thoughts began to have influence over me, when one day
among letters and papers, came one, bearing my name in her own
hand-writing! That old, familiar penmanship brought back, like some
fondly remembered strain of music, thoughts of childhood’s happy
days, and my heart leaped forth in love welcome to the writer ere I
broke the envelope. How much more were my feelings stirred within
me, when the warm, passionate nature of Florence beamed forth in
every line. She proffered a visit to me, telling me, that she too had
known sorrow, deep, lasting—and when she thought of my
happiness, she could not bear to lay open the still tender wound; but
I had suffered, as she had very recently learned, and could therefore
without additional heart-pangs give my sympathy to a friend, my
own, old, wayward, school-friend.”
“How quickly did I respond, and urge her to come speedily, and
she came.”
“Yes, dear aunty,” said Cora, “I recollect her now. I was a tiny
one, it is true, but I remember well a lady, who dressed in mourning,
and was accustomed to walk evening after evening up and down the
broad portico with you, while I, too, would endeavor to keep pace
with you, till tired out I have thrown myself across the door-step and
slept, unconsciously, until you became aware of ‘my small existence,’
and gave me to Elsie, to put in bed.”
“Yes, dear Co, I plead guilty; for the fascination of Florence’s
conversation, tinctured, too, with sadness, was sufficient to make
any one forget their own identity. It was during that visit she
narrated all that happened to her during our separation. But, as I
am but little skilled as a raconteuse, I will, after Elsie has given us
our tea, lend you her journal to glance over. She said, when she
gave it to me, ‘This journal, my dear Mary, will bring me and my
trials sometimes before your eyes; for I cannot bear to be utterly
forgotten by the one being who has loved me through evil as well as
good report. Besides, I think it sinful to remind myself, by looking
over these blotted pages—which, strange incongruity as it may
appear, I cannot bear the idea of destroying—as they make me
unhappy and discontented, by recalling times past, that were better
forever to lie buried in Oblivion’s stream.’
“There, Co, is the manuscript—rather formidable in its closely
written pages; but to me, so full of interest, that I should have read
it were it six times as long. So, read it to yourself, dear, after you
have given me my tea, and then I will attend to my little domestic
concerns; for though ’tis, indeed, but a ‘wee nest,’ yet the birds of
the air do not minister to me.”
“Thank you, dear aunty. Now, Elsie, my good Elsie, please hurry
with the tea-waiter; for I am so famished with curiosity to read these
yellow leaves, that I will pardon any supper, if ’tis not comme il faut,
if you will only hurry!”
My readers will imagine the refreshment past—the wick of the
lamp raised—the shade adjusted—and the fair Cora, with her head
supported by one tiny hand, hid in a shower of curls, seated at the
centre-table, in the most comfortable of all chairs, and deeply intent
upon the pages of

THE JOURNAL
Tuesday night, June.—Well, ’tis over. To-day I arrived in my new
home; and setting aside my longing after a home-feeling, which I
have ever felt since the death of my dear, dear mother, there is no
place that promises more domestic enjoyments than Alton;
especially if Clare, my cousin, will love me and let me love her. She is
a pretty girl, not beautiful, I admit, but sufficiently comely. My good,
kind uncle, too! I can love him, I know; for how careful—how very,
very tender was he of my feelings on our road hither. My room, also,
is very nicely arranged; and as I glance around, I think I may again
be happy, even, though I am dependent on my uncle’s bounty. I
must to sleep now, for I am too sleepy now for aught else.
Monday.—Several days have elapsed since I last wrote; and I
begin to love my old uncle in reality. There is yet another member of
our small family circle, whom I did not see the first day of my arrival.
It is an old lady, claiming cousinship with my Uncle Alton, and
carrying herself with quite an “air” to myself. Very strict, too, she
seems in her religious views; and yet sadly lacking in herself that
charity for others which, in my eyes, is the light, “pure and
undefiled.” Ah, me! I must stop, or I shall be wanting in that which I
am so lauding. How lonely—how very lonely do I yet feel! no nearer
my home of the heart yet, I fear me. My uncle I love; but—my
Cousin Clare is so strange. Can she love, or is she like one of those
incomprehensible characters of whom I have read, who keep all
those feelings hidden deep within their heart of hearts, until they die
away of themselves, leaving them in reality as callous as she now
seems to me. I have tried to settle myself to my usual employments.
I sew, I read, and tune my guitar occasionally; and often wander
out, with my books, into those grand old woods around Alton, and
sitting there under their deep, dark shadows, find companionship in
my thoughts. My Cousin Clare I did ask once to accompany me, but
was refused, on account of household duties; and Mrs. Dudley
added, with an expression of countenance, to emphasize her
speech, “Clare, Miss Walton, thinks of others besides herself. For my
part, I never admired those tramps through the woods, of which
some young ladies are so fond.” And her mouth was settled into that
self-complacent expression, as if perfectly satisfied of the effect
produced on me—imagining that poor I must be abashed into utter
prostration before the majesty of her disapproval. Nevertheless, I
still walk, and will continue doing so, with or without approval, which
I neither value nor seek.
Thursday night, July.—What a difference will the arrival of an
agreeable person make in a country-house. Now, yesterday and to-
day are so rapid, compared with the preceding weeks. There has
been an arrival at Alton. No less a personage than Col. Dudley, a
nephew, by marriage, to my old plague. His health, it seems, is not
very good—and he passes the summer here to re-establish it. He
lives in the “sunny South,” and gives me some glowing descriptions
of it. I have some one now who is in reality a companion; but,
although this seems equally agreeable to me, and to himself, it does
not seem to be relished as well by Mrs. Dudley.
Sunday, September.—Many weeks have elapsed since I have
written in my journal. I have been so happy, that I took no note of
time. Col. Dudley has been my constant companion; and Mrs.
Dudley, his aunt, though always making little plans and plots to draw
him into her own and Clare’s society—from which I am as much
excluded by my own choice, as their habitual reserve—has not
succeeded as yet. I am sure to find him at my side, whether in a
walk or ride. And these same glorious woods—so old, so grand—how
beautiful they are becoming now, as the “melancholy days” draw
nigh. What made the poet say the autumn days were the “saddest
of the year.” I am sure he must have been indulging in a poetical
license, for to me they are infinitely joyous and gladsome. I know—I
feel that Hugh Dudley loves me; and yet why does he not ask me to
be his. Perhaps he waits for a manifestation of my feelings for him;
but that I shall never evince, dearly as I love him. I know that he is
proud—so much so, that much as I love a proud man, it becomes
almost a fault in him. But I am also proud; and where I most love,
there am I always the most reserved. I wish him to know “I would
be wooed, and not unsought be won.”
Wednesday night.—How happy! how immeasurably happy am I!
I can hardly realize these joyous feelings! I have just entered my
chamber, too excited for sleep; and seeing my journal lying close to
the writing-desk, have opened it to put in words, my joy. It appears
unaccountable to me, how, for one moment, I could have imagined
myself happy before, when I compare my present ecstatic feelings to
what I can remember of ever experiencing. It seems that my heart
is opening in love, to the whole world. I could even take Mrs. Dudley
with the kindest affection to it, if she would allow me; but why or
wherefore she dislikes me, and will manifest that feeling for me.
Even my perceptions of the beautiful have grown so much the more
lively; and the meanest thing of earth—the mossy trunk—the
cloudlet—the sky—the stream—the wild-flower—are all floating in an
atmosphere of light and beauty. And why is all this? Oh! my proud
heart, you are now satisfied; and you can answer, why this ecstatic
feeling. I love and I am loved! Hugh Dudley—my own Hugh—has
told me this in words—so wondrously eloquent—and has, at last,
sued me to become his wife. He wished our marriage to take place
at once; but for all sufficient reasons, I have begged him to defer it
till next summer. Then I will go forth with him among strangers—
with him who is my world. I have found at last my home of the
heart. ’Tis in his love—his ardent, disinterested love. And why did I
not marry him at once, and go with him to his own sunny home? I
could not, proud heart that I am, bear to owe the very dress in
which I should be decked at the altar, to the bounty of my uncle—
how much less to Col. Dudley. Though I have a home with them—
that is, shelter and food—yet my right hand should be cut off, ere I
would take pecuniary aid from any. They all look cold upon me now,
even my uncle. I have ever conducted myself respectfully—nay, even
affectionately toward him; but, for some reason or other, he has
altered toward me, and I have drawn myself again into my reserve. I
have undoubtedly thwarted some cherished plan of his, with respect
to Clare and Dudley; but even my dependence on him—gratitude will
not be forced—will not allow me to regret what has happened. Oh!
so contented—so blest am I—that cold looks from the world are
unregarded, so long as I am conscious of his love. I had been sick,
and sad, for two days and more; my heart and head seemed
bursting, for I could hear, in my chamber (where sickness kept me
prisoner) the sound of mirth and enjoyment going on below. Even
the unwonted laugh of Clare was echoing merrily, as if my absence
kindled a fire of joy in her bosom of ice; and my jealous heart told
me she was happy, because of the attentions of Col. Dudley. I could
not endure the thought of his wasting upon her one smile—one
word beyond those of common civility. Very, very wicked was I on
that bed of sickness; for every time I could hear the voice of Mrs.
Dudley calling upon my cousin, in a gladdened tone, I would half
utter aloud, “Yes! that vile old woman is satisfied now. She thinks he
will love that icicle—that automaton.” Yes, wicked I was, indeed; but
then, sick and suffering, I should have been treated with more
sympathy by those under whose roof I then was eating the bread of
dependence, it would have made it less bitter—not near so choking.
One ceremonious visit for the day from Clare—one message of
inquiry from my uncle, was the sole interest that was bestowed upon
me. How can it be wondered at, then, if my heart grew bitter toward
them; ay, even to him, for if he inquired, it was never told me. But
the bitterness I felt toward him was different from that which I felt
toward my uncle and cousin. When I reflected on their conduct,
there was a mingling of anger and revenge; when on him, the tears
would rush to my eyes, an aching feeling to my heart, and I would
say, “Could I only die now, would he shed one tear, or be saddened
by the cold, pale face of her whom he must have known felt
something for him beside mere friendship.” And then I would hide
my eyes in the pillow, and weep in pity over the sad fate of myself
which I thus pictured.
As these bitter, bitter thoughts careered through my brain—
increasing its ache—how did I sigh for the rest of the grave. “For the
living know that they shall die: but the dead know not any thing,
neither have they any more a reward; for the memory of them is
forgotten. Also their love, and their hatred, and their envy is now
perished; neither have they any more a portion for ever in any thing
that is done under the sun.” I snatched my journal—in my longing to
unburthen myself of my weight of wo—and scribbled what I here
transcribe, but which from shame I have since torn out:
“Why, oh Father! didst thou see fit to throw me here in this bitter
world, to suffer and to struggle alone! Alone must I suffer—alone am
I in my love—alone in my despair—and when dying solitary, and I
am bore to the rest of the grave, I shall be unwept, unthought of.
Well! be it so; only, Father, teach me to bow in submission and to
drink without murmuring of the bitter cup. I already look upon the
tomb, as the storm-tossed mariner to his haven of safety, ‘where the
wicked cease from troubling and the weary are at rest.’ Ah! how few
care what the motherless one, cut off from the world by poverty and
other adverse circumstances, must endure. My wishes and my hopes
are mine, and mine alone. I feel, as I imagine the deaf and dumb
one does, whose heart is full of love, and bright, warm, beautiful
fancies, and who cannot give them words. To whom can I utter
them? All, all these feelings must be forever buried in the depths of
mine own sad heart, and nothing but the froth, the foam, and the
weeds, be thrown on the surface for the world’s gaze. Oh! how I
envy those who have fond parents—a dear brother—a loving sister.
How I long for a sympathy—a resting-place for my affections, which
I despair of ever finding on earth, but which I hope I may realize
with Him, the Father, who has given me this capability of loving.”
This was written after hearing what my imagination—heated with
fever and jealousy—construed into a light laugh from Dudley,
immediately under my window. I knew it was him, for I heard the
crashing sound of his boot-heel on the gravel, and the mingling
tones of his aunt and Clare. They had all been walking—for I sprang
from the bed to ascertain the fact. Yes, walking! For Clare was
leaning on his arm; her sun-bonnet dangling by the string from her
hand, and to my jealous eye she had never looked so near to
beautiful. Her cheeks were flushed, and a smile almost loving parted
her lips as she looked up into his face. They had stopped to admire a
flower, over which Mrs. Dudley still leaned, and he—apparently—was
describing some of the same kind he possessed. How I hated Clare,
at the moment, there standing with her hand upon his arm, when
there was no necessity for the support; loving him, too, as I knew
she must—though in what manner I could not picture to myself—for
I had ever thought from her impassable nature it was the blood of
fishes which filled her veins. As I looked upon the group my
dejection became intensified into agony. I felt utterly alone, and I
wished for some kind Samaritan to pour the oil of sympathy into my
bleeding wounds. It was then I wrote, and in the despair of my soul
I felt that all was vanity and bitterness, and that I had deceived
myself entirely—yes, blindly deceived myself. He cared not for me—
whilst I was writhing in pain, he was merrily and gleefully laughing
with those whom he knew, as well as I did, loved me not.
How changed my feelings now from those penned above, wrung
from me by jealousy and despair! ’Tis as if I had been groping in
some dark, noisome cave alone—ay, alone and fearful—and had
suddenly entered an inner chamber, before unknown, where a
thousand lights are dancing and reflecting against its brilliant
columns and gem-like stalactites pendent from its illuminated sides
and dome—so beautiful—so sudden has been the change. To begin
at the beginning and tell how came this change.
For three days had I kept my room. On the afternoon of the third
I stole out unobserved, as I thought, and made my way to the old,
sombre-looking forest—my favorite haunt—where, under its dark,
umbrageous trees, amid its gloom and solitude, I sought for
companionship for my own sad thoughts. Seated on a fallen tree,
turning with my foot the dry leaves listlessly, and hearing the
moaning and sighing of the breeze through the tree tops. No other
sound reached me; but I started up wildly—for sickness had made
me nervous—as a hand was laid upon my arm, and scarcely heard

You might also like