PowerShell and WMI
Richard Siddaway & Foreword by Ed Wilson
Copyright
For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact
Special Sales Department Manning Publications Co. 20 Baldwin Road PO Box 261 Shelter Island, NY 11964 Email:
orders@manning.com2012 by Manning Publications Co. All rights reserved.
No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps.
| Recognizing the importance of preserving what has been written, it is Mannings policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. |
| Manning Publications Co.20 Baldwin RoadPO Box 261Shelter Island, NY 11964 | Development editor: Jeff BleielTechnical proofreaders: Aleksandar NikolicCopyeditor: Andy CarrollProofreader: Melody DolabTypesetter: Gordan SalinovicCover designer: Marija Tudor |
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 MAL 17 16 15 14 13 12
Dedication
To my parents, June and RonWithout your help, support, and encouragementId never have been able to do this
Brief Table of Contents
Table of Contents
Foreword
I am glad that Richard Siddaway decided to sit down and write a book on WMI. I have had the privilege of working with Richard over the last several years since becoming the Microsoft Scripting Guy, and I have long been impressed by his technical prowess. Whether Richard is speaking at a user group or conference or writing a blog article, it does not take long before the topic of WMI crops up. When I am planning a guest series of articles for the Hey Scripting Guy! Blog, Richard is the first person I turn to if the subject is WMI. In short, Richard is the perfect person to write this book.
The book is not just about WMI. Richard begins with an overview of Windows PowerShell technology. In fact, the Using PowerShell chapter is an excellent overview of Windows PowerShell. In less than 40 pages he hits all the highlightsfunctions, modules, PSDrives, aliases, remoting, and jobs. But it is not simply a fly-by at 30,000 feet; he gets down to the nitty-gritty, boils down essential information, and surfaces a number of potential gotchas. Even if you already know Windows PowerShell, this chapter is worth a look; if you dont know Windows PowerShell, you should read this chapter a couple of times so you dont have problems with the remainder of the book.
WMI can be complicatedI know, I wrote a book on the subject for Microsoft Press a few years ago. Luckily, Richard has devoted an entire chapter to discussing not only the basics of WMI, but some of the more advanced concepts as well. I love his WMI documentation script in . Of course, one of the nice things about WMI is that it is self-describing, which means that it is possible to write scripts to discover information about WMI. Well, now you do not need to write those scripts yourself, because Richard has done it for you.
But if the book were all esoteric academic minutiae, it would be of limited practical value to network administrators and to consultants in the field who are attempting to use this rather difficult technology to solve real world problems. Luckily, Richard lives in the real world and his book quickly begins to produce real value. His section on WMI in the enterprise covers system documentation, working with disk subsystems, the registry, and more.
Windows PowerShell is a powerful, cool technology. WMI is a powerful, cool technology. When you combine the two you have a flexible and powerful solution. When Richard Siddaway is the author of the bookyou have an unbeatable combination. Buy this book! You will thank me later.
ED WILSON, MCSE, MCSD
MICROSOFT SCRIPTING GUY
AUTHOR OF
WINDOWS POWERSHELL 2.0 BEST PRACTICES
Preface
I am very passionate about using PowerShell to automate the administration of Windows systems. This will become apparent very quickly if you talk to me, listen to me at conferences, or read my other books or blogs. WMI has a reputation for being powerful but hard to use. PowerShell is the way forward for system administrators, and WMI is that horrible, old technology that no one really knows how to use. So why do we need a book on PowerShell and WMI?
In reality, PowerShell and WMI are made for each other. They are both powerful, but put them together and you have low-level access to just about every facet of your Windows system. WMI is a first-class citizen in the PowerShell world, with a set of cmd-lets to make using WMI easier and to provide the ability to work over WSMAN or DCOM protocols. The great strength of the pairing of PowerShell and WMI is that you can work with both local and remote systems. The other point to remember is that Microsoft is putting a lot of effort into WMI for the Windows 8 family of products. There are big changes coming regarding what you can do with WMI and how you can use it.
In short, it seemed that now was the time to bring WMI in from the cold and into mainstream administration where it belongs.
This book is written for system administrators, and it provides a suite of scripts to automate a large range of administration tasks. In most cases, these scripts are ready to use in your environmentI use many of them on a regular basis. In the chapters, those scripts are explained and the background to the tasks is discussed so you can put the script into context for your environment. This isnt a cookbook or a theoretical book on the PowerShell languageits more. Its a practical guide to taking these two technologies and making them do what you need in order to solve the problems you have in your environment.
Best practices can be an emotive subject, but one of my goals in writing the book has been to supply best practice guidelines for using PowerShell and WMI and Windows administration in general. There is no point in automating bad practiceit just makes mistakes happen quicker.
The solutions presented in the book show the way that I solve various problems. Use the scripts to solve your problems, and if you find better solutions, please share them with the PowerShell community.
Ive gained a number of things during the writing of this book:
- A deeper understanding of PowerShell and WMI
- Some wonderful opportunities to talk with very knowledgeable people
- New friends who share my interest in and passion for PowerShell and WMI
I hope you get a sense of that passion and interest from reading this book, and I hope that it both helps you in your role as an administrator and inspires you to investigate some of the areas of PowerShell and WMI that I havent been able to cover. Who knows, we could be talking about it at a PowerShell Deep Dive sometime soon.