Quick Outline:
What are the Get Property Commands in PowerShell
What are the Get Property Commands in PowerShell?
The Get Property commands refer to the PowerShell commands list that get the properties of the specified file, item, or object. Get Property commands get the properties of the specified item. These commands include Get-Member, Get-Item, Get-ItemProperty, Select-Object, and Get-ChildItem.
1. Get-Member – Gets the Properties of an Item
The Get-Member command gets the properties of an item or object. It gets the specified object’s members, methods, and properties. The object is specified to it using the InputObject parameter or by piping the object to it. However, to get the object’s properties use the -MemberType parameter and specify the Property value.
Syntax
Here is the syntax of the PowerShell’s Get-Member command:
Example 1:
This example will get the properties and not the methods of the given object using Get-Member cmdlet:
According to the above code:
- First, specify the Get-Process command or any other desired command.
- Then, pipe it to the Get-Member command.
- After that, use the -MemberType parameter and specify the Property value to get only the properties of an item:
Example 2:
This demonstration will get the properties of the specified command using the Get-Member cmdlet and Where condition:
According to the above code:
- First, the Get-Process command is placed and piped to the Get-Member cmdlet.
- Then, the Get-Member cmdlet is piped to the Where condition.
- In the Where condition, the MemberType property is selected which will find values that are equal to the Property instance:
2. Select-Object – Selects Objects or Objects Properties
The Select-Object command selects the objects or properties of an object. It can select a specified number of objects, such as the first five items from the index using the -First parameter and the last five using the -Last parameter.
Syntax
This is the syntax of the Select-Object command:
Example:
This example will select the specified properties of an object using the Select-Object command:
According to the above code:
- First, specify the Get-Command cmdlet and then pipe it to the Select-Object command.
- After that, use the -Property parameter and specify the properties to select and display:
3. Get-Item – Gets Items from the Given Path
The Get-Item command gets the items from the provided location. It gets the properties for one item at a time. Get-Item commands do not get the content of the specified item, unlike the Get-Content command. But, it lists down the item’s properties such as its name, mode, or length.
Syntax
Here is the syntax of the PowerShell’s Get-Item command:
Example:
This example will get the item from the provided location and will also provide its properties:
In accordance with the mentioned command:
- First, specify the Get-Item command.
- Then, use the -Path parameter and assign it the item’s path:
4. Get-ItemProperty – Gets Properties of the Specified Item
The Get-ItemProperty command gets the properties of the specified item. It gets properties like LastWriteTime, Length, and Mode of the specified item.
Syntax
Here is the syntax of the PowerShell’s Get-ItemProperty command:
Example:
This example gets the properties of a single specified item using the Get-ItemProperty command:
According to the above code:
- First, specify the Get-ItemProperty command.
- After that, specify the file path using the -path parameter:
5. Get-ChildItem – Gets Child Item Properties from Sub Folders
The Get-ChildItem command gets the items and child items from the specified locations. The subfolders or files are known as child items. It gets the properties of items like Name, Mode, Length, and LastWriteTime.
Syntax
Here is the syntax of the PowerShell’s Get-ChildItem command:
Example:
This example not only gets the child items from the specified location but displays the properties of items:
According to the above code:
- First, mention the Get-ChildItem command.
- Then, the folder path is specified to the Get-ChildItem command using the -path parameter:
Summary
A property is a piece of information that describes the object. PowerShell Get Property commands are the commands that get the properties of an item, file, folder, or object. These commands include Get-Member, Get-Item, Get-ItemProperty, Select-Object, and Get-ChildItem. Each command either gets the properties of a file or an object.