[Webinar] PowerShell series part 3 – PowerShell and WMI

Post on 07-Jul-2015

177 views 5 download

description

PowerShell and Windows Management Instrumentation (WMI) are both great on their own but when you combine these two tools, you have an even more flexible and powerful solution. In part 3 of this PowerShell series, we will show you how to use and leverage WMI with Windows PowerShell

transcript

POWERSHELL AND WMI

Discovering your environment – in a meaningful way

Kevin Sullivan – Specops Software

Darren Mar-Elia –SDM Software

Welcome

• Kevin Sullivan

– kevin.Sullivan@specopssoft.com

– @kevsully67

• Director of Sales Engineering

• Recovering GP MVP, Musician

• Previously Principal Program Manager at Microsoft

• Technology lover – geek dad

WHOAMI

Darren Mar-Elia

• 30 years of experience in enterprise IT and software

• Founder, in 2006, of Group Policy solutions company SDM Software, Inc. (www.sdmsoftware.com)– Wrote the first PowerShell cmdlets for Group Policy!

• Microsoft Group Policy MVP for the last 11 years

• Contributing Editor to Windows IT Pro Magazine since 1997

• Founder of GPOGUY.COM—a Group Policy resource site

3

SDM Software

• Founded in 2006, by Darren Mar-Elia—Group Policy MVP with 30 years experience in IT & Enterprise Software

• Provides Group Policy Reporting, Auditing and Compliance solutions to over 300 customers worldwide

• Freeware tools for Group Policy management to 1000s of users

• WWW.GPOGUY.COM resource site for GP technical questions (GPTalk Forum)

WWW.SDMSOFTWARE.COM

Stream of Consciousness

LET IT FLOW

What is Windows Management

Instrumentation (WMI)?

• Based on the DMTF Common Information Model (CIM) standard

– Industry-standard for describing systems and their components

• WMI is the CIM implementation for Windows

• But, lots of CIM implementations on other platforms

– Linux, network devices, etc.

• See Open Management Instrumentation (OMI)—Microsoft’s open source CIM framework

What is WMI For?

• Provides a standard mechanism for describing Windows system configuration

– And allow some manipulation of it

• Provides the basis for Desired State Configuration (DSC) in PowerShell v4+

• Accessible remotely via DCOM (old way) or WinRM(WS-Management implementation)

How WMI Works

• Creates a hierarchy of System Configuration “stuff”

– Namespaces

• Classes

– Properties

– Methods

• Configuration elements are instances of classes

– e.g. the “Spooler” service is an instance of the Win32_Service class

– Instances have properties (e.g. State property equals ‘Running’) and Methods (Stop() method to stop the service)

• You can query instances using WMI Query Language (WQL)

– Select * from Win32_Service Where Name = ‘spooler’

PowerShell & WMI

• Microsoft started by providing a single cmdlet to get access to WMI instances on local or remote systems:

– Get-WMIObject

• In PowerShell v4, introduced the “CIM Cmdlets”

– Think a more raw (and flexible) way of getting to WMI data (e.g.)

– Get-CIMInstance

– Invoke-CIMMethod

FORMATTING OUTPUT

Exploring Objects

• Get-Member

– MemberType

– Properties

– Methods

WHAT IS IN THE OBJECT

Format Right

• Guidance received from the experts

– Don Jones & Jeffrey Hicks

– PowerShell in a Month Of Lunches

• Get this book

• And PS Toolmaking in a Month of Lunches

• Figure out everything first

– What data/objects do you want to retrieve

– Sort/organize/filter/query etc…

– Perfume the Pig! (Format)

THE SUPER BASIC

Select-Object / Where-Object

• Cmdlets return object(s)

– Could be many

• Need to filter down to something manageable or useable

• Need to Organize output to make results easier to parse

Format-Table

• FT– Don’t use alias’ if you are sharing!

• Default Views– Dir $pshome

– Look for ps1xml files

– Define default output for cmdlets

• Creating Custom views– Out-of-Scope (but pretty cool)

– http://msdn.microsoft.com/en-us/library/gg580944(v=vs.85).aspx

Format-List

• FL

– Don’t use Alias’ if you are sharing!

• If the default output of an object is more than six columns it will default to a list

• Properties shown in a stack

• Great for looking at details as you figure out what to do

Format-Wide

• Quick results

• Easy to read on the screen

• Great when digging in deeper… Progressive exploration

Out-GridView

• As we say in Boston

– Wicked Pissah!

• Sort

• Manipulate

• Quick

• Export-CSV open in Excel

– Better, but more steps and not as quick

– For saving and sharing long term… Export and Excel is way better

Default Formats

• $pshome

– Ps1xml files – defining default output

– Open in notepad to explore contents –BE CAREFUL

• Object types

• Get-EventLog –LogName Applcation | Get-Member

Wrap-up

• Questions

• Next month?

• Send feedback

• kevin.sullivan@specopssoft.com

WHAT DOES THE FUTURE BRING?

Resources• Http://www.SpecopsSoft.com

• Http://success.SpecopsSoft.com

• Http://sdmsoftware.com

LOTS OF RESOURCES

Resources• http://www.powershellpro.com

– Some great tutorials

• http://powershell.org

• http://technet.Microsoft.com/scriptcenter

– Repository!

• http://jdhitsolutions.com/blog

– Jeff Hicks

• PowerShell help system!

• http://www.specopssoft.com

• http://success.specopssoft.com

LOTS OF RESOURCES