Tải bản đầy đủ (.pdf) (434 trang)

Automating Microsoft® Windows Server® 2008 R2 with Windows PowerShell® 2.0 potx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (14.65 MB, 434 trang )

ffirs.indd iiffirs.indd ii 4/18/2011 3:07:34 PM4/18/2011 3:07:34 PM
Automating Microsoft®
Windows Server® 2008
R2 with Windows
PowerShell® 2.0
ffirs.indd iffirs.indd i 4/18/2011 3:07:28 PM4/18/2011 3:07:28 PM
ffirs.indd iiffirs.indd ii 4/18/2011 3:07:34 PM4/18/2011 3:07:34 PM
Automating
Microsoft®
Windows
Server® 2008 R2
with Windows
PowerShell® 2.0
Matthew Hester
Sarah Dutkiewicz
ffirs.indd iiiffirs.indd iii 4/18/2011 3:07:34 PM4/18/2011 3:07:34 PM
Acquisitions Editor: Agatha Kim
Development Editor: Dick Margulis
Technical Editor: Sarah Dutkiewicz
Production Editor: Liz Britten
Copy Editor: Kim Wimpsett
Editorial Manager: Pete Gaughan
Production Manager: Tim Tate
Vice President and Executive Group Publisher: Richard Swadley
Vice President and Publisher: Neil Edde
Book Designer: Franz Baumhackl
Proofreader: Word One, New York
Indexer: Jack Lewis
Project Coordinator, Cover: Katie Crocker
Cover Designer: Ryan Sneed


Cover Image: © Petrovich9 / iStockPhoto
Copyright © 2011 by Wiley Publishing, Inc., Indianapolis,
Indiana
Published simultaneously in Canada
ISBN: 978-1-118-01386-1 (Cloth)
ISBN: 978-1-118-10306-7 (ebk)
ISBN: 978-1-118-10308-1 (ebk)
ISBN: 978-1-118-10309-8 (ebk)
No part of this publication may be reproduced, stored in a
retrieval system or transmitted in any form or by any means,
electronic, mechanical, photocopying, recording, scan-
ning or otherwise, except as permitted under Sections 107 or
108 of the 1976 United States Copyright Act, without either
the prior written permission of the Publisher, or authoriza-
tion through payment of the appropriate per-copy fee to the
Copyright Clearance Center, 222 Rosewood Drive, Danvers,
MA 01923, (978) 750-8400, fax (978) 646-8600. Requests
to the Publisher for permission should be addressed to the
Permissions Department, John Wiley & Sons, Inc., 111 River
Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008,
or online at
/>Limit of Liability/Disclaimer of Warranty:  e publisher and
the author make no representations or warranties with respect
to the accuracy or completeness of the contents of this work and
speci cally disclaim all warranties, including without limitation
warranties of  tness for a particular purpose. No warranty may
be created or extended by sales or promotional materials.  e
advice and strategies contained herein may not be suitable for
every situation.  is work is sold with the understanding that
the publisher is not engaged in rendering legal, accounting, or

other professional services. If professional assistance is required,
the services of a competent professional person should be
sought. Neither the publisher nor the author shall be liable for
damages arising herefrom.  e fact that an organization or Web
site is referred to in this work as a citation and/or a potential
source of further information does not mean that the author or
the publisher endorses the information the organization or Web
site may provide or recommendations it may make. Further,
readers should be aware that Internet Web sites listed in this
work may have changed or disappeared between when this work
was written and when it is read.
For general information on our other products and services or
to obtain technical support, please contact our Customer Care
Department within the U.S. at (877) 762-2974, outside the U.S.
at (317) 572-3993 or fax (317) 572-4002.
Wiley also publishes its books in a variety of electronic formats.
Some content that appears in print may not be available in
electronic books.
Library of Congress Cataloging-in-Publication Data is available
from the publisher.
TRADEMARKS: Wiley, the Wiley logo, and the Sybex logo are
trademarks or registered trademarks of John Wiley & Sons, Inc.
and/or its a liates, in the United States and other countries,
and may not be used without written permission. Microso ,
Windows Server, and Windows PowerShell are trademarks
or registered trademarks of Microso Corporation. All other
trademarks are the property of their respective owners. Wiley
Publishing, Inc., is not associated with any product or vendor
mentioned in this book.
10 9 8 7 6 5 4 3 2 1

ffirs.indd ivffirs.indd iv 4/18/2011 3:07:34 PM4/18/2011 3:07:34 PM
Dear Reader,
 ank you for choosing Automating Windows Server 2008 R2 with Windows
PowerShell 2.0.  is book is part of a family of premium-quality Sybex books, all of
which are written by outstanding authors who combine practical experience with a
gi for teaching.
Sybex was founded in 1976. More than 30 years later, we’re still committed to
producing consistently exceptional books. With each of our titles, we’re working
hard to set a new standard for the industry. From the paper we print on, to the
authors we work with, our goal is to bring you the best books available.
I hope you see all that re ected in these pages. I’d be very interested to hear your
comments and get your feedback on how we’re doing. Feel free to let me know what
you think about this or any other Sybex book by sending me an email at
nedde@
wiley.com
. If you think you’ve found a technical error in this book, please visit

. Customer feedback is critical to our e orts at
Sybex.
Best regards,

Neil Edde
Vice President and Publisher
Sybex, an Imprint of Wiley
ffirs.indd vffirs.indd v 4/18/2011 3:07:34 PM4/18/2011 3:07:34 PM
To Deb, my strength and heart, thank you
so much for all of your unwavering love
and support. I would not be who I am today
without you. I love you.
To Nicole, Mitchell, and Caitlin, thank you for

teaching me the meaning of grace. I love you
all very much.
—Matt
To Kevin, my wonderful husband who
survived my talks about PowerShell from a
developer’s perspective while writing, o ered
suggestions when I needed another person’s
real-world IT perspective, and has been very
supportive of me through my “wrediting”
process.
—Sarah
ffirs.indd viffirs.indd vi 4/18/2011 3:07:35 PM4/18/2011 3:07:35 PM
ACKNOWLEDGMENTS
eing able to write this book has been a blessing, and I could not have done it without
a lot of top-notch help. First, I would like to thank my fabulous technical editor
and coauthor, Sarah, for going on this journey with me. Sarah, your knowledge and
insight are inspiring.  ank you for making sure this book is rock solid. Second, I
would like to thank Dick Margulis. Dick, you truly are an editor extraordinaire who
I have thoroughly enjoyed working with. I hope I did not drive you to nutty with all
of my “great new features.”  ank you, sir. Lastly, a huge thanks to Agatha Kim not
only for giving me my  rst opportunity to write a book but also for encouraging me
to write this book.  ank you so much for your guidance and support over the past
few years.
Matt
I would like to thank my IT friends for encouraging me and inspiring me as I
explored many of the topics in this book.  anks to Jay R. Wren, my tech editor
for the appendixes. As always, Jay made sure I didn’t stray technically and inspired
new changes.  anks to all of our editors at Sybex, and especially thanks to Dick
Margulis, our development editor, who shepherded us when we got carried away.
Most of all, I would like to thank my awesome coauthor and great friend, Matt

Hester, for the many commas and “great features” that I had to cut out while
tech editing, the laughs throughout the process, and the advice when it came to
writing the appendixes. Matt inspired me to create the term wrediting—writing
and editing, as I had originally been set as a tech editor for Chapters 1–12 and later
was added as a coauthor. It has been a great adventure, and I look forward to more
adventures with Matt!
Sarah
B

ffirs.indd viiffirs.indd vii 4/18/2011 3:07:35 PM4/18/2011 3:07:35 PM
ABOUT THE AUTHORS
Matt Hester is a seasoned Information Technology Professional Evangelist for
Microso . Matt has been involved in the IT Pro community for more than 15 years.
Matt is a skilled and experienced evangelist presenting to audiences nationally and
internationally. Prior to joining Microso , Matt was a highly successful Microso
Certi ed Trainer for more than eight years. A er joining Microso , Matt has con-
tinued to be heavily involved in IT Pro community as an IT Pro Evangelist. In his
role at Microso , Matt has presented to audiences in excess of 5,000 and as small
as 10. Matt has also written four articles for TechNet magazine, and his  rst book
was Microso Windows Server 2008 R2 Administration Instant Reference. Matt is a
movie bu with a massive DVD collection; he also runs marathons and dreams of
joining the PGA tour. Matt cites his father as his role model: “ e older I get, the
smarter he gets.” Funny how that works.
Sarah Dutkiewicz is a seasoned technology professional and has been working in a
variety of technologies for more than eight years. Sarah’s well-rounded background
includes roles in technical support, desktop support, database administrator, system
administrator, and professional developer. Sarah’s true passion comes from devel-
oping and writing code. Currently Sarah develops for a Cleveland, Ohio–based
company, focusing mostly on ASP.NET development and improving processes
using various .NET solutions. Sarah is currently a Microso MVP in Visual C#

and is deeply passionate about the technical community. Sarah’s many commu-
nity activities include blogging, running a technical community website, planning
events, and speaking at regional and national conferences.
ffirs.indd viiiffirs.indd viii 4/18/2011 3:07:35 PM4/18/2011 3:07:35 PM
CONTENTS AT A GLANCE
Introduction xv
Chapter 1 What Is PowerShell, and Why Do You Need It? 1
Chapter 2 Installing and Configuring PowerShell 2.0 19
Chapter 3 PowerShell Grammar Lesson 37
Chapter 4 Aliases, Functions, and the Pipe, Oh My! 65
Chapter 5 Creating Your Own Scripts 97
Chapter 6 Remoting with PowerShell 2.0 125
Chapter 7 Server Essentials in PowerShell 147
Chapter 8 Managing Active Directory with PowerShell 173
Chapter 9 Managing Desktops with PowerShell 197
Chapter 10 Managing IIS Web Server with PowerShell 223
Chapter 11 PowerShell and Deployment Services 243
Chapter 12 PowerShell and Virtualization 267
Appendix A Solutions to Exercises 289
Appendix B Developing at a Command Prompt 299
Appendix C Providing for PowerShell 311
Appendix D Custom Cmdlets and Advanced Functions 339
Appendix E Packaging PowerShell Extensions 357
Appendix F Building Your Own GUI with PowerShell 379
Index 399
ffirs.indd ixffirs.indd ix 4/18/2011 3:07:35 PM4/18/2011 3:07:35 PM
ffirs.indd xffirs.indd x 4/18/2011 3:07:35 PM4/18/2011 3:07:35 PM
TABLE OF CONTENTS
Introduction xvii
Chapter 1 What Is PowerShell, and Why Do You Need It? 1

Why PowerShell? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2
Overview of PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
The Power Behind PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5
What About the Learning Curve?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6
What’s New in PowerShell 2.0?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
PowerShell in the Enterprise. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8
PowerShell with a GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .10
PowerShell Has Something for Everyone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13
What’s in It for IT Professionals?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .14
What’s in It for Developers? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .15
Chapter 2 Installing and Configuring PowerShell 2.0 19
Configure PowerShell 2.0 on Windows Server 2008 R2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
Install the ISE on Windows Server 2008 R2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .22
Install PowerShell 2.0 on Windows Server 2008 R2 Core . . . . . . . . . . . . . . . . . . . . . . . . . . . . .24
Install .NET Framework Support on Windows Server 2008 R2 Core . . . . . . . . . . . . . . . .26
Install PowerShell 2.0 on Windows Server 2008 R2 Core . . . . . . . . . . . . . . . . . . . . . . . . . .26
Install PowerShell 2.0 on Other Operating Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29
Set Up the Prerequisites. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29
Obtain and Install PowerShell 2.0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31
Chapter 3 PowerShell Grammar Lesson 37
Break Down PowerShell: A Lesson on Cmdlets. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .38
Learn the Verbs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .39
Learn the Nouns. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .40
Put Verbs and Nouns Together: Cmdlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .41
Use Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .42
Use Wildcards. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .45
Understand Properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46
Help Yourself with PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48
Learn How to Help Yourself. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48
Use Tab Autocomplete . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .53

Leverage Online Resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .54
Use Even More Commands with Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .55
Use and Understand Modules. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .55
ftoc.indd xiftoc.indd xi 4/18/2011 3:09:23 PM4/18/2011 3:09:23 PM
XII TABLE OF CONTENTS
Get to Know Your Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .58
Create a Custom PowerShell Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .60
Chapter 4 Aliases, Functions, and the Pipe, Oh My! 65
Use Aliases. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .66
Use Built-in Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .67
Create Your Own Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .69
Use Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .77
Understand Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .78
Use Existing Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .79
Create Your Own Function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .80
Work with the Pipe Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .81
Use the Pipe Operator to Combine PowerShell Cmdlets . . . . . . . . . . . . . . . . . . . . . . . . . .81
Control PowerShell Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .82
Chapter 5 Creating Your Own Scripts 97
Create Your Own Scripts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .98
PowerShell Scripting Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .99
Create a PowerShell Script. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .100
Run Your Scripts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .106
Find Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107
Understand Security and PowerShell Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .108
Work with Default Execution Policy of Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .109
Understand the RemoteSigned PowerShell Execution Policy . . . . . . . . . . . . . . . . . . . . . 110
Set the PowerShell Execution Policy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Understand Digital Signing. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
Work with the GUI and the Shell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .116

Understand What the ISE Is. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .116
Use the ISE with Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .119
Display the Call Stack with Scripts Requiring Parameters . . . . . . . . . . . . . . . . . . . . . . . .123
Chapter 6 Remoting with PowerShell 2.0 125
Configure PowerShell Remoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .126
Learn the Requirements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .126
Enable PowerShell Remoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .128
Disable PowerShell Remoting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .133
Run Commands on Remote Systems. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .138
Use Invoke-Command . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .140
Use PowerShell Remote Sessions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .140
Use Remoting in the ISE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .143
Chapter 7 Server Essentials in PowerShell 147
Work with Your Server in PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .148
ftoc.indd xiiftoc.indd xii 4/18/2011 3:09:24 PM4/18/2011 3:09:24 PM
TABLE OF CONTENTS XIII
Work with Server Manager Cmdlets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .148
Analyze Your Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .150
Add Reliability to Your Server. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .156
Install the Backup Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .156
Perform a Backup with PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .156
Load-Balance Your Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .159
Use Other PowerShell Utilities for the Server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .163
Use the Registry with PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .163
Use PowerShell Troubleshooting Packs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .166
Schedule PowerShell Scripts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .169
Chapter 8 Managing Active Directory with PowerShell 173
Work with Active Directory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .174
Load the AD PowerShell Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Understand PowerShell Active Directory Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .178

Work with Users, Groups, and OUs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .182
Understand Managed Service Accounts. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .185
Understand Managed Service Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .185
Create Managed Service Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .186
Install and Use Managed Service Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .188
Work with the Active Directory Recycle Bin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .189
Understand How the Recycle Bin Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .190
Enable the AD Recycle Bin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .191
Use the AD Recycle Bin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .193
Chapter 9 Managing Desktops with PowerShell 197
Access Group Policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .198
Understand Group Policy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .199
Understand How Group Policy Works. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Manage Group Policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .201
Create Group Policy Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Use Starter GPOs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206
Work with Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Understand the Difference Between Policies and Preferences. . . . . . . . . . . . . . . . . . . 209
Work with Domain Password Policies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .210
Understand Order of Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .212
Control Group Policy Order of Precedence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .213
Work with RSOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .215
Back Up and Restore Group Policy Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .216
Manage AppLocker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .217
Understand AppLocker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .217
Understand AppLocker Policy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .218
Configure AppLocker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .219
ftoc.indd xiiiftoc.indd xiii 4/18/2011 3:09:24 PM4/18/2011 3:09:24 PM
XIV TABLE OF CONTENTS
Chapter 10 Managing IIS Web Server with PowerShell 223

Use PowerShell and IIS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .224
Work with Configuration Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 225
Back Up and Recover IIS Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 229
Deploy Websites, Application Pools, and Virtual Directories with PowerShell . . . . . . . . .231
Manage Sites with PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .231
Work with Web Application Pools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
Work with Virtual Directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .240
Chapter 11 PowerShell and Deployment Services 243
Work with Windows Deployment Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244
Understand WDS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .245
Install WDS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .246
Work with WDS in PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .247
Use WDSUTIL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .248
Work with the Microsoft Deployment Toolkit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .253
Understand the MDT. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .253
Deploy with Windows Imaging Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
Install MDT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 256
Work with MDT in PowerShell. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .257
Put It All Together . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .265
Chapter 12 PowerShell and Virtualization 267
Install and Access Hyper-V. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 268
Install Hyper-V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .269
Access Hyper-V in PowerShell. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .270
Work with Hyper-V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .276
Work with Virtual Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .276
Configure Virtual Machines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .278
Connect to Virtual Machines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .283
Work with Snapshots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .285
Appendix A Solutions to Exercises 289
Solution 1: Inventory Your Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290

Solution 2: Install PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Solution 3: Create a PowerShell Profile. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Solution 4: Create Your Own Alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .291
Solution 5: Create a Script to Find Startup Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .292
Solution 6: Set Up a Remote PowerShell Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .292
Solution 7: Create a Scheduled Backup with PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . .293
Solution 8: Populate an Active Directory Test Environment . . . . . . . . . . . . . . . . . . . . . . . . .293
Solution 9: Turn Off the Display Control Panel in Group Policy with PowerShell . . . . . . .295
Solution 10: Create a Website with PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
ftoc.indd xivftoc.indd xiv 4/18/2011 3:09:25 PM4/18/2011 3:09:25 PM
TABLE OF CONTENTS XV
Solution 11: Create a Deployment Share . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Solution 12: Create a Virtual Machine and Take a Snapshot . . . . . . . . . . . . . . . . . . . . . . . . .297
Appendix B Developing at a Command Prompt 299
Choose Between the ISE and the Command Prompt. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Write Code at a Command Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .301
Write Scripts in the ISE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .302
Work with Objects in PowerShell. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
Understand Properties. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .305
Create Your Own Custom Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .307
Appendix C Providing for PowerShell 311
Work with Built-in Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .312
Understand Provider Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .313
Use PowerShell-Specific Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .314
Use Other Built-in Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .317
Work with Additional Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .322
Install and Remove Providers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .322
Create Your Own Provider . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .323
Understand Basic Provider Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .323
Build a Custom Provider. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .327

Appendix D Custom Cmdlets and Advanced Functions 339
Choose Between an Advanced Function and a Cmdlet . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
Parameters and Attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 340
Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 346
Runtime Life Cycle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .347
Create an Advanced Function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348
Create a Custom Cmdlet. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .349
Appendix E Packaging PowerShell Extensions 357
Work with Existing Snap-ins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .358
Create a Custom Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .361
Understand Module Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .361
Build Your Module. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368
Appendix F Building Your Own GUI with PowerShell 379
Choose Between WinForms and WPF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 380
Create a GUI in PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .381
Create a WinForms Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .385
Create a WPF Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .391
Index 399
ftoc.indd xvftoc.indd xv 4/18/2011 3:09:25 PM4/18/2011 3:09:25 PM
flast.indd xviflast.indd xvi 4/18/2011 3:11:09 PM4/18/2011 3:11:09 PM
owerShell is a scripting language built into Windows Server 2008 R2 servers.
PowerShell is designed to help you perform routine and repetitive tasks in a script-
able fashion. PowerShell helps alleviate many of the time-consuming and tedious
tasks administrators have had to do in the past. You may have used various script-
ing technologies over the years to accomplish these tasks; however, in PowerShell
2.0, you have a better tool than you have ever had when working with Microso
environments. PowerShell 2.0 was launched with the release of Windows 7 and
Windows Server 2008 R2. You can now leverage tons of new built-in capabilities
to help make administering your server easier. It is quickly growing to become the
scripting tool of choice for Microso operating systems and applications. In many

cases, PowerShell has replaced former command prompt tools or has been incor-
porated into new tools. PowerShell provides a common language you can use to
manage any of your Microso infrastructure that supports PowerShell scripting.
Who Should Read This Book
 is book is for anyone who wants to learn more about PowerShell, from novices to
scripting a cionados. If you are looking to learn PowerShell for the  rst time or if
you are looking to learn how to manage Windows Server 2008 R2 with PowerShell,
then this book is for you. Whether you are an IT administrator, developer, scripta-
holic, or anyone else with an interest in PowerShell, you will  nd something in this
book to help you use PowerShell to save you time.  is book is designed to allow
you to use PowerShell to meet your everyday business needs.
What You Will Learn
In this book you will learn the foundation behind PowerShell and how to work with
this powerful scripting language.  is book covers four main things:
f
 e foundation of PowerShell from the smallest components to how to create
your own scripts and a lesson in syntax and grammar.  e foundation you
build here will enable you to work with PowerShell regardless of the operating
system or application.
INTRODUCTION
P

flast.indd xviiflast.indd xvii 4/18/2011 3:11:13 PM4/18/2011 3:11:13 PM
XVIII INTRODUCTION
f
How to practically apply PowerShell to your Windows Server 2008 R2 servers.
Topics include server essentials tasks such as backup to management of Active
Directory and many other Windows Server 2008 R2 server roles and features.
f
 e foundation of how to incorporate PowerShell into your application devel-

opment environment and how to take PowerShell to the next level.
f
 e new capabilities of PowerShell 2.0.  roughout the chapters in this book
you will see many of the new built-in capabilities of PowerShell 2.0, from
new commands in Active Directory management to new functions such as
remoting.
At the end of each chapter, you will get to practice what you have learned and try
PowerShell with exercises designed to reinforce what you saw in the chapter. Most
importantly, this book will jump-start your learning of PowerShell. Once you learn
the essentials provided in the book, you can apply your knowledge to leverage
PowerShell not only in Windows Server 2008 R2 but also in other Windows oper-
ating systems and applications such as Microso Exchange Server and Microso
SharePoint Server, as well as anywhere else you  nd PowerShell.
What Is Covered in This Book
Automating Microso Windows Server 2008 R2 with Windows PowerShell 2.0 is
organized to provide you with the knowledge to be successful with PowerShell.
Chapter 1: What Is PowerShell, and Why Do You Need It? talks about the
importance of learning PowerShell not only for IT professionals but also for
application developers. You will also see many of the new tools in PowerShell 2.0.
Chapter 2: Installing and Con guring PowerShell 2.0 focuses on installing
and con guring PowerShell 2.0, including other Microso operating systems
besides Windows Server 2008 R2 and Windows 7.
Chapter 3: PowerShell Grammar Lesson breaks down the PowerShell language
to its smallest parts.  is chapter provides the background to cmdlets and how
you can work with them.
Chapter 4: Aliases, Functions, and the Pipe, Oh My! shows how to create
shortcuts for your commands, called aliases. You will also learn the power of
functions, which give you the ability to create your own custom commands. You
will also see how to tie PowerShell commands together with the pipe (|).
flast.indd xviiiflast.indd xviii 4/18/2011 3:11:13 PM4/18/2011 3:11:13 PM

INTRODUCTION XIX
Chapter 5: Creating Your Own Scripts focuses on creating and writing your
own scripts by combining your PowerShell commands.
Chapter 6: Remoting with PowerShell 2.0 shows how to use the new PowerShell
2.0 capability of being able to create remoting sessions and run PowerShell com-
mands remotely.
Chapter 7: Server Essentials in PowerShell shows how to use PowerShell to per-
form daily server administrative tasks such as backing up your server as well as
unlocking other data stores directly with PowerShell.
Chapter 8: Managing Active Directory with PowerShell takes a look at the new
built-in commands for working with Active Directory with PowerShell.
Chapter 9: Managing Desktops with PowerShell shows how to manage your
desktops via Group Policy and how to manage Group Policy with PowerShell.
Chapter 10: Managing IIS Web Server with PowerShell discusses how
you can use PowerShell to manage your web servers in Internet Information
Services (IIS).
Chapter 11: PowerShell and Deployment Services shows how to work with
Windows Deployment Services (WDS) and the free Microso Deployment
Toolkit (MDT) to deploy operating systems for your organization.  e MDT has
native PowerShell support and allows you to build custom deployment images
for your environment.
Chapter 12: PowerShell and Virtualization gives you a brief tour of Hyper-V,
Microso ’s virtualization platform, and how you can manage it with PowerShell.
Appendix A: Solutions to Exercises gives the answers for the end-of-chapter
exercises.
Appendix B: Developing at a Command Prompt discusses choosing between
the Integrated Scripting Engine (ISE) and the command prompt and establishes
a foundation for working with objects in PowerShell.
Appendix C: Providing for PowerShell discusses the built-in providers and
provides a basic example for creating your own provider in PowerShell.

Appendix D: Custom Cmdlets and Functions discusses how to create your own
cmdlets and functions, allowing you to extend PowerShell to meet your needs.
Appendix E: Packaging PowerShell Extensions discusses how to work with
modules and how to create your own custom module.
flast.indd xixflast.indd xix 4/18/2011 3:11:13 PM4/18/2011 3:11:13 PM
XX INTRODUCTION
Appendix F: Building Your Own GUI with PowerShell discusses the options
for creating a graphical user interface (GUI) from scratch in PowerShell and
shows examples for getting started in creating a GUI.
How to Contact the Author
We welcome feedback from you about this book or about books you’d like to see
from us in the future. You can reach us by writing to Matt at


or Sarah at

or by contacting us on our blogs at
http://
blogs.technet.com/matthewms
or

. You can
also follow Sarah on Twitter as
@sadukie
.
For more information about our work, please visit our websites at
http://blogs
.technet.com/matthewms
and


.
Sybex strives to keep you supplied with the latest tools and information you need for
your work. Please check its website at
www.sybex.com
, where we’ll post additional
content and updates that supplement this book if the need arises. Enter Automating
Microso Windows Server 2008 R2 with Windows PowerShell 2.0 in the Search
box (or type the book’s ISBN—9781118013861), and click Go to get to the book’s
update page.
flast.indd xxflast.indd xx 4/18/2011 3:11:13 PM4/18/2011 3:11:13 PM
CHAPTER 1
What Is PowerShell,
and Why Do You Need It?
HERE ARE THE TOPICS COVERED IN THIS
CHAPTER:
X
WHY POWERSHELL? 2
Overview of PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3
The Power Behind PowerShell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5
What About the Learning Curve? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6
X
WHAT’S NEW IN POWERSHELL 2.0? 7
PowerShell in the Enterprise. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8
PowerShell with a GUI. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
X
POWERSHELL HAS SOMETHING FOR EVERYONE 13
What’s in It for IT Professionals?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
What’s in It for Developers?. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
c01.indd 1c01.indd 1 4/21/2011 12:59:29 PM4/21/2011 12:59:29 PM
CHAPTER 1

I

T professionals have been looking for ways to automate and perform tasks in a
consistent manner for years.  ere have been many techniques and technologies —
from simple batch  les to third-party tools — to accomplish the tasks. Some IT
professionals have gone the extra step and learned developer languages, such as
Visual Basic or JavaScript, to give their scripts more power.
A majority of these tools were not integrated into the Microso environment. More
importantly, the documentation for these tools to accomplish common administra-
tive tasks was not readily available. As part of its e ort over the years to improve the
scripting environment, Microso developed PowerShell to overcome the challenges
of previous scripting languages.
PowerShell provides a common language you can use throughout your Microso
infrastructure. You will spend less time on manual repetitive tasks by scripting
these tasks with PowerShell. PowerShell is used in a number of scenarios, including
system administration and so ware development. PowerShell is ideal for remote
management, reporting, automation, and administration.
 is book focuses on learning this powerful scripting language with real-world
examples and ways to perform common, everyday tasks. Tasks such as backing up
servers, maintaining web servers, analyzing your environment, and many more can
bene t from PowerShell. Step-by-step instructions in the chapters that follow show
you how you can make PowerShell work for you.
 e book is divided into two sections. In the  rst few chapters, you will build the
foundation of your PowerShell knowledge. You will learn the basics of a building
block known as a cmdlet (pronounced “command-let”) and how to read script.  e
second section of the book focuses on administrative tasks you can perform in
Windows Server 2008 R2. Although the book is geared to working on a Windows
Server 2008 R2 setup, the foundational knowledge provided in the book allows you
to leverage PowerShell regardless of the target Windows operating system.  e goal
is to demystify PowerShell for you so you can use it in your day-to-day tasks.

 is chapter gives an overview of PowerShell and why it is important.
Why PowerShell?
If you have been working in a Microso environment for the past few years, you
may have seen or heard about PowerShell. You may even remember its original code
name, Monad. It may have been discounted as “yet another scripting language” and
put aside to look at later. You may have even thought, why reinvent the wheel?
c01.indd 2c01.indd 2 4/21/2011 12:59:34 PM4/21/2011 12:59:34 PM
WHY POWERSHELL? 3
What Is PowerShell, and
Why Do You Need It?
CHAPTER 1
In other words, your environment was running smoothly, you were busy, and you
had no time to learn the language. You may have decided to wait to see whether
there would be a version 2 and whether Microso was really serious about this
language. Well, here we are with version 2, and PowerShell is getting better than
ever. Microso and communities such as
/>
are creating native PowerShell commands and providers as well as the documenta-
tion for scripts to make your everyday work with PowerShell even easier. So, you are
not in this alone.  e community is growing and vibrant!
 e initial project Monad debuted in June 2005. In April 2006, Microso announced
that Monad’s name would be PowerShell, and PowerShell Release Candidate 1 was
released. PowerShell 1.0 was released in November 2006. It was well received in the
community, and with its integration into the Windows environment, this became a
new language for administrators to work with. In 2009, version 2 of PowerShell was
released and built into Windows 7 and Windows Server 2008 R2. PowerShell 2.0 is
also available for free download for systems newer than Windows XP SP3. Chapter 2
discusses how to install the tools on older, supported operating systems.
Overview of PowerShell
What is PowerShell?


PowerShell is an extensible automation engine from Microso .

PowerShell is a command-line shell and task-based scripting technology that
provides you with enhanced remote management and automation of system
administration tasks.
PowerShell can look like Figure 1.1, and it can look like Figure 1.2.
What can it do?
PowerShell enables you to perform via scripts virtually any task you can do in the
GUI for your local or remote Windows operating systems and your computers. With
PowerShell, you can script and automate your day-to-day administrative tasks.

Do you need to get a list of all the computers on the network and create a
report on the service pack level for each operating system?

Do you need to check to make sure that all the users in the domain are
complying with the corporate password policy?

Do you need to start a service on 500 computers?

Do you need to add 100 user accounts to your domain?
c01.indd 3c01.indd 3 4/21/2011 12:59:34 PM4/21/2011 12:59:34 PM

×