Getting Started with PowerShell
eBook - ePub

Getting Started with PowerShell

  1. 180 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Getting Started with PowerShell

About this book

Learn the fundamentals of PowerShell to build reusable scripts and functions to automate administrative tasks with Windows

About This Book

  • Harness the capabilities of the PowerShell system to get started quickly with server automation
  • Learn to package commands into a reusable script and add control structures and parameters to make them flexible
  • Get to grips with cmdlets that allow you to perform administration tasks efficiently

Who This Book Is For

This book is intended for Windows administrators or DevOps users who need to use PowerShell to automate tasks. Whether you know nothing about PowerShell or know just enough to get by, this guide will give you what you need to go to take your scripting to the next level.

What You Will Learn

  • Learn to verify your installed version of PowerShell, upgrade it, and start a PowerShell session using the ISE
  • Discover PowerShell commands and cmdlets and understand PowerShell formatting
  • Use the PowerShell help system to understand what particular cmdlets do
  • Utilise the pipeline to perform typical data manipulation
  • Package your code in scripts, functions, and modules
  • Solve common problems using basic file input/output functions
  • Find system information with WMI and CIM
  • Automate IIS functionality and manage it using the WebAdministration module

In Detail

Windows PowerShell is a task-based command-line shell and scripting language designed specifically for system administration. Built on the.NET Framework, Windows PowerShell helps IT professionals and power users control and automate the administration of the Windows operating system and applications that run on Windows.

PowerShell is great for batch importing or deleting large sets of user accounts and will let you collect a massive amount of detailed system information in bulk via WMI (Windows Management Instrumentation).

Getting Started with PowerShell is designed to help you get up and running with PowerShell, taking you from the basics of installation, to writing scripts and web server automation. This book, as an introduction to the central topics of PowerShell, covers finding and understanding PowerShell commands and packaging code for reusability, right through to a practical example of automating IIS. It also includes topics such as installation and setup, creating scripts, automating tasks, and using Powershell to access data stores, registry, and file systems.

You will explore the PowerShell environment and discover how to use cmdlets, functions, and scripts to automate Windows systems. Along the way, you will learn to perform data manipulation and solve common problems using basic file input/output functions.

By the end of this book, you will be familiar with PowerShell and be able to utilize the lessons learned from the book to automate your servers.

Style and approach

A practical learning guide, complete with plenty of activities, examples and screenshots.

Tools to learn more effectively

Saving Books

Saving Books

Keyword Search

Keyword Search

Annotating Text

Annotating Text

Listen to it instead

Listen to it instead

Information

Getting Started with PowerShell


Table of Contents

Getting Started with PowerShell
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. First Steps
Determining the installed PowerShell version
Using the registry to find the installed version
Using PowerShell to find the installed version
Installing/upgrading PowerShell
Starting a PowerShell session
PowerShell hosts
64-bit and 32-bit PowerShell
PowerShell as an administrator
Simple PowerShell commands
PowerShell aliases
Summary
For further reading
2. Building Blocks
What can you do?
The scripter's secret weapon – tab completion
How does that work?
Interpreting the cmdlet syntax
Summary
For further reading
3. Objects and PowerShell
Objects all the way down
Digging into objects
Types, classes, and objects
What are members?
The DOS DIR command
The IPCONFIG command
PowerShell for comparison
The Get-Member cmdlet
Where did these all come from?
Summary
For further reading
4. Life on the Assembly Line
The pipeline as an assembly line
This isn't your DOS or Linux pipeline
Objects at your disposal
Dealing with pipeline data
The Sort-Object cmdlet
The Where-Object cmdlet
The Select-Object cmdlet
Limiting the number of objects returned
Limiting the properties of the objects returned
Retrieving the values of a single property
The Measure-Object cmdlet
The Group-Object cmdlet
Putting them together
Summary
For further reading
5. Formatting Output
When does formatting occur?
The rules of automatic formatting
Formatting files
Formatting decisions are based on the first object
Small objects go in a table
Large objects go in a list
Cmdlets that control formatting
Format-Table and Format-List
The dangers of formatting
Best practices of formatting
Summary
For further reading
6. Scripts
Packaging commands
Execution policy
Types of scripts
Scopes and scripts
Parameters add flexibility
Adding some logic
Conditional logic (IF)
Looping logic
More logic
Profiles
Summary
For further reading
7. Functions
Another kind of container
Comparing scripts and functions
Executing and calling functions
Naming conventions
Comment-based help
Parameters revisited
Typed parameters
Switches
Default values for parameters
Output
Summary
For further reading
8. Modules
Packaging functions
Script modules
The Export-ModuleMember cmdlet
Where do modules live?
Removing a module
PowerShell module autoloading
The #Requires statement
Removing a module – take two
Manifest modules
Listing modules
Summary
9. File I/O
Reading and writing text files
Writing text files
Working with CSV files
Output to CSV for quick reports
The Invoke-Item cmdlet
Import from CSV for quick objects
PowerShell streams and redirection
Other types of redirection operators
The out-file cmdlet
CLIXML – a special type of XML
Summary
For further reading
10. WMI and CIM
What is WMI?
WMI organization
Finding WMI classes
Retrieving objects with Get-WMIObject
Getting the right instance
WQL syntax
Calling methods
WMI and CIM
The CIM cmdlets
CDXML modules
Summary
For further reading
11. Web Server Administration
Installing IIS
Detecting and installing IIS in Windows 8.1
Detecting and installing IIS in Server 2012R2
Verifying IIS
The WebAdministration module
Starting, stopping, and restarting IIS
Creating virtual directories and web applications
Working with application pools
Creating application pools
Summary
For further reading
A. Next Steps
Index

Getting Started with PowerShell

Copyright © 2015 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot gu...

Table of contents

  1. Getting Started with PowerShell

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn how to download books offline
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 990+ topics, we’ve got you covered! Learn about our mission
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more about Read Aloud
Yes! You can use the Perlego app on both iOS and Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app
Yes, you can access Getting Started with PowerShell by Michael Shepard in PDF and/or ePUB format, as well as other popular books in Computer Science & Computer Networking. We have over one million books available in our catalogue for you to explore.