Windows PowerShell Get-MemberIntroduction to Windows PowerShell Get-MemberGet-Member is an essential command for discovering more about PowerShell's objects. Because you are at the command line, you cannot right click an object and check its properties; instead, what you can do is type: get-ObjectXYZXYZ | get-Member. PowerShell is sometimes referred to as a self-describing language. Indeed, it is thanks to get-Member that we can see the properties and methods associated with any given object. Topics for PowerShell's get-Member
The Concept behind get-MemberThe reason that I use get-Member at every opportunity is so that I can discover 'handles', which help me achieve a particular scripting task. These 'handles' or memberTypes are split into methods and properties. Suitable objects to learn more about get-Member include, service, process, eventlog, or WmiObject. Employing get-Member is a useful tactic in the bigger game of scripting specific properties. For example, if your goal is to stop, or to start a service, then you need to investigate the scripting properties, and possible values, for that service. A little research with get-Member will reveal a property called 'Status', with values of 'Running' or 'Stopped' - perfect for our task. Here are three examples to illustrate my research technique:
1)
get-Service
2)
get-Service | get-Member
3)
get-Service messenger
3a) get-Service messenger | get-Member Special note, the pipeline symbol displays as ¦ in PowerShell, but as | in notepad.
The Basics of get-ObjectXYZ | get-MemberNaturally, the phrase get-Member never varies, a case of learn once and apply to many objects. Just remember the hyphen, and also remember that there are no spaces in verb-noun pairs. Please note that get-ObjectXYZ is just a generic name that I made up to illustrate get-Member in action. Correct Syntax: get-Member Incorrect Syntax: get member (no hyphen), or get -Member or even get- member (spaces) As I mentioned earlier, when you use get-Member in conjunction with other commands such as get-ObjectXYZ, remember the 'Pipe' or 'Pipeline' symbol. This vertical line | is ASCII 124 and looks like this at the PS Prompt ¦ Correct Sequence: get-ObjectXYZ | get-Member
Incorrect Syntax: get-Member | get-ObjectXYZ (wrong sequence of verb-noun pair) More Examples of get-Member
get-WmiObject Win32_processor | get-Member
get-Process |get-Member
get-Eventlog system | get-Member Filter with -MembertypeResults from the simple command: get-Member, may produce too many MemberTypes; if so, then you can filter the output with a -Membertype argument, for example: get-Process
| get-Member -Membertype
property Appreciate that the results of the parameter -MemberType are grouped into at least four categories: AliasProperty, Method, Property and ScriptProperty. Once you have researched -MemberType, you may see
new applications for the properties that it reveals, for example Strictly speaking, the above command should be, 'group-Object company', however, 'group-Object' has an alias, you can shorten the command to plain 'group'. Here is a method for expanding the company information: Incidentally, this whole page of -Member examples gives valuable experience of when to use the hyphen - also called a dash, and sometimes referred to as a minus sign. For example -Membertype takes the hyphen prefix, whereas property, as in -Membertype property does not need any prefix.
˚
Getting Help for get-MemberFor a complete list of filters
supported by the
get-Member command, call for help thus: This may be just me, but I have the urge to call this -method instead of -Member. I mention this because you always learn more from mistakes. The answer lies in, a) Reading the error message! b) Trying an example you know works, for example, I was trying this: Here is a mistake that I made: When I read the error message it said: 'get-method is not recognised'. Hmmm... I thought, let me try an old friend the process object. When I tried get-help and get-Member working in tandem.Remember that get-help and get-Member are complimentary. On the one hand, get-help will disclose information about parameters or switches that you can employ with your command, for example -recurse with get-Childitem -path and -pattern with Select-String. On the other hand, get-Member will disclose the properties and methods, for example .extension .fullname both of which are useful with get-Childitem. My point is that get-help and get-Member each provide different information; they are complimentary rather than interchangeable. If you are complete beginner, investigate both get-help and get-Member; when you are an intermediate don't get fixated on one, and forget all about the other. More examples of get-MemberSummary of PowerShell's get-Member
When you need to investigate the methods and properties available to a PowerShell object, then call for get-Member. You will soon get used its hyphen and associated 'Pipe' symbol (|), just remember the
correct sequence: See Also• Windows PowerShell Home • Introduction • Cmdlets • Exchange 2007 • Profile.ps1 • $_.Pipeline If you see an error of any kind, do let me know. Please report any factual mistakes, grammatical errors or broken links, I will be happy to not only to correct the fault, but also to give you credit. *
|
|||||