Parameters and Intellisence

A colleague of mine sent me an email asking if I could explain what he sees in his console:

You might be interested in as well so here are the answers:

For the 1rst screenshot, it’s the Intellisense feature that proposes this list of values that the MemberType parameter accepts.
If you use the help either online or interactively, you can’t unfortunately find the answer.
As you can see the help on PowerShell 5.0 doesn’t really help.

I knew the answer and replied that property is actually an alias of the properties parametername.
Yes, parameters can have aliases πŸ™‚
To uncover it, you should use the Get-Command cmdlet:

(gcm Get-ADUser | Select -Expand Parameters)['Properties']

And when I tested on PowerShell 5.1, it appears that the alias is displayed

First mistery solved πŸ˜€

Now the 2nd one. Why there’s a difference in the count?

Can you notice the addtional “Select * ” in the second command invocation ?

Well, using the Select-Object cmdlet changes an object, including its type, methods and properties.

To find out what are the exact differences, you can do

$User = 'A random UserName'
Compare-Object (Get-ADUser $User -Pro *| gm).Name -Diff (Get-ADUser $User -Pro *| select *| gm).Name

The native ADUser object has a Contains and GetEnumerator methods, a Item ParameterizedProperty whereas its “Selected” ADuser doesn’t…
2nd Mystery solved 😎

Advertisements

One thought on “Parameters and Intellisence

  1. Pingback: Dew Drop - April 7, 2017 (#2458) - Morning Dew

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s