PowerShell and WMI
Richard Siddaway
Foreword by Ed Wilson
  • April 2012
  • ISBN 9781617290114
  • 552 pages
  • printed in black & white

PowerShell, WMI, and Richard Siddaway--an unbeatable combination.

From the Foreword by Ed Wilson, Microsoft Scripting Guy

PowerShell and WMI is an example-driven guide for administrators managing networks of Windows servers and desktops. With 150 practical examples, including ready-to-reuse scripts and techniques, you'll learn the ins and outs of automating WMI via PowerShell v3. You'll find deep coverage of all aspects of Windows administration, including IIS, DNS and Hyper-V.

Table of Contents show full




about this book

about the author

about the cover illustration

Part 1 Tools of the trade

1. Solving administrative challenges

1.1. Administrative challenges

1.2. Automation: the way forward

1.3. PowerShell overview

1.4. WMI overview

1.5. Automation with WMI and PowerShell

1.6. Putting PowerShell and WMI to work

1.7. Summary

2. Using PowerShell

2.1. PowerShell in a nutshell

2.2. Cmdlets

2.3. Pipeline

2.4. .NET for administrators

2.5. PowerShell scripting language

2.6. Finding help

2.7. Code reuse

2.8. PowerShell remoting

2.9. PowerShell jobs

2.10. Summary

3. WMI in depth

3.1. The structure of WMI

3.2. Methods and properties

3.3. Documenting WMI

3.4. WMI cmdlets and accelerators

3.5. Using WQL

3.6. WMI references and associators

3.7. WMI events

3.8. Summary

4. Best practices and optimization

4.1. Security

4.2. Optimizing PowerShell code

4.3. Calculated fields, types, and formatting

4.4. Debugging and error handling

4.5. Getting the most from WMI

4.6. Summary

Part 2 WMI in the enterprise

5. System documentation

5.1. System hardware and configuration

Technique 1 Get computer system information

Technique 2 Get computer type

Technique 3 Get domain role

Technique 4 Get processor information

Technique 5 Get BIOS information

Technique 6 Get memory configuration

5.2. Peripherals

Technique 7 Get display settings

Technique 8 Get input devices

Technique 9 Get ports

5.3. Power supplies

Technique 10 Get battery details

Technique 11 Get battery status

Technique 12 Test power source

Technique 13 Get power plans

5.4. Operating system

Technique 14 Get operating system version

Technique 15 Discover hotfixes

Technique 16 Get boot configuration

Technique 17 Find recovery configuration

Technique 18 Test system time

5.5. Software

Technique 19 Discover installed software

5.6. Summary

6. Disk systems

6.1. Physical disks

Technique 20 Discover disk controllers

Technique 21 Physical drive information

Technique 23 Enumerating disk partitions

6.2. Logical disks

Technique 25 Logical disk information

Technique 26 Root directory data

Technique 27 Mount points

6.3. Volumes

Technique 28 Enumerate volume information

Technique 29 Using volume change events

6.4. Managing disks

Technique 30 Formatting a disk

Technique 31 Performing Chkdsk

Technique 32 Analyzing and removing fragmentation

6.5. CD drives

Technique 33 Enumerating CD drives

6.6. Summary

7. Registry administration

7.1. Accessing the registry

Technique 34 Test registry size

Technique 35 Discovering registry data types

7.2. Reading the registry

Technique 36 Reading registry keys

Technique 37 Reading registry values

Technique 38 Enumerating keys and values

7.3. Creating and modifying registry keys and values

Technique 39 Creating registry keys

Technique 40 Setting registry values

7.4. Deleting registry keys

Technique 41 Deleting registry values

Technique 42 Deleting registry keys

7.5. Registry access rights

Technique 43 Reading access rights

Technique 44 Taking ownership of a registry key

7.6. Registry events

Technique 45 Monitoring registry events

7.7. Summary

8. Filesystem administration

8.1. Working with files

Technique 46 Finding files

Technique 47 Performing actions on files

Technique 48 Compressing files

8.2. Folder administration

Technique 49 Discovering the files in a folder

Technique 50 Discovering folders with specific attributes

Technique 51 Decoding the access mask

8.3. Listing, creating, and modifying shares

Technique 52 Listing shares

Technique 53 Creating shares

Technique 54 Modifying shares

8.4. Filesystem events

Technique 55 Working with filesystem events

8.5. Page file management

8.6. Summary

9. Services and processes

9.1. Services

Technique 56 Listing services

Technique 57 Configuring services

Technique 58 Discovering the service load order

9.2. Processes

Technique 59 Listing process owners

Technique 60 Creating a process

Technique 61 Terminating a process

Technique 62 Investigating an event

Technique 63 Monitoring processes

9.4. Summary

10. Printers

10.1. Printer configuration

Technique 64 Discovering printers

Technique 65 Testing printer capabilities

Technique 66 Discovering printer ports

Technique 67 Discovering printer drivers

10.2. Printer status

Technique 68 Testing printer status

Technique 69 Listing print jobs

10.3. Managing printers

Technique 70 Setting a default printer

Technique 71 Printing a test page

Technique 72 Controlling printers

Technique 73 Renaming a printer

10.4. Summary

11. Configuring network adapters

11.1. Discovering network adapters

Technique 74 Identifying network adapters

Technique 75 Discovering adapter configurations

Technique 76 Listing an adapter’s network protocols

Technique 77 Listing network connections

11.2. Configuring network adapters

Technique 78 Enabling network adapters

Technique 79 Disabling network adapters

Technique 80 Renaming network adapters

11.3. Enabling and setting network addresses

Technique 81 Enabling DHCP

Technique 82 Displaying DHCP configuration

Technique 83 Controlling DHCP leases

Technique 84 Setting an IP address

Technique 85 Setting other properties

11.4. Configuring network services

Technique 86 Setting DNS servers

Technique 87 Setting WINS servers

Technique 88 Displaying the routing table

11.5. Summary

12. Managing IIS

12.1. IIS WMI provider

Technique 89 Displaying web server defaults

Technique 90 Restarting the web server

12.2. Websites

Technique 91 Listing websites

Technique 92 Creating a website

Technique 93 Testing website status

Technique 94 Restarting a website

12.3. Application pools and applications

Technique 95 Listing web applications

Technique 96 Listing application pools

Technique 97 Recycling an application pool

12.4. Summary

13. Configuring a server

13.1. Initial tasks

Technique 98 Renaming a server

Technique 99 Joining a computer to a domain

13.2. Controlling server restarts

Technique 100 Shutting down a server

Technique 101 Restarting a server

13.3. Configuring network adapter settings

Technique 102 Setting an IP address

Technique 103 Configuring other settings

13.4. Activating a server

Technique 104 Testing license state

Technique 105 Setting the license key

Technique 106 Activating a server

Technique 107 Setting a power plan

13.5. Summary

14. Users and security

14.1. User accounts on the local system

Technique 108 Listing user accounts

Technique 109 Finding logged on users

Technique 110 Discovering user information

14.2. Groups on the local system

Technique 111 Listing local groups

Technique 112 Listing group membership

14.3. Security

Technique 113 Testing antivirus status

Technique 114 Testing antispyware status

Technique 115 Testing antimalware status

Technique 116 Testing firewall status

Technique 117 Listing firewall settings

14.4. Summary

15. Logs, jobs, and performance

15.1. Event logs

Technique 118 Discovering event log sources

Technique 119 Backing up event logs

15.2. Scheduled jobs

Technique 120 Creating a scheduled job

Technique 121 Discovering scheduled jobs

Technique 122 Deleting scheduled jobs

15.3. System performance

Technique 123 Reading performance counters

Technique 124 Windows system assessment report

Technique 125 Stability index data

15.4. Summary

16. Administering Hyper-V with PowerShell and WMI

16.1. Creating and configuring virtual machines

Technique 126 Creating a virtual machine

Technique 127 Adding extra CPUs

Technique 128 Attaching an .iso image to a DVD drive

Technique 129 Adding a virtual disk

Technique 130 Adding a network adapter

16.2. Controlling virtual machines

Technique 131 Starting a virtual machine

Technique 132 Starting multiple machines

Technique 133 Stopping virtual machines

16.3. Managing virtual disks

Technique 134 Testing virtual disk status

Technique 135 Examining virtual disk usage

Technique 136 Compacting virtual disks

16.4. Summary

Part 3 The future: PowerShell v3 and WMI

17. WMI over WSMAN

17.1. Remoting protocols

17.2. Using WSMAN

Technique 137 Testing WSMAN

Technique 138 Retrieving WMI data using WSMAN

Technique 139 Modifying WMI instances through WSMAN

Technique 140 Deleting WMI instances through WSMAN

17.3. Using CredSSP to access remote machines

17.4. How to choose between WMI, remoting, and WSMAN

17.5. Summary

18. Your own WMI cmdlets

18.1. Creating a WMI cmdlet

Technique 141 Creating a simple cmdlet

Technique 142 Extending the cmdlet

18.2. Creating multiple cmdlets

Technique 143 Creating cmdlets from multiple WMI classes

Technique 144 Building a super- module

18.3. Creating format and type files

Technique 145 Adding a format file

Technique 146 Adding a type file

18.4. Using the CIM IDE

18.5. Summary

19. CIM cmdlets and sessions

19.1. Using WMI methods

Technique 147 Adding a method

Technique 148 Adding a method that uses parameters

19.2. CIM cmdlets

19.3. CIM sessions

Technique 149 Creating a CIM session

Technique 150 Accessing CIM sessions

19.4. Summary

afterword This is not the end

Appendix A: PowerShell reference

Appendix B: WMI reference

Appendix C: Best practices


About the Technology

WMI, on its own, is simply a collection of Windows management facilities. Paired with PowerShell, however, WMI becomes a brilliant toolset for automating servers, networks, and remote Windows computers.

About the book

PowerShell and WMI is an industrial-strength guide for administrators of Windows networks, servers, and desktops. You'll start with practical overviews of PowerShell and of WMI. Then you'll explore 150 specific examples — all with ready-to-use scripts — designed to simplify your day-to-day system management. Each tested technique is configured to load as part of a PowerShell module.

A set of handy appendixes includes references for PowerShell and WMI.

What's inside

  • Managing Windows, IIS, and Hyper-V
  • Remote desktops and devices
  • Logs, jobs, and performance
  • New PowerShell v3 WMI functionality

About the reader

Prior exposure to PowerShell and WMI is helpful but not required.

About the author

Richard Siddaway is a veteran IT architect, server administrator, support engineer, and PowerShell MVP. He's the author of PowerShell in Practice, published in 2010 by Manning.

combo $59.99 pBook + eBook
eBook $47.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks

The definitive dive into using WMI with PowerShell.

Adam Bell, ZOE Systems Pty Ltd

Belongs on the desk of every Windows administrator and engineer.

James Berkenbile, Berkenbile Consulting

A great resource

Jonathan Medd, Get-Scripting Podcast