SAMPLE CHAPTER SECOND EDITION. Don Jones Jeffery Hicks Richard Siddaway MANNING

Similar documents
An administrator s guide

Introduction. 1.1 Who this book is for. This chapter covers. What the book will and won t teach The boundaries of this book Going beyond PowerShell

Automating Administration with Windows PowerShell

"Charting the Course... MOC C: Automating Administration with Windows PowerShell. Course Summary

: 10961C: Automating Administration With Windows PowerShell

Corporate Training Centre (306)

Microsoft Automating Administration with Windows PowerShell

Course 10961: Automating Administration with Windows PowerShell

Automating Administration with Windows PowerShell

Automating Administration with Windows PowerShell

Course Outline. Advanced Automated Administration with Windows PowerShell Course 10962: 3 days Instructor Led

Product Page:

[MS10961]: Automating Administration with Windows PowerShell

SAMPLE CHAPTER SECOND EDITION. Don Jones Jeffery Hicks Richard Siddaway MANNING

COURSE 10961B: AUTOMATING ADMINISTRATION WITH WINDOWS POWERSHELL

ADVANCED AUTOMATED ADMINISTRATION WITH WINDOWS POWERSHELL

Course Outline: Course Automating Administration with Windows PowerShell v3.

Course Outline. Automating Administration with Windows PowerShell Course 10961B: 5 days Instructor Led

Automating Administration with Windows PowerShell V3

COURSE 10962B: ADVANCED AUTOMATED ADMINISTRATION WITH WINDOWS POWERSHELL

Automating Administration with Windows PowerShell (M10961)

10961C: Automating Administration with Windows PowerShell

Learn Windows PowerShell in a Month of Lunches

Advanced Automated Administration with Windows PowerShell

PowerShell 10961: Automating Administration with Windows PowerShell. Upcoming Dates. Course Description. Course Outline

COURSE OUTLINE: OD10961B Automating Administration with Windows PowerShell

Learn PowerShell Toolmaking In A Month Of Lunches Free Download PDF

POWERSHELL MANAGEMENT IN A NUTSHELL

10961B: Automating Administration with Windows PowerShell

Automating Administration with Windows PowerShell (10961)

This course incorporates materials from the Official Microsoft Learning Product M10961: Automating Administration with Windows PowerShell.

Customizing DAZ Studio

Creating HTML Reports in PowerShell

Automating Administration with Microsoft Windows PowerShell

Automating Administration with Windows PowerShell 2.0

WINDOWS POWERSHELL 3.0 FIRST STEPS BY ED WILSON DOWNLOAD EBOOK : WINDOWS POWERSHELL 3.0 FIRST STEPS BY ED WILSON PDF

Learn Windows PowerShell 3 in a Month of Lunches

Advanced Automated Administration with Windows PowerShell

T H E I N T E R A C T I V E S H E L L

Advanced Automated Administration with Windows PowerShell (MS-10962)

As a programmer, you know how easy it can be to get lost in the details

Learn PowerShell Toolmaking in a Month of Lunches

shortcut Tap into learning NOW! Visit for a complete list of Short Cuts. Your Short Cut to Knowledge

An administrator s guide

Microsoft Windows PowerShell v2 For Administrators

Learning The Bash Shell: Unix Shell Programming (In A Nutshell (O'Reilly)) PDF

Rockablepress.com Envato.com. Rockable Press 2010

Inside Visual C++: With CDROM (Microsoft Programming Series) PDF

Hello! ios Development

Part II Composition of Functions

Contents at a Glance

Advanced Automated Administration with Windows PowerShell

Pearson: Windows PowerShell in 24 Hours Labs. Course Outline. Pearson: Windows PowerShell in 24 Hours Labs.

DOWNLOAD OR READ : WINDOWS POWERSHELL SCRIPTING GUIDE PDF EBOOK EPUB MOBI

MEAP Edition Manning Early Access Program Learn Hyper V in A Month of Lunches Covers Windows Server 2016 Version 3

THINGS YOU NEED TO KNOW ABOUT USER DOCUMENTATION DOCUMENTATION BEST PRACTICES

Introduction. Thank you for picking up Silverlight 1.0 Unleashed! IN THIS CHAPTER. . Who Should Read This Book?. Software Requirements

Learn Python In One Day And Learn It Well: Python For Beginners With Hands-on Project. The Only Book You Need To Start Coding In Python Immediately

Expert Reference Series of White Papers. Five Simple Symbols You Should Know to Unlock Your PowerShell Potential

Part II: PowerShell s Basic Structure and Syntax... 47

Security Challenges: Integrating Apple Computers into Windows Environments

One of the fundamental kinds of websites that SharePoint 2010 allows

New Perspectives On HTML, CSS, And Dynamic HTML Ebooks Free

Read & Download (PDF Kindle) VBA Developer's Handbook, 2nd Edition

Creating Simple Links

Acing the QuickBooks Online Certification Exam

A PRACTICAL GUIDE TO SHAREPOINT 2013: NO FLUFF! JUST PRACTICAL EXERCISES TO ENHANCE YOUR SHAREPOINT 2013 LEARNING! BY SAIFULLAH SHAFIQ

Touring the Mac S e s s i o n 4 : S A V E, P R I N T, C L O S E & Q U I T

Learn PowerShell Toolmaking in a Month of Lunches

Usability Test Report: Bento results interface 1

Small changes. Big results.

Get Your Browser into Use Quickly!

Microsoft Core Solutions of Microsoft SharePoint Server 2013

VIDEO 1: WHAT ARE THE SMART CONTENT TOOLS? VIDEO 2: HOW DO YOU CREATE A SMART CTA?

Monitoring Tool Made to Measure for SharePoint Admins. By Stacy Simpkins

10961B: Automating Administration with Windows PowerShell

Remote Control in Detail: PowerShell Remoting

A quick guide to... Split-Testing

Sucuri Webinar Q&A HOW TO IDENTIFY AND FIX A HACKED WORDPRESS WEBSITE. Ben Martin - Remediation Team Lead

Installing Dolphin on Your PC

POWERSHELL + DEVOPS POWERSHELL WS-MAN DEVOPS TOOLMAKING GLOBAL SUMMIT 2016 LINUX WINDOWS CONFIGURATION KEY FACTS_ WINRM DSC ISE RUNBOOKS CLOUD

Windows Server 2008 Resource Kit PDF

The ebuilders Guide to selecting a Web Designer

Microsoft Windows Server 2003 Administration Fundamentals

20331B: Core Solutions of Microsoft SharePoint Server 2013

Iron Scripter 2018: Prequel 3 A commentary

Digital Marketing Manager, Marketing Manager, Agency Owner. Bachelors in Marketing, Advertising, Communications, or equivalent experience

Microsoft SharePoint 2013 Disaster Recovery Guide PDF

Excel Basics: Working with Spreadsheets

WordPress Tutorial for Beginners with Step by Step PDF by Stratosphere Digital

Financial Statements Using Crystal Reports

INTRODUCTION. 2

Legal Notice: Copyright 2012 and 2013 Hitman Advertising, all rights reserved. You are responsible for your own advertising in your business.

CS 4349 Lecture August 21st, 2017

Creating Word Outlines from Compendium on a Mac

Data Structures And Other Objects Using Java Download Free (EPUB, PDF)

The Challenges for Software Developers with Modern App Delivery

Introduction. A Brief Description of Our Journey

Advanced Technologies of SharePoint 2016 ( )

Read & Download (PDF Kindle) Data Structures And Other Objects Using Java (4th Edition)

Transcription:

SAMPLE CHAPTER SECOND EDITION Don Jones Jeffery Hicks Richard Siddaway MANNING

PowerShell in Depth by Don Jones Jeffery Hicks Richard Siddaway Chapter 1 Copyright 2015 Manning Publications

brief contents PART 1 POWERSHELL FUNDAMENTALS...1 1 Introduction 3 2 PowerShell hosts 7 3 Using the PowerShell help system 19 4 The basics of PowerShell syntax 33 5 Working with PSSnapins and modules 44 6 Operators 52 7 Working with objects 69 8 The PowerShell pipeline 106 9 Formatting 125 PART 2 POWERSHELL MANAGEMENT...143 10 PowerShell Remoting 145 11 Background jobs and scheduling 181 12 Working with credentials 196 13 Regular expressions 206 14 Working with HTML and XML data 222 v

vi BRIEF CONTENTS 15 PSDrives and PSProviders 244 16 Variables, arrays, hash tables, and script blocks 260 17 PowerShell security 282 18 Advanced PowerShell syntax 296 PART 3 POWERSHELL SCRIPTING AND AUTOMATION...315 19 PowerShell s scripting language 317 20 Basic scripts and functions 332 21 Creating objects for ouput 344 22 Scope 361 23 PowerShell workflows 376 24 Advanced syntax for scripts and functions 406 25 Script modules and manifest modules 427 26 Custom formatting views 439 27 Custom type extensions 451 28 Data language and internationalization 465 29 Writing help 477 30 Error handling techniques 484 31 Debugging tools and techniques 496 32 Functions that work like cmdlets 520 33 Tips and tricks for creating reports 539 PART 4 ADVANCED POWERSHELL...549 34 Working with the Component Object Model (COM) 551 35 Working with.net Framework objects 560 36 Accessing databases 573 37 Proxy functions 581 38 Building a GUI 593 39 WMI and CIM 613 40 Working with the web 640 41 Desired State Configuration 656

Introduction This chapter covers What the book will and won t teach The boundaries of this book Going beyond PowerShell As of this writing, Windows PowerShell is on to its seventh year of existence and in its fourth major release, with a fifth version in preview. In that time, it s changed the way people look at administering many Microsoft, and even some non-microsoft, products. Although the graphical user interface (GUI) will always be an important part of administration in many ways, PowerShell has given administrators options: Use an easy, intuitive GUI; manage from a rich, interactive command-line console; or fully automate with a simple scripting language. We re delighted that so many administrators have started using PowerShell, and we re honored that you ve chosen this book to further your own PowerShell education. 1.1 Who this book is for We wrote this book for system administrators, not developers. In the Microsoft world, administrators go by the catchall title IT professional or IT pro and that s who we had in mind. As such, we assume you re not a full-time programmer, although 3

4 CHAPTER 1 Introduction if you have some programming or scripting experience it ll make certain parts of Power- Shell easier to learn. We assume you re primarily interested in automating various administrative tasks and processes, or at least being more efficient, but we don t make any assumptions about the products with which you work. You may be an Exchange Server administrator, or maybe SharePoint or SQL Server is your thing. Perhaps you manage Active Directory, or you re in charge of file servers. You may even manage a Citrix or VMware environment (yes, they can be managed by PowerShell). It doesn t matter, because what we ll focus on in this book is the core technologies of PowerShell itself: the techniques and features you ll need to use no matter what products you re administering. We do use Active Directory in a few examples, but every technique, pattern, practice, and trick we show you will apply equally well, no matter where you ve chosen to use PowerShell. 1.2 What this book will teach you You can certainly read this book cover to cover, and we ve tried to arrange the chapters in a logical progression. But in the end, we intend for this book to be a reference. Need to figure out PowerShell Remoting? Skip to that chapter. Confused about how commands pipe data from one to another? We ve written a chapter for that. Need to access a database from within a PowerShell script? There s a chapter for that. We ve no intention of making you a programmer we don t claim to be programmers we all have backgrounds as IT pros. Yes, PowerShell can support some robust scripts, but you can also accomplish a lot by running commands. If you have programming experience, it ll serve you well, and you may be tempted to approach PowerShell more as a scripting language, which is fine. If you ve never scripted or programmed a single line of code, you ll probably see PowerShell as a pure command-line interface, where you run commands to make stuff happen, and that s fine, too. Either way you win because you get to automate your tedious, repetitive work. The other winning feature is that what you learn by using PowerShell at the command line is directly usable when you start writing scripts there s no wasted learning with PowerShell. 1.3 What this book won t teach you We assume you re already an experienced administrator and that you re familiar with the inner workings of whatever technology you manage. We aren t going to teach you what an Active Directory user account is, or what an Exchange mailbox does, or how to create a SharePoint site. PowerShell is a tool that lets you accomplish administrative tasks, but like any tool it assumes you know what you re doing. To use a noncomputer analogy, PowerShell is a hammer, and this book will teach you how to swing that hammer and not smash your thumb. We won t teach you about building houses, though we assume you already know how to do that and that you re looking for a more efficient way to do it than pounding nails with a rock.

Beyond PowerShell 5 1.4 Where we drew the line It s safe to say that PowerShell can t do everything for you. You ll find some things with which it s completely incapable of helping, as with any technology. But you ll also find tasks for which PowerShell works well. And you ll encounter that weird middle ground where you could do something in PowerShell, but to do it you d have to go beyond the strict boundaries of what PowerShell is. For example, PowerShell doesn t natively contain a way to map a network printer. NOTE There is a PrintManagement module containing an Add-Printer cmdlet, but it s part of Windows (specifically Windows 8/2012 and later) rather than PowerShell. You could instantiate a Component Object Model (COM) object to accomplish the task from within PowerShell, but it has nothing to do with PowerShell. Instead, it s the shell giving you a way to access completely external technologies. In these cases (which are becoming increasingly rare in the latest version of Windows), we ll only say, You can t do that in PowerShell yet. We know our statement isn t 100% true, but we want to keep this book focused on what PowerShell is and what it does natively. If we turn this book into everything you can do with PowerShell natively, plus all the external stuff like.net and COM and so on that you can get to from PowerShell, it d grow to 7,000 pages in length and we d never finish. That said, we re including material in the book on using some of these external technologies, along with some guidance on where you can find resources to educate yourself on them more completely if you ve a mind to do so. 1.5 Beyond PowerShell PowerShell is a lot like the Microsoft Management Console (MMC), with which you re probably familiar. On its own, it s useless. Both the MMC and PowerShell only become useful when you add extensions, which in the MMC would be snap-ins, and in Power- Shell would be either a snap-in or a module. Those extensions give you access to Exchange, Active Directory, SharePoint, SQL Server, and so on. The later versions of Windows (Windows 8 and later) ship with over 50 additional modules, not counting the Remote Server Administration Tools (RSAT) modules. This additional functionality is blurring the boundaries of PowerShell. The thing to remember is that in this book we re concentrating on the core of PowerShell so that you understand how it works. Using the other modules will become obvious once you understand PowerShell itself. Understand that the folks at Microsoft who write PowerShell don t write the extensions. They provide some tools and rules for the developers who do create extensions, but their job is to create the core PowerShell stuff. Extensions are made by other product teams: The Exchange team makes the Exchange PowerShell extension, the Active Directory team makes its extension, and so on. If you re looking at a particular extension and don t like what you see, blame the product team that produced it, not PowerShell. If you d like to administer something maybe Windows Internet Name

6 CHAPTER 1 Introduction Service (WINS) Server, for example and PowerShell has no way to administer it, it s not the PowerShell team s fault. Blame the owners of the technology you re trying to work with, and encourage them to get on board and produce a PowerShell extension for their product. This division of labor is one reason why we re keeping this book focused on the core of PowerShell. That core is what you ll use no matter what extensions you end up deploying to achieve your administrative goals. 1.6 Ready? Okay, that s enough of an introduction. If you want to follow along, make sure you have PowerShell v4 installed on a Windows 7 or later client. You ll also find it useful to have a test server running PowerShell v4, ideally on Windows Server 2012 R2. NOTE The examples and code in this book will work with PowerShell v5 if you have that installed. The major new feature in PowerShell v5 is software management through the OneGet module. Now, pick a chapter and jump in.

POWERSHELL PowerShell IN DEPTH, Second Edition Jones Hicks Siddaway A Windows admin using PowerShell every day may not have the time to search the net every time he or she hits a snag. Wouldn t it be great to have a team of seasoned PowerShell experts ready to answer even the toughest questions? That s what you get with this book. PowerShell in Depth, Second Edition is the go-to reference for administrators working with Windows PowerShell. Every major technique, technology, and tactic is carefully explained and demonstrated, providing a hands-on guide to almost everything an admin would do in the shell. Written by PowerShell MVPs Don Jones, Jeffrey Hicks, and Richard Siddaway, each valuable technique was developed and thoroughly tested, so you ll be able to consistently write production-quality, maintainable scripts while saving hours of time and effort. What s Inside Automating tasks Packaging and deploying scripts Introduction to Desired State Configuration PowerShell security Covers PowerShell version 3 and later SEE INSERT Very thorough. My go-to book for PowerShell. Lincoln Bovee, Protolabs, Inc. Three MVPs thinking deeply about PowerShell. What more can you want? David Moravec Mainstream Technologies Immediately applicable to real-world problems. Jim Gray, Navigant Consulting An excellent way to gain more PowerShell wisdom! Arthur Zubarev Complete Innovations, Inc. This book assumes you know the basics of PowerShell. Don Jones, Jeffery Hicks, and Richard Siddaway are Microsoft MVPs, trainers, and administrators. Collectively, they ve authored nearly three dozen books on PowerShell and Windows administration. To download their free ebook in PDF, epub, and Kindle formats, owners of this book should visit manning.com/powershellindepthsecondedition MANNING $59.99 / Can $62.99 [INCLUDING ebook]