Powershell 2.0 Get-Member Enhancements
The other day I blogged on a cool way to alter database file properties. And I promised I would film the solution for you. Well, I got home that night and started filming but when I pulled up sqlps I was stopped dead in my tracks by something I couldn’t explain. The methods to get and set were missing. I checked my other box and they were there, so what happened? The only difference was that the box I wrote the blog from was XP and the box I was filming from was Win7.
So I pinged a couple really smart guys as MS (and I cc’d Buck). So after a couple of days we have an answer. There’s a new feature in powershell 2.0 that hides the getter and setter methods from you by default in get-member. They’re officially calling it an enhancement.
There are 2 new parameters that get-member supports that allow you to control what you see. You can now use –view and –force.
-view takes the parameters Extended, Adapted, Base, All
-force doesn’t take any additional parameters.
However if you’re looking specifically for getter and setter methods, you’ll have to use –force because –view doesn’t display them. Here’s what that’ll look like:
dir | gm –force
Now you can see everything. It’s interesting though is that by defalt, PS loads all the methods, it just doesn’t show them to you.
Here’s the MSDN blog that explains this and so much more.
And I’d like to give a special thanks to Robert Hutchinson at MS for chasing this down for me while Buck and I sat on the sidelines helpless.
About Me
- Sean McCown
- I am a Contributing Editor for InfoWorld Magazine, and a frequent contributor to SQLServerCentral.com as well as SSWUG.org. I live with my wife and 3 kids, and have practiced and taught Kenpo for 22yrs now.