21

Click here to load reader

[Webinar] PowerShell series part 3 – PowerShell and WMI

Embed Size (px)

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

Citation preview

Page 1: [Webinar] PowerShell series part 3 – PowerShell and WMI

POWERSHELL AND WMI

Discovering your environment – in a meaningful way

Kevin Sullivan – Specops Software

Darren Mar-Elia –SDM Software

Page 2: [Webinar] PowerShell series part 3 – PowerShell and WMI

Welcome

• Kevin Sullivan

[email protected]

– @kevsully67

• Director of Sales Engineering

• Recovering GP MVP, Musician

• Previously Principal Program Manager at Microsoft

• Technology lover – geek dad

WHOAMI

Page 3: [Webinar] PowerShell series part 3 – PowerShell and WMI

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

Page 4: [Webinar] PowerShell series part 3 – PowerShell and WMI

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

Page 5: [Webinar] PowerShell series part 3 – PowerShell and WMI

Stream of Consciousness

LET IT FLOW

Page 6: [Webinar] PowerShell series part 3 – PowerShell and WMI

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

Page 7: [Webinar] PowerShell series part 3 – PowerShell and WMI

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)

Page 8: [Webinar] PowerShell series part 3 – PowerShell and WMI

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’

Page 9: [Webinar] PowerShell series part 3 – PowerShell and WMI

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

Page 10: [Webinar] PowerShell series part 3 – PowerShell and WMI

FORMATTING OUTPUT

Page 11: [Webinar] PowerShell series part 3 – PowerShell and WMI

Exploring Objects

• Get-Member

– MemberType

– Properties

– Methods

WHAT IS IN THE OBJECT

Page 12: [Webinar] PowerShell series part 3 – PowerShell and WMI

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

Page 13: [Webinar] PowerShell series part 3 – PowerShell and WMI

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

Page 14: [Webinar] PowerShell series part 3 – PowerShell and WMI

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

Page 15: [Webinar] PowerShell series part 3 – PowerShell and WMI

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

Page 16: [Webinar] PowerShell series part 3 – PowerShell and WMI

Format-Wide

• Quick results

• Easy to read on the screen

• Great when digging in deeper… Progressive exploration

Page 17: [Webinar] PowerShell series part 3 – PowerShell and WMI

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

Page 18: [Webinar] PowerShell series part 3 – PowerShell and WMI

Default Formats

• $pshome

– Ps1xml files – defining default output

– Open in notepad to explore contents –BE CAREFUL

• Object types

• Get-EventLog –LogName Applcation | Get-Member

Page 19: [Webinar] PowerShell series part 3 – PowerShell and WMI

Wrap-up

• Questions

• Next month?

• Send feedback

[email protected]

WHAT DOES THE FUTURE BRING?

Page 20: [Webinar] PowerShell series part 3 – PowerShell and WMI

Resources• Http://www.SpecopsSoft.com

• Http://success.SpecopsSoft.com

• Http://sdmsoftware.com

LOTS OF RESOURCES

Page 21: [Webinar] PowerShell series part 3 – PowerShell and WMI

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