Hi
Can someone explain this line to me - i know what it does - it displays vm's and the datastore they are in but what happens exactly when the code is run - not sure what this part means at all @{N="Datastore";E={$_ | Get-Datastore
Get-VM | Select Name, @{N="Datastore";E={$_ | Get-Datastore}}
This construction is called a "calculated property".
As the name says, instead of referring to a property that is present on the object passed to the Select-Object cmdlet, a calculated property allows one to create a new property.
The N, or Name, part defines the name of this new property.
The E, or Expression, part defines a code block that defines how the value of the new property is calculated.
In the E part, one can refer to the object that was passed to the Select-Object cmdlet with the $_ variable.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
@{N="the name of the value your are defining";E={This is code to execute that defines the value}}
@{N="";E={}} is a very useful tool to define an arbitrary value.
The "$_ | Get-Datastore" in your example is piping the value of each Get-VM into Get-Datastore and calling the result "Datastore". So for each VM it looks like this "Get-vm VMname | Get-Datastore" giving you the result: for each Line as "Datastore" in the column.
I hope this helps, my terminology may be a bit confusing.
This construction is called a "calculated property".
As the name says, instead of referring to a property that is present on the object passed to the Select-Object cmdlet, a calculated property allows one to create a new property.
The N, or Name, part defines the name of this new property.
The E, or Expression, part defines a code block that defines how the value of the new property is calculated.
In the E part, one can refer to the object that was passed to the Select-Object cmdlet with the $_ variable.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference