Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell dot notation vs select-object

Can somebody explain to me what is the difference between dot notation and select-object in Powershell? How these two methods of accessing properties differ internally?

I've noticed that running (ls).name gives basically the same results as ls | select-object name however running ls | select-object name | export-csv foo.csv gives me proper csv file while trying (ls).name | export-csv foo.csv gives me the file with length. In both cases gettype() returns Object[]

like image 685
Łukasz Avatar asked May 10 '15 08:05

Łukasz


People also ask

What does the DOT do in PowerShell?

The PowerShell dot-source operator brings script files into the current session scope. It is a way to reuse script. All script functions and variables defined in the script file become part of the script it is dot sourced into. It is like copying and pasting text from the script file directly into your script.

What is the purpose of select dot is multiple method?

operator? (Select multiple) It enables you to access instance variables of any objects within a class.

How do I get the properties of an object in PowerShell?

Object properties To get the properties of an object, use the Get-Member cmdlet. For example, to get the properties of a FileInfo object, use the Get-ChildItem cmdlet to get the FileInfo object that represents a file.

What is Dot sourcing in PowerShell?

The dot sourcing feature lets you run a script in the current scope instead of in the script scope. When you run a script that is dot sourced, the commands in the script run as though you had typed them at the command prompt.


1 Answers

The select-object cmdlet wraps the result in a new object. To see the differences (look at the Type) use the get-member cmdlet.

(ls).Name | get-member

and

ls | select-object Name | get-member
like image 68
Peter Schneider Avatar answered Oct 19 '22 11:10

Peter Schneider