Stupid noob question - Why does this "byvalue" work?

I hate to ask a “PowerShell 101” question but I’m having a little trouble understanding how this works…

So I create a text file “C:\names.txt” containing samaccountnames.
Then run the following snippet:

$names = get-content c:\names.txt
foreach ($name in $names)
{
get-aduser -identity $name -property name,enabled,accountexpirationdate
}
 

Running “help get-ADUser -full” indicates the parameter “-Identity” is the only parameter that accepts pipeline input, and it expects pipeline input ‘ByValue’ for the value .

Since “get-content c:\names.txt | gm” indicates the object type is “string”, how is this value being accepted by “get-ADUser” which only accepts pipeline input ‘ByValue’ for value ?

Sorry - the type “ADUser” was stripped out of my post. Gues arrow brackets are a no-no.

Running “help get-ADUser -full” indicates the parameter “-Identity” is the only parameter that accepts pipeline input, and it expects pipeline input ‘ByValue’ for value ‘ADUser’

Since “get-content c:\names.txt | gm” indicates the object type is “string”, how is this value being accepted by “get-ADUser” which only accepts pipeline input ‘ByValue’ for value ‘ADUser’?

Not sure how you learn if you don’t ask, so don’t apologize ;).

ByValue means “of the same data type.” So, normally, if you were piping in a System.String, the parameter would need to be rigged to accept System.String - that match in datatype is how it makes the connection.

Get-ADUser is a little weird. The help says the parameter accepts objects of type ADUser, but that’s not strictly correct. I’m fairly certain it’s rigged to accept System.Object, which means “anything,” and then it figures out what you’ve passed it internally. That’s because it accepts a really wide variety of input on that parameter, as described in the help.

So your statement “pipeline input ‘ByValue’ for the value” isn’t technically correct. It doesn’t accept “ByValue for the value;” it just accepts “By Value.” Meaning, “by data type.” Once you know a parameter accepts ByValue, you have to look and see what kind of value it accepts, to know what you can pipe to it.

“Learn Windows PowerShell in a Month of Lunches” has a lovely chapter on this :wink: as well as ByPropertyName, and how they both work.

Don - Thanks for the info. I guess this is a Powershell easter egg for the Get-ADUser cmdlet.

Powershell is a bunch of fun. Every day I either read something from “Learn Windows PowerShell in a Month of Lunches (2nd Ed)”, watch a Powershell jump start or one of the CBTNuggets Powershell videos.