Michal Ciechan
Michal Ciechan

Reputation: 13888

PowerShell - How to get names of piped variables

I am trying to figure out something in powershell using piping.

I have something like this:

Get-Project -All | %{ $_.Name } 

Note: I know %{} = ForEach{}

Get-Project -All is a NuGet command which returns all project in current solution.

This works for me, but I would like to find out all available variables that get piped through. I only know $_.Name is one of them as I can see from an example online.

When I run Get-Project -All I get the following output

ProjectName   Type   FullName  
-----------   ----   --------
ABC           C#     C:\SolutionDir\Category\ABC.csproj  

Now inside my pipe I found the following variables:

$_.Name = ABC
$_.ProjectName = Category/ABC
$_.Type = C#
$_.FullName = C:\SolutionDir\Category\ABC.csproj 

Now what I don't understand is

  1. The "Table" output of Get-Project -All has a header of ProjectName with value of ABC. But inside the pipe $_.ProjectName = Category/ABC and$_.Name = ABC`. Are they unrelated?
  2. If I didn't see the example online mentioning $_.Name I would of never known about this variable. Is there some way of getting all available variables?

Note:

Get-Project -All | %{ Get-Variable } does not return any of the above mentioned variables.

Upvotes: 0

Views: 1321

Answers (1)

ojk
ojk

Reputation: 2542

When you use the pipeline, it's the entire object created, in this case Get-Project, that is sent through it. To see all members of an object, use Get-Member.

So in your case, you can use Get-Project -All | Get-Member to see all the properties and methods of the object being returned.

Upvotes: 2

Related Questions