Guy's Scripting Ezine 110 - PowerShell WMIGuy's Scripting Ezine 110 - PowerShell WMI
♣ This Week's SecretThis week Microsoft announced that Monad had metamorphosized into PowerShell. (My friend 'Mad' Mick unfairly calls it PowersHell.) One of the hazards of being a Beta pioneer is having to keep updating to the latest version of the program. What I did was download PowerShell, uninstall Monad and install the new PowerShell. The crucial difference is that PowerShell files require a change of extension from .msh to .ps1. This new extension only affects scripts, called cmdlets, which we will investigate next week. This Week's MissionWith any new system you get hype. In the case of PowerShell much of the talk is about what it may (or may not) do in Longhorn. What I want to do is give you a killer reason to use PowerShell, with Windows 7, or Windows Server. That killer reason is to create WMI scripts. I urge you to switch to PowerShell rather than use VBScript for accessing WMI. If you have never explored WMI, then it's like an Aladdin's cave, so start now with PowerShell. Here is an example, which discovers your computer's name, model, manufactures and memory, type: get-WmiObject win32_computersystem If there is another machine on your subnet try these two commands: Calling for Windows Management Instrumentation (WMI) is rather like switching on a microscope to observe what the operating system is doing. WMI permits you to discover what the operating system knows about disks, memory processor or any other Win32 component. My prediction is not the end of the road for WMI, far from it, what I foresee is using PowerShell commands rather than VBScript to access the WMI classes. Note: See more on using WMI Monitor Guy's Twin Goals for PowerShell and WMI1) To explore WMI's Win32_* classes type; get-WmiObject. If at least one of these examples does not give you an idea for a production PowerShell scripts then I will be amazed. 2) I want to introduce you to a few useful PowerShell commands that you learn once then apply to a wide range of verb-noun pairs. For example, format-table, -autosize and -list. Assumptions and Preparation You download PowerShell (or Monad) and .NET Framework 2.0. Next, you install the .msi file, finally you run powershell (or for Monad, MSH). Now you are at a black screen with a PS Prompt > Note: When you type on the PowerShell command line, the only tricky symbol is this pipe |. If in doubt activate your keyboard's number lock, hold down the alt key, type 124 and then let go of alt. If necessary, investigate which key on your keyboard corresponds to this pipe symbol (|). Here are commands to try at the PS Prompt > i a) get-WmiObject Win32_NetworkAdapterConfiguration i b) get-WmiObject Win32_NetworkAdapterConfiguration | format-table i c) get-WmiObject Win32_NetworkAdapterConfiguration | format-table Ipaddress, Description, DHCPEnabled -autosize ii a) In many ways we should have started by researching a list
of properties, try: ii b) Now amend this command choosing different properties: iii a) get-WmiObject Win32_product iii b) get-WmiObject Win32_product |sort-object vendor |format-table name, vendor -groupby vendor iv) get-WmiObject Win32_LogicalDisk | format-table v) get-WmiObject Win32_environment vi a) Research more objects with: get-WmiObject -list vi b) Refine your search with: get-WmiObject -list | where {$_.name -like "Win32_n*"} vi c) Try Win32 objects beginning with other letters, for example, substitute 'p' "Win32_p*. vii) As you make your selections try appending at least some of these, See more PowerShell Scripts for Windows 7
Guy
Recommends: WMI Monitor and It's Free!
| |||||
Custom Search
|
Guy Recommends: WMI Monitor and It's Free!
|
|
Home Copyright © 1999-2012 Computer Performance LTD All rights reserved Please report a broken link, or an error. | |