2. Inventory Your Network and Clientswith Windows PowerShell Don Jones Senior Partner and Technologist Concentrated Technology, LLC Required Slide SESSION CODE: WCL308
4. Introductions Me: Don Jones, Concentrated Technology Microsoft MVP Award recipient Contributing Editor, TechNet Magazine Author of 45+ IT books Blogger at http://ConcentratedTech.com You: A Busy Windows Administrator Needing to inventory management information from one or more remote computers, both server and client (but especially client)
5. Agenda Windows PowerShell, Briefly Windows Management Instrumentation, Briefly Exploring WMI Playing with WMI on Your Local Computer Using WMI on Remote Computers Making a Flexible WMI Tool in Steps
6. Windows PowerShell, Briefly This session’s code will work with v1 and v2 (up until “advanced functions” at the very end – that’s v2 only) V1: Ships with Win2008 and Vista, available for WinXP and Win2003 V2: Ships with Win2008R2 and Win7, available for WinXP, Win2003, Vista, and Win2008 Primarily a command-line shell; has scripting capabilities, but we won’t be diving into them (much) – we’ll be using scripts as “batch files” mainly Note: I make all scripts downloadable from my Web site, no need to take notes
7. Security Notes Windows PowerShell disables script execution (but not commands) by default; see Help about_execution* for details Windows PowerShell is subject to User Account Control (UAC); for our purposes, ensure you explicitly run “as Administrator” for necessary remote privileges
8. WMI, Briefly Present since Windows NT 4.0 Does not require PowerShell on the remote computer Uses Remote Procedure Calls (RPCs) for communication; does not require PowerShell v2 / WinRM “remoting” on remote machines Organized into: Namespaces: Top-level, strictly organizational, usually product-related Classes: Represent potential manageable elements Instances: Real-world occurrences of classes Properties & Methods: Elements of an instance Properties contain management information Methods perform actions (such as reconfiguration)
9. WMI Security Configured (by default) on the root namespace Typically, don’t mess with this – many things rely on WMI and can get angry if you fuss with the permissions Use WMI Control MMC snap-in to modify (or view – great way for seeing what namespaces are installed)
11. Differences from Machine to Machine WMI namespaces will vary based on the roles/products/technologies installed on a computer Individual classes will vary based on product or Windows version Classes’ properties and methods can vary from version to version, too Core Windows OS and hardware stuff is in ootIMv2; most classes start with Win32_ or CIM_ prefix in the class name Best to get a “WMI Explorer” or “WMI Browser” that can be focused at a remote computer to see what that computer has You don’t need a class on your computer in order to query it from a remote computer (very handy)
12. Documentation Easiest: Plug class name into favorite search engine First 1-2 results usually msdn.microsoft.com/…, which will be what you want Only rely on “core” classes being well-documented – everything else is pretty inconsistently documented Use search engines to find examples – even VBScript examples can usually provide some help Pipe retrieved WMI objects to Get-Member or to Format-List * in order to see what properties/methods they have, and what values the properties contain
14. Using PowerShell Locally Use Get-WmiObjectcmdlet Cannot specify alternate credentials for local connections (by design); make sure shell is running as Administrator Specify –class name to query; retrieves all instances and all properties by default
15. Filtering Results Use –filter parameter to narrow down instances returned (large result sets can take a lot of time and resources) -filter "property <comparison> value” Numeric values are not delimited String/date values are delimited in single quotes Easiest to enclose the entire filter in double quotes Valid comparison operators: = > < <> <= => LIKE (use % as a wildcard) These are different from PowerShell’s native operators!
17. Going Remote Use –computerName parameter to specify remote computer(s) -computername ”Client17” -computername (get-content names.txt) -computername “client17”,”client18”,”client19” Other parameters allow specification of alternate credential -credential CONTOSOdministrator Graphically prompts for password – by design Use Get-Credentialto create a reusable credential object that contains a password
18. Multiple Computers Remote connections are synchronous and sequential (not parallel) Use –AsJob to run in background Use remoting (Invoke-Command) for parallel processing (not in this session) Failure of one computer will not stop the command from continuing You can trap errors and log them; we’ll see how later
20. The Steps Move command into a “batch file” for easier repetition Enclose command in a function for parameterization Add error handling / logging Upgrade function to a filtering function to accept pipeline input Enables scenarios like getting names from AD OR a text file Upgrade function to an advanced function (v2 only) for cmdlet-like behavior Package as a Script Module (v2 only) for easier distribution and re-use by others Add comment-based help so you can tell what the heck it’s doing (I’ll demo – you remind me of what step is next)
21. Building a WMI Tool DEMO Remember! I’ll save all my scripts and make them downloadable fromwww.ConcentratedTech.com in a few days – no need to take notes!
22. Conclusion WMI + PowerShell = Very Powerful, Very Convenient And a great way to learn PowerShell incrementally! Build reusable, cmdlet-like tools Now in the TechEd Bookstore:Windows PowerShell v2: TFM by Don Jones & Jeffery Hicks Download this session’s scripts & slides fromwww.ConcentratedTech.com
23. Track Resources Required Slide Track PMs will supply the content for this slide, which will be inserted during the final scrub. Resource 1 Resource 2 Resource 3 Resource 4
24. Resources Required Slide Learning Sessions On-Demand & Community Microsoft Certification & Training Resources www.microsoft.com/teched www.microsoft.com/learning Resources for IT Professionals Resources for Developers http://microsoft.com/technet http://microsoft.com/msdn
25. Related Content Required Slide Speakers, please list the Breakout Sessions, Interactive Sessions, Labs and Demo Stations that are related to your session. Breakout Sessions (session codes and titles) Interactive Sessions (session codes and titles) Hands-on Labs (session codes and titles) Product Demo Stations (demo station title and location)